LangSchema.Type behaviour (LangSchema v0.2.0)
View SourceDefines the behaviour and common helpers for handling JSON Schema type conversion.
Each module implementing LangSchema.Type
specifies how a particular JSON Schema type
(such as boolean
, integer
, number
, string
, array
, or object
) should be converted
into its corresponding JSON Schema representation.
It also provides shared utilities for processing schema keywords during conversion.
Summary
Callbacks
Defines how the core part of the given type should be converted into its corresponding JSON Schema representation.
Converts and attaches additional keywords to the JSON schema for this type.
Returns the list of allowed keywords that can be additionally set for this type.
Callbacks
Defines how the core part of the given type should be converted into its corresponding JSON Schema representation.
This focuses on converting the essential structure specific to the type — for example,
handling properties
for object
, or items
for array
.
Complex types like object
and array
will typically implement meaningful logic here.
@callback convert_keywords(json_schema :: map(), schema :: map(), keywords :: map()) :: json_schema :: map()
Converts and attaches additional keywords to the JSON schema for this type.
This function applies the allowed keywords (as defined by keywords/0
) onto the base JSON schema
according to the values provided in the original schema definition.
By default, the pattern
keyword is predefined with its specific converter.
If a keyword is not explicitly associated with a converter, the behavior defined by LangSchema.Keyword.Default
is applied.
@callback keywords() :: [atom()]
Returns the list of allowed keywords that can be additionally set for this type.
In JSON Schema, various keywords (such as description
, minimum
, pattern
, etc.)
can be used to further constrain or describe a field beyond its basic type.
This callback defines which keywords are considered relevant for the type and will be processed during schema conversion.
Within this Elixir codebase, keyword names follow Elixir's snake_case convention
(e.g., min_length
, max_items
), even though in JSON Schema they are typically camelCase
(e.g., minLength
, maxItems
).