class Identity < Dry::Schema::JSON
define do
required(:id).filled { str? | int? }
required(:type).filled(:string)
end
end
class Resource < Identity
define do
optional(:attributes).hash
optional(:relationships).hash
optional(:links).hash
optional(:meta).hash
end
end
class Document < Dry::Schema::JSON
define do
required(:data) do
array { schema(Resource.new) } | schema(Resource.new)
end
optional(:included).array { schema(Resource.new) }
optional(:links).hash
optional(:meta).hash
optional(:jsonapi).hash
end
end
There are two places where Dry::Schema still falls short: relationships and links both can contain arbitrarily-named keys. In Dry::Types you would be tempted to express these as Map types, but that is currently not supported.