castor
Types
Node in the Specification that might be represented by a reference.
pub type Ref(t) {
Ref(
ref: String,
summary: option.Option(String),
description: option.Option(String),
)
Inline(value: t)
}
Constructors
-
Ref( ref: String, summary: option.Option(String), description: option.Option(String), ) -
Inline(value: t)
Represents a decoded JSON schema.
Chosen to add metadata inline as it doesn’t belong on ref object https://json-schema.org/draft/2020-12/json-schema-validation#name-a-vocabulary-for-basic-meta
pub type Schema {
Boolean(
nullable: Bool,
title: option.Option(String),
description: option.Option(String),
deprecated: Bool,
)
Integer(
multiple_of: option.Option(Int),
maximum: option.Option(Int),
exclusive_maximum: option.Option(Int),
minimum: option.Option(Int),
exclusive_minimum: option.Option(Int),
nullable: Bool,
title: option.Option(String),
description: option.Option(String),
deprecated: Bool,
)
Number(
multiple_of: option.Option(Int),
maximum: option.Option(Int),
exclusive_maximum: option.Option(Int),
minimum: option.Option(Int),
exclusive_minimum: option.Option(Int),
nullable: Bool,
title: option.Option(String),
description: option.Option(String),
deprecated: Bool,
)
String(
max_length: option.Option(Int),
min_length: option.Option(Int),
pattern: option.Option(String),
format: option.Option(String),
nullable: Bool,
title: option.Option(String),
description: option.Option(String),
deprecated: Bool,
)
Null(
title: option.Option(String),
description: option.Option(String),
deprecated: Bool,
)
Array(
max_items: option.Option(Int),
min_items: option.Option(Int),
unique_items: Bool,
items: Ref(Schema),
nullable: Bool,
title: option.Option(String),
description: option.Option(String),
deprecated: Bool,
)
Object(
properties: dict.Dict(String, Ref(Schema)),
required: List(String),
additional_properties: option.Option(Ref(Schema)),
max_properties: option.Option(Int),
min_properties: Int,
nullable: Bool,
title: option.Option(String),
description: option.Option(String),
deprecated: Bool,
)
AllOf(non_empty_list.NonEmptyList(Ref(Schema)))
AnyOf(non_empty_list.NonEmptyList(Ref(Schema)))
OneOf(non_empty_list.NonEmptyList(Ref(Schema)))
Enum(non_empty_list.NonEmptyList(utils.Any))
AlwaysPasses
AlwaysFails
}
Constructors
-
Boolean( nullable: Bool, title: option.Option(String), description: option.Option(String), deprecated: Bool, ) -
Integer( multiple_of: option.Option(Int), maximum: option.Option(Int), exclusive_maximum: option.Option(Int), minimum: option.Option(Int), exclusive_minimum: option.Option(Int), nullable: Bool, title: option.Option(String), description: option.Option(String), deprecated: Bool, ) -
Number( multiple_of: option.Option(Int), maximum: option.Option(Int), exclusive_maximum: option.Option(Int), minimum: option.Option(Int), exclusive_minimum: option.Option(Int), nullable: Bool, title: option.Option(String), description: option.Option(String), deprecated: Bool, ) -
String( max_length: option.Option(Int), min_length: option.Option(Int), pattern: option.Option(String), format: option.Option(String), nullable: Bool, title: option.Option(String), description: option.Option(String), deprecated: Bool, ) -
Null( title: option.Option(String), description: option.Option(String), deprecated: Bool, ) -
Array( max_items: option.Option(Int), min_items: option.Option(Int), unique_items: Bool, items: Ref(Schema), nullable: Bool, title: option.Option(String), description: option.Option(String), deprecated: Bool, ) -
Object( properties: dict.Dict(String, Ref(Schema)), required: List(String), additional_properties: option.Option(Ref(Schema)), max_properties: option.Option(Int), min_properties: Int, nullable: Bool, title: option.Option(String), description: option.Option(String), deprecated: Bool, ) -
AllOf(non_empty_list.NonEmptyList(Ref(Schema))) -
AnyOf(non_empty_list.NonEmptyList(Ref(Schema))) -
OneOf(non_empty_list.NonEmptyList(Ref(Schema))) -
-
AlwaysPasses -
AlwaysFails
Values
pub fn decoder() -> decode.Decoder(Schema)
Decoder for the JSON Schema type
Use with json.parse
pub fn dict(field_schema: Schema) -> Schema
Create a schema for an open dictionary of strings to the given schema type
pub fn encode(schema: Schema) -> json.Json
Convert a Schema to a gleam_json type.
encode this to a string using json.to_string
pub fn enum_of_strings(
strings: non_empty_list.NonEmptyList(String),
) -> Schema
pub fn field(key: a, schema: b) -> #(a, Ref(b), Bool)
Construct a schema for a required field of an object.
pub fn object(
properties: List(#(String, Ref(Schema), Bool)),
) -> Schema
Create a schema for an object with all properties defined.
user field and optional_field to define fields.
pub fn optional_field(key: a, schema: b) -> #(a, Ref(b), Bool)
Construct a schema for an optional field of an object.
pub fn ref_decoder(
of: decode.Decoder(t),
) -> decode.Decoder(Ref(t))