View Source Xema.Schema (xema v0.17.5)
This module contains the struct for the keywords of a schema.
Summary
Functions
Fetches a subschema from the schema by the given pointer.
Fetches a subschema from the schema by the given pointer.
Returns all keywords in a list.
Returns a %Schema{} for the given keywords in the keyword list.
Returns the %Schema{} as a map. Items which a nil value are not in the
map.
Returns all available types in a list.
Types
@type t() :: %Xema.Schema{ additional_items: Xema.Behaviour.t() | t() | boolean() | nil, additional_properties: map() | boolean() | nil, all_of: [t()] | nil, any_of: [t()] | nil, caster: function() | module() | {module(), atom()} | {module(), atom(), arity()} | list() | nil, comment: String.t() | nil, const: any(), contains: Xema.Behaviour.t() | t() | nil, content_encoding: String.t() | nil, content_media_type: String.t() | nil, data: map() | nil, default: any(), definitions: map() | nil, dependencies: list() | map() | nil, description: String.t() | nil, else: Xema.Behaviour.t() | t() | nil, enum: list() | nil, examples: [any()] | nil, exclusive_maximum: boolean() | number() | nil, exclusive_minimum: boolean() | number() | nil, format: atom() | nil, id: String.t() | nil, if: Xema.Behaviour.t() | t() | nil, items: list() | Xema.Behaviour.t() | t() | nil, keys: atom() | nil, max_items: pos_integer() | nil, max_length: pos_integer() | nil, max_properties: pos_integer() | nil, maximum: number() | nil, min_items: pos_integer() | nil, min_length: pos_integer() | nil, min_properties: pos_integer() | nil, minimum: number() | nil, module: atom() | nil, multiple_of: number() | nil, not: t() | nil, one_of: [t()] | nil, pattern: Regex.t() | nil, pattern_properties: map() | nil, properties: map() | nil, property_names: Xema.Behaviour.t() | t() | nil, ref: Xema.Ref.t() | nil, required: MapSet.t() | nil, schema: String.t() | nil, then: Xema.Behaviour.t() | t() | nil, title: String.t() | nil, type: type() | [type()], unique_items: boolean() | nil, validator: function() | module() | {module(), atom()} | {module(), atom(), arity()} | list() | nil }
The struct contains the keywords for a schema.
additional_itemsdisallow additional items, if set to false. The keyword can also contain a schema to specify the type of additional items.additional_propertiesdisallow additional properties, if set to true.- 'all_of' a list of schemas they must all be valid.
- 'any_of' a list of schemas with any valid schema.
castera custom caster. This can be a function, a tuple with module and function name, or aXema.Casterbehaviour.commentfor the schema.constspecifies a constant.content_encodingannotation for the encoding.content_media_typeannotation for the media type.containsvalidates a list whether any item is valid for the given schema.datanone schema data. Values indatawill be interpreted as schemas when possible. It is not recommended to put any data or schemas under this key. Thedataproperty is mainly for compatibility with JsonSchema.defaultthis keyword can be used to supply a default value for JSON anddefstruct.definitionscontains schemas for reuse.dependenciesallows the schema of the map to change based on the presence of certain special propertiesdescriptionof the schema.elseseeif,then,else.enumspecifies an enumerationexamplesthe value of this keyword must be an array. There are no restrictions placed on the values within the array.exclusive_maximumis a boolean. When true, it indicates that the range excludes the maximum value.exclusive_minimumis a boolean. When true, it indicates that the range excludes the minimum value.formatsemantic validation.ida unique identifier.if,then,else: These keywords work together to implement conditional application of a subschema based on the outcome of another subschema.itemsspecifies the type(s) of the items.keyscould be:atomsor:strings.max_itemsthe maximum length of list.max_lengththe maximum length of string.max_propertiesthe maximum count of properties for the map.maximumthe maximum value.min_itemsthe minimal length of list.min_lengththe minimal length of string.min_propertiesthe minimal count of properties for the map.minimumthe minimum value.modulethe module of a struct.multiple_ofis a number greater 0. The value has to be a multiple of this number.notnegates the given schemaone_ofthe given data must be valid against exactly one of the given subschemas.pattern_propertiesspecifies schemas for properties by patternspatternrestrict a string to a particular regular expression.propertiesspecifies schemas for properties.property_namesa schema to check property names.refa reference to a schema.requiredcontains a set of required properties.schemadeclares the used schema.titleof the schema.thenseeif,then,elsetypespecifies the data type for a schema.unique_itemsdisallow duplicate items, if set to true.validatora custom validator. This can be a function, a tuple with module and function name, or aXema.Validatorbehaviour.
@type type() ::
:any
| :atom
| :boolean
| false
| :float
| :integer
| :keyword
| :list
| :map
| nil
| :number
| :string
| :struct
| true
| :tuple
The type for the schema.
@type xema() :: struct()
Functions
@spec fetch(t(), Xema.Ref.t() | String.t()) :: {:ok, t()} | :error
Fetches a subschema from the schema by the given pointer.
If schema contains the given pointer with a subschema, then {:ok, schema}
is returned otherwise :error.
@spec fetch!(t(), Xema.Ref.t() | String.t()) :: t()
Fetches a subschema from the schema by the given pointer.
If schema contains the given pointer with a subschema, then {:ok, schema}
is returned otherwise a SchemaError is raised.
@spec keywords() :: [atom()]
Returns all keywords in a list.
The key :data is not a regular keyword and is not in the list.
Returns a %Schema{} for the given keywords in the keyword list.
Returns the %Schema{} as a map. Items which a nil value are not in the
map.
@spec types() :: [type()]
Returns all available types in a list.