Current section
Files
Jump to
Current section
Files
lib/nldoc/spec/image.ex
defmodule NLdoc.Spec.Image do
@moduledoc """
This module defines the Ecto schema for the NLdoc spec Image object.
"""
use NLdoc.Spec.Schema, type: "https://spec.nldoc.nl/Resource/Image"
@required [:id, :type, :source]
@fields @required ++ [:alternative_text, :decorative]
typed_embedded_schema null: false do
field :id, Ecto.UUID
field :type, :string, default: @resource_type
field :source, :string
field :alternative_text, :string, null: true
field :decorative, :boolean, default: false
embeds_many :caption, NLdoc.Spec.Paragraph
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, @fields, @cast_opts)
|> cast_embed(:caption, @cast_opts)
|> cast_polymorphic_embed(:descriptors, @cast_opts)
|> validate_required(@required)
|> validate_inclusion(:type, [@resource_type])
end
end