Current section
Files
Jump to
Current section
Files
lib/nldoc/spec/list_item.ex
defmodule NLdoc.Spec.ListItem do
@moduledoc """
This module defines the Ecto schema for the NLdoc spec ListItem object.
"""
use NLdoc.Spec.Schema, type: "https://spec.nldoc.nl/Resource/ListItem"
alias NLdoc.Spec.{OrderedList, Paragraph, UnorderedList}
typed_embedded_schema null: false do
field :id, Ecto.UUID
field :type, :string, default: @resource_type
field(:children, {:array, PolymorphicEmbed},
types: map([Paragraph, OrderedList, UnorderedList]),
type_field_name: :type,
on_replace: :delete,
default: [],
array?: true
) :: [Paragraph.t() | OrderedList.t() | UnorderedList.t()]
end
def changeset(object, attrs) do
object
|> cast(attrs, [:id, :type], @cast_opts)
|> cast_polymorphic_embed(:children, @cast_opts)
|> validate_required([:id, :type])
|> validate_inclusion(:type, [@resource_type])
end
end