Current section

Files

Jump to
nldoc_spec lib nldoc spec link.ex
Raw

lib/nldoc/spec/link.ex

defmodule NLdoc.Spec.Link do
@moduledoc """
This module defines the Ecto schema for the NLdoc spec Link object.
"""
use NLdoc.Spec.Schema, type: "https://spec.nldoc.nl/Resource/Link"
typed_embedded_schema null: false do
field :id, Ecto.UUID
field :type, :string, default: @resource_type
field :text, :string, default: ""
field :uri, :string
field :purpose, :string, null: true
field :styling, {:array, Ecto.Enum},
values: NLdoc.Spec.text_styling(),
default: []
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, :text, :styling, :uri, :purpose], @cast_opts)
|> cast_polymorphic_embed(:descriptors, @cast_opts)
|> validate_required([:id, :type, :text, :uri])
|> validate_inclusion(:type, [@resource_type])
|> validate_length(:purpose, min: 1)
end
end