nori/schema

JSON Schema types for OpenAPI 3.1.x.

OpenAPI 3.1.x uses JSON Schema Draft 2020-12 for schema definitions. This module provides comprehensive types for JSON Schema with OpenAPI extensions.

Types

Additional properties can be a boolean or a schema.

pub type AdditionalProperties {
  AdditionalPropertiesBool(Bool)
  AdditionalPropertiesSchema(reference.Ref(Schema))
}

Constructors

Discriminator for polymorphism in OpenAPI.

pub type Discriminator {
  Discriminator(
    property_name: String,
    mapping: option.Option(dict.Dict(String, String)),
    extensions: dict.Dict(String, json.Json),
  )
}

Constructors

External documentation reference.

pub type ExternalDocumentation {
  ExternalDocumentation(
    url: String,
    description: option.Option(String),
    extensions: dict.Dict(String, json.Json),
  )
}

Constructors

Common string formats defined in JSON Schema and OpenAPI.

pub type Format {
  FormatDateTime
  FormatDate
  FormatTime
  FormatDuration
  FormatEmail
  FormatIdnEmail
  FormatHostname
  FormatIdnHostname
  FormatIpv4
  FormatIpv6
  FormatUri
  FormatUriReference
  FormatIri
  FormatIriReference
  FormatUuid
  FormatUriTemplate
  FormatJsonPointer
  FormatRelativeJsonPointer
  FormatRegex
  FormatInt32
  FormatInt64
  FormatFloat
  FormatDouble
  FormatByte
  FormatBinary
  FormatPassword
  FormatCustom(String)
}

Constructors

  • FormatDateTime
  • FormatDate
  • FormatTime
  • FormatDuration
  • FormatEmail
  • FormatIdnEmail
  • FormatHostname
  • FormatIdnHostname
  • FormatIpv4
  • FormatIpv6
  • FormatUri
  • FormatUriReference
  • FormatIri
  • FormatIriReference
  • FormatUuid
  • FormatUriTemplate
  • FormatJsonPointer
  • FormatRelativeJsonPointer
  • FormatRegex
  • FormatInt32
  • FormatInt64
  • FormatFloat
  • FormatDouble
  • FormatByte
  • FormatBinary
  • FormatPassword
  • FormatCustom(String)

JSON primitive types.

pub type JsonType {
  TypeNull
  TypeBoolean
  TypeInteger
  TypeNumber
  TypeString
  JsonTypeArray
  TypeObject
}

Constructors

  • TypeNull
  • TypeBoolean
  • TypeInteger
  • TypeNumber
  • TypeString
  • JsonTypeArray
  • TypeObject

JSON Schema object following Draft 2020-12 with OpenAPI extensions.

pub type Schema {
  Schema(
    schema: option.Option(String),
    vocabulary: option.Option(dict.Dict(String, Bool)),
    id: option.Option(String),
    anchor: option.Option(String),
    dynamic_anchor: option.Option(String),
    ref: option.Option(String),
    dynamic_ref: option.Option(String),
    defs: option.Option(dict.Dict(String, Schema)),
    comment: option.Option(String),
    all_of: List(reference.Ref(Schema)),
    any_of: List(reference.Ref(Schema)),
    one_of: List(reference.Ref(Schema)),
    not: option.Option(reference.Ref(Schema)),
    if_schema: option.Option(reference.Ref(Schema)),
    then_schema: option.Option(reference.Ref(Schema)),
    else_schema: option.Option(reference.Ref(Schema)),
    dependent_schemas: option.Option(
      dict.Dict(String, reference.Ref(Schema)),
    ),
    prefix_items: List(reference.Ref(Schema)),
    items: option.Option(reference.Ref(Schema)),
    contains: option.Option(reference.Ref(Schema)),
    properties: dict.Dict(String, reference.Ref(Schema)),
    pattern_properties: option.Option(
      dict.Dict(String, reference.Ref(Schema)),
    ),
    additional_properties: option.Option(AdditionalProperties),
    property_names: option.Option(reference.Ref(Schema)),
    unevaluated_items: option.Option(reference.Ref(Schema)),
    unevaluated_properties: option.Option(reference.Ref(Schema)),
    schema_type: option.Option(SchemaType),
    const_value: option.Option(json.Json),
    enum_values: option.Option(List(json.Json)),
    multiple_of: option.Option(Float),
    maximum: option.Option(Float),
    exclusive_maximum: option.Option(Float),
    minimum: option.Option(Float),
    exclusive_minimum: option.Option(Float),
    max_length: option.Option(Int),
    min_length: option.Option(Int),
    pattern: option.Option(String),
    max_items: option.Option(Int),
    min_items: option.Option(Int),
    unique_items: option.Option(Bool),
    max_contains: option.Option(Int),
    min_contains: option.Option(Int),
    max_properties: option.Option(Int),
    min_properties: option.Option(Int),
    required: List(String),
    dependent_required: option.Option(
      dict.Dict(String, List(String)),
    ),
    format: option.Option(String),
    content_encoding: option.Option(String),
    content_media_type: option.Option(String),
    content_schema: option.Option(reference.Ref(Schema)),
    title: option.Option(String),
    description: option.Option(String),
    default: option.Option(json.Json),
    deprecated: option.Option(Bool),
    read_only: option.Option(Bool),
    write_only: option.Option(Bool),
    examples: option.Option(List(json.Json)),
    discriminator: option.Option(Discriminator),
    xml: option.Option(Xml),
    external_docs: option.Option(ExternalDocumentation),
    example: option.Option(json.Json),
    extensions: dict.Dict(String, json.Json),
  )
}

Constructors

Schema type following JSON Schema Draft 2020-12.

In OpenAPI 3.1.x, type can be a single type or an array of types to support nullable fields (e.g., ["string", "null"]).

pub type SchemaType {
  SingleType(JsonType)
  MultipleTypes(List(JsonType))
}

Constructors

  • SingleType(JsonType)

    Single type

  • MultipleTypes(List(JsonType))

    Array of types (e.g., for nullable: [“string”, “null”])

XML metadata for OpenAPI.

pub type Xml {
  Xml(
    name: option.Option(String),
    namespace: option.Option(String),
    prefix: option.Option(String),
    attribute: option.Option(Bool),
    wrapped: option.Option(Bool),
    extensions: dict.Dict(String, json.Json),
  )
}

Constructors

Values

pub fn empty() -> Schema

Creates an empty schema with all fields set to None/empty.

pub fn format_to_string(format: Format) -> String

Converts a Format to its string representation.

pub fn parse_format(format_string: String) -> Format

Parses a format string into a Format.

Search Document