Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "schema"

Module schema provides code to safely handle JSON Typedef schemas.

JSON Typedef schemas are represented in this module with Schema, and you can check if a JSON object is a correct schema by using isSchema and isValidSchema.

Index

Type aliases

Schema

Schema is a TypeScript representation of a correct JSON Typedef schema.

The JSON Typedef specification allows schemas to take on one of eight forms. Each of those forms has its own type in this module; Schema is simply a union of each of those eight types.

SchemaFormDiscriminator

SchemaFormDiscriminator: SharedFormProperties & { discriminator: string; mapping: {} }

SchemaFormDiscriminator represents schemas of the discriminator form.

SchemaFormElements

SchemaFormElements: SharedFormProperties & { elements: Schema }

SchemaFormElements represents schemas of the elements form.

SchemaFormEmpty

SchemaFormEmpty: SharedFormProperties

SchemaFormEmpty represents schemas of the empty form.

SchemaFormEnum

SchemaFormEnum: SharedFormProperties & { enum: string[] }

SchemaFormEnum represents schemas of the enum form.

SchemaFormProperties

SchemaFormProperties: SharedFormProperties & { additionalProperties?: undefined | false | true; optionalProperties: {}; properties?: undefined | {} } | { additionalProperties?: undefined | false | true; optionalProperties?: undefined | {}; properties: {} }

SchemaFormProperties represents schemas of the properties form.

SchemaFormRef

SchemaFormRef: SharedFormProperties & { ref: string }

SchemaFormRef represents schemas of the ref form.

SchemaFormType

SchemaFormType: SharedFormProperties & { type: Type }

SchemaFormType represents schemas of the type form.

SchemaFormValues

SchemaFormValues: SharedFormProperties & { values: Schema }

SchemaFormValues represents schemas of the values form.

Type

Type: "boolean" | "float32" | "float64" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "string" | "timestamp"

Type represents the legal values of the "type" keyword in JSON Typedef.

Variables

Const VALID_FORMS

VALID_FORMS: boolean[][] = [// Empty form[false, false, false, false, false, false, false, false, false, false],// Ref form[true, false, false, false, false, false, false, false, false, false],// Type form[false, true, false, false, false, false, false, false, false, false],// Enum form[false, false, true, false, false, false, false, false, false, false],// Elements form[false, false, false, true, false, false, false, false, false, false],// Properties form -- properties or optional properties or both, and never// additional properties on its own[false, false, false, false, true, false, false, false, false, false],[false, false, false, false, false, true, false, false, false, false],[false, false, false, false, true, true, false, false, false, false],[false, false, false, false, true, false, true, false, false, false],[false, false, false, false, false, true, true, false, false, false],[false, false, false, false, true, true, true, false, false, false],// Values form[false, false, false, false, false, false, false, true, false, false],// Discriminator form[false, false, false, false, false, false, false, false, true, true],]

Const VALID_TYPES

VALID_TYPES: string[] = ["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp",]

Functions

isDiscriminatorForm

  • isDiscriminatorForm(schema: Schema): schema is SchemaFormDiscriminator
  • isDiscriminatorForm checks whether some Schema is of the values form.

    Parameters

    • schema: Schema

      The schema to validate

    Returns schema is SchemaFormDiscriminator

isElementsForm

  • isElementsForm(schema: Schema): schema is SchemaFormElements
  • isElementsForm checks whether some Schema is of the elements form.

    Parameters

    • schema: Schema

      The schema to validate

    Returns schema is SchemaFormElements

isEmptyForm

  • isEmptyForm(schema: Schema): schema is SchemaFormEmpty
  • isEmptyForm checks whether some Schema is of the empty form.

    Parameters

    • schema: Schema

      The schema to validate

    Returns schema is SchemaFormEmpty

isEnumForm

  • isEnumForm(schema: Schema): schema is SchemaFormEnum
  • isEnumForm checks whether some Schema is of the enum form.

    Parameters

    • schema: Schema

      The schema to validate

    Returns schema is SchemaFormEnum

isPropertiesForm

  • isPropertiesForm(schema: Schema): schema is SchemaFormProperties
  • isPropertiesForm checks whether some Schema is of the properties form.

    Parameters

    • schema: Schema

      The schema to validate

    Returns schema is SchemaFormProperties

isRefForm

  • isRefForm(schema: Schema): schema is SchemaFormRef
  • isRefForm checks whether some Schema is of the ref form.

    Parameters

    • schema: Schema

      The schema to validate

    Returns schema is SchemaFormRef

isSchema

  • isSchema(data: unknown): data is Schema
  • isSchema checks whether some piece of JSON data has the shape of a JSON Typedef Schema.

    This function only looks at the "shape" of data: it just makes sure all property names and types are valid, and that the data takes on one of the eight JSON Typedef forms.

    If an object returned from JSON.parse passes both isSchema and isValidSchema, then it is a correct JSON Typedef schema.

    Parameters

    • data: unknown

      The data to check

    Returns data is Schema

isTypeForm

  • isTypeForm(schema: Schema): schema is SchemaFormType
  • isTypeForm checks whether some Schema is of the type form.

    Parameters

    • schema: Schema

      The schema to validate

    Returns schema is SchemaFormType

isValidSchema

  • isValidSchema checks whether some Schema is correct, according to the syntax rules of JSON Typedef.

    In particular, isValidSchema verifies that:

    1. The schema does not have any non-root definitions,
    2. All references point to actually-existing definitions,
    3. All enums are non-empty, and do not contain duplicates,
    4. The properties and optionalProperties of a schema never share properties,
    5. All schemas in mapping are of the properties form,
    6. Schemas in mapping never re-specify the discriminator property

    If an object returned from JSON.parse passes both isSchema and isValidSchema, then it is a correct JSON Typedef schema.

    Parameters

    • schema: Schema

      The schema to validate

    • Optional root: Schema

      The schema to consider as the "root" schema. If undefined, schema will be used as the root. This is usually what you want to do.

    Returns boolean

isValuesForm

  • isValuesForm(schema: Schema): schema is SchemaFormValues
  • isPropertiesForm checks whether some Schema is of the values form.

    Parameters

    • schema: Schema

      The schema to validate

    Returns schema is SchemaFormValues

Generated using TypeDoc