json/blueprint/schema

Types

Represents a complete JSON Schema document

pub type Schema {
  Schema(
    schema: SchemaDefinition,
    vocabulary: Option(List(String)),
    id: Option(String),
    comment: Option(String),
    defs: Option(List(#(String, SchemaDefinition))),
  )
}

Constructors

  • Schema(
      schema: SchemaDefinition,
      vocabulary: Option(List(String)),
      id: Option(String),
      comment: Option(String),
      defs: Option(List(#(String, SchemaDefinition))),
    )

Core schema definition that can be used recursively

pub type SchemaDefinition {
  Type(type_: SchemaType)
  Enum(values: List(json.Json))
  Const(value: json.Json)
  Nullable(schema: SchemaDefinition)
  Number(
    minimum: Option(Float),
    maximum: Option(Float),
    exclusive_minimum: Option(Float),
    exclusive_maximum: Option(Float),
    multiple_of: Option(Float),
  )
  String(
    min_length: Option(Int),
    max_length: Option(Int),
    pattern: Option(String),
    format: Option(StringFormat),
  )
  Array(items: Option(SchemaDefinition))
  DetailedArray(
    items: Option(SchemaDefinition),
    prefix_items: Option(List(SchemaDefinition)),
    min_items: Option(Int),
    max_items: Option(Int),
    unique_items: Option(Bool),
    contains: Option(SchemaDefinition),
    min_contains: Option(Int),
    max_contains: Option(Int),
  )
  Object(
    properties: List(#(String, SchemaDefinition)),
    additional_properties: Option(Bool),
    required: Option(List(String)),
  )
  DetailedObject(
    properties: Option(List(#(String, SchemaDefinition))),
    pattern_properties: Option(List(#(String, SchemaDefinition))),
    additional_properties: Option(SchemaDefinition),
    required: Option(List(String)),
    property_names: Option(SchemaDefinition),
    min_properties: Option(Int),
    max_properties: Option(Int),
  )
  AllOf(schemas: List(SchemaDefinition))
  AnyOf(schemas: List(SchemaDefinition))
  OneOf(schemas: List(SchemaDefinition))
  Not(schema: SchemaDefinition)
  Ref(ref: String)
  TrueValue
  FalseValue
}

Constructors

  • Type(type_: SchemaType)
  • Enum(values: List(json.Json))
  • Const(value: json.Json)
  • Nullable(schema: SchemaDefinition)
  • Number(
      minimum: Option(Float),
      maximum: Option(Float),
      exclusive_minimum: Option(Float),
      exclusive_maximum: Option(Float),
      multiple_of: Option(Float),
    )
  • String(
      min_length: Option(Int),
      max_length: Option(Int),
      pattern: Option(String),
      format: Option(StringFormat),
    )
  • Array(items: Option(SchemaDefinition))
  • DetailedArray(
      items: Option(SchemaDefinition),
      prefix_items: Option(List(SchemaDefinition)),
      min_items: Option(Int),
      max_items: Option(Int),
      unique_items: Option(Bool),
      contains: Option(SchemaDefinition),
      min_contains: Option(Int),
      max_contains: Option(Int),
    )
  • Object(
      properties: List(#(String, SchemaDefinition)),
      additional_properties: Option(Bool),
      required: Option(List(String)),
    )
  • DetailedObject(
      properties: Option(List(#(String, SchemaDefinition))),
      pattern_properties: Option(List(#(String, SchemaDefinition))),
      additional_properties: Option(SchemaDefinition),
      required: Option(List(String)),
      property_names: Option(SchemaDefinition),
      min_properties: Option(Int),
      max_properties: Option(Int),
    )
  • AllOf(schemas: List(SchemaDefinition))
  • AnyOf(schemas: List(SchemaDefinition))
  • OneOf(schemas: List(SchemaDefinition))
  • Not(schema: SchemaDefinition)
  • Ref(ref: String)
  • TrueValue
  • FalseValue

Represents the allowed basic JSON Schema types

pub type SchemaType {
  Null
  BooleanType
  ObjectType
  ArrayType
  NumberType
  StringType
  IntegerType
  Multiple(List(SchemaType))
}

Constructors

  • Null
  • BooleanType
  • ObjectType
  • ArrayType
  • NumberType
  • StringType
  • IntegerType
  • Multiple(List(SchemaType))

Common string formats defined in the spec

pub type StringFormat {
  DateTime
  Date
  Time
  Duration
  Email
  IdnEmail
  Hostname
  IdnHostname
  Ipv4
  Ipv6
  Uri
  UriReference
  Iri
  IriReference
  UriTemplate
  JsonPointer
  RelativeJsonPointer
  Regex
}

Constructors

  • DateTime
  • Date
  • Time
  • Duration
  • Email
  • IdnEmail
  • Hostname
  • IdnHostname
  • Ipv4
  • Ipv6
  • Uri
  • UriReference
  • Iri
  • IriReference
  • UriTemplate
  • JsonPointer
  • RelativeJsonPointer
  • Regex

Constants

pub const json_schema_version: String

Functions

pub fn new_schema(definition: SchemaDefinition) -> Schema

Helper function to create a new schema with default values

pub fn number_constraint(
  minimum minimum: Option(Float),
  maximum maximum: Option(Float),
  exclusive_minimum exclusive_minimum: Option(Float),
  exclusive_maximum exclusive_maximum: Option(Float),
  multiple_of multiple_of: Option(Float),
) -> SchemaDefinition

Helper to create a number constraint

pub fn string_constraint(
  min_length min_length: Option(Int),
  max_length max_length: Option(Int),
  pattern pattern: Option(String),
  format format: Option(StringFormat),
) -> SchemaDefinition

Helper to create a string constraint

pub fn to_json(schema: Schema) -> Json

Convert a Schema to JSON value

pub fn to_json_string(schema: Schema) -> String

Convert a Schema to JSON string

pub fn type_constraint(type_: SchemaType) -> SchemaDefinition

Helper to create a basic type constraint

Search Document