Thanks to visit codestin.com
Credit goes to effect-ts.github.io

Skip to main content Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

JSONSchema.ts overview

Since v3.10.0


Exports Grouped by Category


encoding

fromAST

Returns a JSON Schema with additional options and definitions.

Warning

This function is experimental and subject to change.

Options

  • definitions: A record of definitions that are included in the schema.
  • definitionPath: The path to the definitions within the schema (defaults to “#/$defs/”).
  • target: Which spec to target. Possible values are:
    • 'jsonSchema7': JSON Schema draft-07 (default behavior).
    • 'jsonSchema2019-09': JSON Schema draft-2019-09.
    • 'openApi3.1': OpenAPI 3.1.
  • topLevelReferenceStrategy: Controls the handling of the top-level reference. Possible values are:
    • "keep": Keep the top-level reference (default behavior).
    • "skip": Skip the top-level reference.
  • additionalPropertiesStrategy: Controls the handling of additional properties. Possible values are:
    • "strict": Disallow additional properties (default behavior).
    • "allow": Allow additional properties.

Signature

declare const fromAST: (
  ast: AST.AST,
  options: {
    readonly definitions: Record<string, JsonSchema7>
    readonly definitionPath?: string | undefined
    readonly target?: Target | undefined
    readonly topLevelReferenceStrategy?: TopLevelReferenceStrategy | undefined
    readonly additionalPropertiesStrategy?: AdditionalPropertiesStrategy | undefined
  }
) => JsonSchema7

Source

Since v3.11.5

make

Generates a JSON Schema from a schema.

Options

  • target: The target JSON Schema version. Possible values are:
    • "jsonSchema7": JSON Schema draft-07 (default behavior).
    • "jsonSchema2019-09": JSON Schema draft-2019-09.
    • "jsonSchema2020-12": JSON Schema draft-2020-12.
    • "openApi3.1": OpenAPI 3.1.

Signature

declare const make: <A, I, R>(
  schema: Schema.Schema<A, I, R>,
  options?: { readonly target?: Target | undefined }
) => JsonSchema7Root

Source

Since v3.10.0

model

JsonSchema7 (type alias)

Signature

type JsonSchema7 =
  | JsonSchema7Never
  | JsonSchema7Any
  | JsonSchema7Unknown
  | JsonSchema7Void
  | JsonSchema7object
  | JsonSchema7empty
  | JsonSchema7Ref
  | JsonSchema7Null
  | JsonSchema7String
  | JsonSchema7Number
  | JsonSchema7Integer
  | JsonSchema7Boolean
  | JsonSchema7Array
  | JsonSchema7Enum
  | JsonSchema7Enums
  | JsonSchema7AnyOf
  | JsonSchema7Object

Source

Since v3.10.0

JsonSchema7Any (interface)

Signature

export interface JsonSchema7Any extends JsonSchemaAnnotations {
  $id: "/schemas/any"
}

Source

Since v3.10.0

JsonSchema7AnyOf (interface)

Signature

export interface JsonSchema7AnyOf extends JsonSchemaAnnotations {
  anyOf: Array<JsonSchema7>
}

Source

Since v3.10.0

JsonSchema7Array (interface)

Signature

export interface JsonSchema7Array extends JsonSchemaAnnotations {
  type: "array"
  items?: JsonSchema7 | Array<JsonSchema7> | false
  prefixItems?: Array<JsonSchema7>
  minItems?: number
  maxItems?: number
  additionalItems?: JsonSchema7 | boolean
}

Source

Since v3.10.0

JsonSchema7Boolean (interface)

Signature

export interface JsonSchema7Boolean extends JsonSchemaAnnotations {
  type: "boolean"
}

Source

Since v3.10.0

JsonSchema7Enum (interface)

Signature

export interface JsonSchema7Enum extends JsonSchemaAnnotations {
  type?: "string" | "number" | "boolean"
  enum: Array<string | number | boolean>
}

Source

Since v3.10.0

JsonSchema7Enums (interface)

Signature

export interface JsonSchema7Enums extends JsonSchemaAnnotations {
  $comment: "/schemas/enums"
  anyOf: Array<{
    type: "string" | "number"
    title: string
    enum: [string | number]
  }>
}

Source

Since v3.10.0

JsonSchema7Integer (interface)

Signature

export interface JsonSchema7Integer extends JsonSchema7Numeric {
  type: "integer"
}

Source

Since v3.10.0

JsonSchema7Never (interface)

Signature

export interface JsonSchema7Never extends JsonSchemaAnnotations {
  $id: "/schemas/never"
  not: {}
}

Source

Since v3.11.5

JsonSchema7Null (interface)

Signature

export interface JsonSchema7Null extends JsonSchemaAnnotations {
  type: "null"
}

Source

Since v3.11.7

JsonSchema7Number (interface)

Signature

export interface JsonSchema7Number extends JsonSchema7Numeric {
  type: "number"
}

Source

Since v3.10.0

JsonSchema7Numeric (interface)

Signature

export interface JsonSchema7Numeric extends JsonSchemaAnnotations {
  minimum?: number
  exclusiveMinimum?: number
  maximum?: number
  exclusiveMaximum?: number
  multipleOf?: number
  allOf?: Array<{
    minimum?: number
    exclusiveMinimum?: number
    maximum?: number
    exclusiveMaximum?: number
    multipleOf?: number
  }>
}

Source

Since v3.10.0

JsonSchema7Object (interface)

Signature

export interface JsonSchema7Object extends JsonSchemaAnnotations {
  type: "object"
  required: Array<string>
  properties: Record<string, JsonSchema7>
  additionalProperties?: boolean | JsonSchema7
  patternProperties?: Record<string, JsonSchema7>
  propertyNames?: JsonSchema7
}

Source

Since v3.10.0

JsonSchema7Ref (interface)

Signature

export interface JsonSchema7Ref extends JsonSchemaAnnotations {
  $ref: string
}

Source

Since v3.10.0

JsonSchema7Root (type alias)

Signature

type JsonSchema7Root = JsonSchema7 & {
  $schema?: string
  $defs?: Record<string, JsonSchema7>
}

Source

Since v3.10.0

JsonSchema7String (interface)

Signature

export interface JsonSchema7String extends JsonSchemaAnnotations {
  type: "string"
  minLength?: number
  maxLength?: number
  pattern?: string
  format?: string
  contentMediaType?: string
  allOf?: Array<{
    minLength?: number
    maxLength?: number
    pattern?: string
  }>
}

Source

Since v3.10.0

JsonSchema7Unknown (interface)

Signature

export interface JsonSchema7Unknown extends JsonSchemaAnnotations {
  $id: "/schemas/unknown"
}

Source

Since v3.10.0

JsonSchema7Void (interface)

Signature

export interface JsonSchema7Void extends JsonSchemaAnnotations {
  $id: "/schemas/void"
}

Source

Since v3.10.0

JsonSchema7empty (interface)

Signature

export interface JsonSchema7empty extends JsonSchemaAnnotations {
  $id: "/schemas/%7B%7D"
  anyOf: [{ type: "object" }, { type: "array" }]
}

Source

Since v3.10.0

JsonSchema7object (interface)

Signature

export interface JsonSchema7object extends JsonSchemaAnnotations {
  $id: "/schemas/object"
  anyOf: [{ type: "object" }, { type: "array" }]
}

Source

Since v3.10.0

JsonSchemaAnnotations (interface)

Signature

export interface JsonSchemaAnnotations {
  title?: string
  description?: string
  default?: JsonValue
  examples?: Array<JsonValue>
}

Source

Since v3.10.0