defmodule NLdoc.Spec.OrderedList do @moduledoc """ This module defines the Ecto schema for the NLdoc spec OrderedList object. """ use NLdoc.Spec.Schema, type: "https://spec.nldoc.nl/Resource/OrderedList" alias NLdoc.Spec.ListItem @style_types [:decimal, :"lower-alpha", :"upper-alpha", :"lower-roman", :"upper-roman"] @type style_type :: :decimal | :"lower-alpha" | :"upper-alpha" | :"lower-roman" | :"upper-roman" # coveralls-ignore-next-line Guard functions cannot be covered by ExCoveralls defguard is_ordered_list_style(style) when is_atom(style) and style in @style_types typed_embedded_schema null: false do field :id, Ecto.UUID field :type, :string, default: @resource_type field :start, :integer, default: 1 field :reversed, :boolean, default: false field :style_type, Ecto.Enum, values: @style_types, default: :decimal embeds_many :children, ListItem field(:descriptors, {:array, PolymorphicEmbed}, types: map(NLdoc.Spec.descriptors()), type_field_name: :type, on_replace: :delete, default: [], array?: true ) :: [NLdoc.Spec.descriptor()] end def changeset(object, attrs) do object |> cast(attrs, [:id, :type, :start, :reversed, :style_type], @cast_opts) |> cast_embed(:children) |> cast_polymorphic_embed(:descriptors, @cast_opts) |> validate_required([:id, :type]) |> validate_inclusion(:type, [@resource_type]) end end