xema v0.6.2 Xema.Schema View Source
This module contains the struct for the keywords of a schema.
Usually this struct will be just used by xema.
Examples
iex> xema = Xema.new :any
iex> xema.schema == %Xema.Schema{type: :any}
true
Link to this section Summary
Functions
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
Link to this section Types
Link to this type
t()
View Source
t()
View Source
t() :: %Xema.Schema{
items: list() | Xema.t() | Xema.Schema.t() | nil,
data: map(),
max_length: pos_integer() | nil,
one_of: [Xema.Schema.t()] | nil,
any_of: [Xema.Schema.t()] | nil,
then: Xema.t() | Xema.Schema.t() | nil,
exclusive_minimum: boolean() | number() | nil,
max_items: pos_integer() | nil,
format: atom() | nil,
keys: atom() | nil,
additional_properties: map() | boolean() | nil,
min_properties: pos_integer() | nil,
additional_items: Xema.t() | Xema.Schema.t() | boolean() | nil,
unique_items: boolean() | nil,
min_items: pos_integer() | nil,
all_of: [Xema.Schema.t()] | nil,
max_properties: pos_integer() | nil,
const: any(),
description: String.t() | nil,
exclusive_maximum: boolean() | number() | nil,
minimum: number() | nil,
required: MapSet.t() | nil,
module: atom() | nil,
title: String.t() | nil,
id: String.t() | nil,
else: Xema.t() | Xema.Schema.t() | nil,
multiple_of: number() | nil,
contains: Xema.t() | Xema.Schema.t() | nil,
content_encoding: String.t() | nil,
comment: String.t() | nil,
default: any(),
dependencies: list() | map() | nil,
definitions: map(),
ref: Xema.Ref.t() | nil,
properties: map() | nil,
maximum: number() | nil,
pattern: Regex.t() | nil,
property_names: Xema.t() | Xema.Schema.t() | nil,
enum: list() | nil,
type: type() | [type()],
examples: [any()],
pattern_properties: map() | nil,
not: Xema.Schema.t() | nil,
schema: String.t() | nil,
if: Xema.t() | Xema.Schema.t() | nil,
content_media_type: String.t() | nil,
min_length: pos_integer() | nil
}
t() :: %Xema.Schema{
items: list() | Xema.t() | Xema.Schema.t() | nil,
data: map(),
max_length: pos_integer() | nil,
one_of: [Xema.Schema.t()] | nil,
any_of: [Xema.Schema.t()] | nil,
then: Xema.t() | Xema.Schema.t() | nil,
exclusive_minimum: boolean() | number() | nil,
max_items: pos_integer() | nil,
format: atom() | nil,
keys: atom() | nil,
additional_properties: map() | boolean() | nil,
min_properties: pos_integer() | nil,
additional_items: Xema.t() | Xema.Schema.t() | boolean() | nil,
unique_items: boolean() | nil,
min_items: pos_integer() | nil,
all_of: [Xema.Schema.t()] | nil,
max_properties: pos_integer() | nil,
const: any(),
description: String.t() | nil,
exclusive_maximum: boolean() | number() | nil,
minimum: number() | nil,
required: MapSet.t() | nil,
module: atom() | nil,
title: String.t() | nil,
id: String.t() | nil,
else: Xema.t() | Xema.Schema.t() | nil,
multiple_of: number() | nil,
contains: Xema.t() | Xema.Schema.t() | nil,
content_encoding: String.t() | nil,
comment: String.t() | nil,
default: any(),
dependencies: list() | map() | nil,
definitions: map(),
ref: Xema.Ref.t() | nil,
properties: map() | nil,
maximum: number() | nil,
pattern: Regex.t() | nil,
property_names: Xema.t() | Xema.Schema.t() | nil,
enum: list() | nil,
type: type() | [type()],
examples: [any()],
pattern_properties: map() | nil,
not: Xema.Schema.t() | nil,
schema: String.t() | nil,
if: Xema.t() | Xema.Schema.t() | nil,
content_media_type: String.t() | nil,
min_length: pos_integer() | 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.
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.defaultthis keyword can be used to supply a default JSON value.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.
Link to this type
type()
View Source
type()
View Source
type() ::
:any
| :atom
| :boolean
| false
| :float
| :integer
| :keyword
| :list
| :map
| nil
| :number
| :string
| :struct
| true
| :tuple
type() :: :any | :atom | :boolean | false | :float | :integer | :keyword | :list | :map | nil | :number | :string | :struct | true | :tuple
The type for the schema.
Link to this section Functions
Link to this function
keywords()
View Source
keywords()
View Source
keywords() :: [atom()]
keywords() :: [atom()]
Returns all keywords in a list.
The key :data is not a regular keyword and is not in the list.
Link to this function
new(keywords)
View Source
new(keywords)
View Source
new(keyword()) :: Xema.Schema.t()
new(keyword()) :: Xema.Schema.t()
Returns a %Schema{} for the given keywords in the keyword list.
Link to this function
to_map(schema)
View Source
to_map(schema)
View Source
to_map(Xema.Schema.t()) :: map()
to_map(Xema.Schema.t()) :: map()
Returns the %Schema{} as a map. Items which a nil value are not in the
map.
Link to this function
types()
View Source
types()
View Source
types() :: [type()]
types() :: [type()]
Returns all available types in a list.