json_typedef

https://jsontypedef.com/

https://datatracker.ietf.org/doc/html/rfc8927

Types

pub type CodegenError {
  CannotConvertEmptyToJsonError
  EmptyEnumError
  DuplicatePropertyError(
    type_name: String,
    constructor_name: String,
    property_name: String,
  )
  DuplicateConstructorError(name: String)
  DuplicateTypeError(name: String)
  DuplicateFunctionError(name: String)
}

Constructors

  • CannotConvertEmptyToJsonError
  • EmptyEnumError
  • DuplicatePropertyError(
      type_name: String,
      constructor_name: String,
      property_name: String,
    )
  • DuplicateConstructorError(name: String)
  • DuplicateTypeError(name: String)
  • DuplicateFunctionError(name: String)
pub opaque type Generator
pub type PropertiesSchema {
  PropertiesSchema(
    properties: List(#(String, Schema)),
    optional_properties: List(#(String, Schema)),
    additional_properties: Bool,
  )
}

Constructors

  • PropertiesSchema(
      properties: List(#(String, Schema)),
      optional_properties: List(#(String, Schema)),
      additional_properties: Bool,
    )
pub type RootSchema {
  RootSchema(
    definitions: List(#(String, Schema)),
    schema: Schema,
  )
}

Constructors

  • RootSchema(definitions: List(#(String, Schema)), schema: Schema)
pub type Schema {
  Empty
  Type(
    nullable: Bool,
    metadata: List(#(String, Dynamic)),
    type_: Type,
  )
  Enum(
    nullable: Bool,
    metadata: List(#(String, Dynamic)),
    variants: List(String),
  )
  Properties(
    nullable: Bool,
    metadata: List(#(String, Dynamic)),
    schema: PropertiesSchema,
  )
  Elements(
    nullable: Bool,
    metadata: List(#(String, Dynamic)),
    schema: Schema,
  )
  Values(
    nullable: Bool,
    metadata: List(#(String, Dynamic)),
    schema: Schema,
  )
  Discriminator(
    nullable: Bool,
    metadata: List(#(String, Dynamic)),
    tag: String,
    mapping: List(#(String, PropertiesSchema)),
  )
  Ref(
    nullable: Bool,
    metadata: List(#(String, Dynamic)),
    name: String,
  )
}

Constructors

  • Empty

    Any value. The empty form is like a Java Object or TypeScript any.

  • Type(
      nullable: Bool,
      metadata: List(#(String, Dynamic)),
      type_: Type,
    )

    A simple built-in type. The type form is like a Java or TypeScript primitive type.

  • Enum(
      nullable: Bool,
      metadata: List(#(String, Dynamic)),
      variants: List(String),
    )

    One of a fixed set of strings. The enum form is like a Java or TypeScript enum.

  • Properties(
      nullable: Bool,
      metadata: List(#(String, Dynamic)),
      schema: PropertiesSchema,
    )
  • Elements(
      nullable: Bool,
      metadata: List(#(String, Dynamic)),
      schema: Schema,
    )

    A sequence of some other form. The elements form is like a Java List<T> or TypeScript T[].

  • Values(
      nullable: Bool,
      metadata: List(#(String, Dynamic)),
      schema: Schema,
    )

    A dictionary with string keys and some form values. The values form is like a Java Map<String, T> or TypeScript { [key: string]: T}.

  • Discriminator(
      nullable: Bool,
      metadata: List(#(String, Dynamic)),
      tag: String,
      mapping: List(#(String, PropertiesSchema)),
    )

    The discriminator form is like a tagged union.

  • Ref(
      nullable: Bool,
      metadata: List(#(String, Dynamic)),
      name: String,
    )

    The ref form is for re-using schemas, usually so you can avoid repeating yourself.

pub type Type {
  Boolean
  String
  Timestamp
  Float32
  Float64
  Int8
  Uint8
  Int16
  Uint16
  Int32
  Uint32
}

Constructors

  • Boolean

    true or false

  • String

    JSON strings

  • Timestamp

    JSON strings containing an RFC3339 timestamp

  • Float32

    JSON numbers

  • Float64

    JSON numbers

  • Int8

    Whole JSON numbers that fit in a signed 8-bit integer

  • Uint8

    Whole JSON numbers that fit in an unsigned 8-bit integer

  • Int16

    Whole JSON numbers that fit in a signed 16-bit integer

  • Uint16

    Whole JSON numbers that fit in an unsigned 16-bit integer

  • Int32

    Whole JSON numbers that fit in a signed 32-bit integer

  • Uint32

    Whole JSON numbers that fit in an unsigned 32-bit integer

Functions

pub fn codegen() -> Generator
pub fn decoder(
  data: Dynamic,
) -> Result(RootSchema, List(DecodeError))
pub fn generate(
  gen: Generator,
  schema: RootSchema,
) -> Result(String, CodegenError)
pub fn generate_decoders(gen: Generator, x: Bool) -> Generator
pub fn generate_encoders(gen: Generator, x: Bool) -> Generator
pub fn root_name(gen: Generator, root_name: String) -> Generator
pub fn to_json(schema: RootSchema) -> Json
Search Document