@schema-kit/json-schema
TypeScript icon, indicating that this package has built-in type declarations

1.5.0 • Public • Published

JSON Schema transform for Schema Kit

About Schema Kit

Schema Kit allows you to create a meta-schema that can be transformed into TypeScript, JSON Schema, and more.

Usage

Schema Kit JSON Schema
never() false
any() {}
buildConst(value) { const: value }
buildNull() null
boolean() { type: "boolean" }
number() { type: "number" }
integer() { type: "integer" }
string() { type: "string" }
stringEnum(values) { type: "string", enum: values }
optional(schema) excluded from required array
object(props) { type: "object", properties: { ... } }
array(schema) { type: "array", items: schema }
union(schemas) { anyOf: schemas }

Optional nodes only make sense in the context of object node property values.

For const, the appropriate type will be included if the value is null, a boolean, a number, a string, or an array.

import { toJsonSchema } from "@schema-kit/json-schema"

toJsonSchema(schema)

Converts the input schema into JSON Schema.

Parameters:

  • schema - The input schema.

Returns: false | object - The output JSON Schema.

Options

The Schema Kit schema builders can be passed an optional options object to further describe their schema.

Check the JSON Schema documentation for information on how to use these options.

Common options

  • title
  • description
  • default
  • examples
  • raw - Merges an object into the schema.

Numeric: number and integer

  • multipleOf
  • minimum
  • maximum
  • exclusiveMinimum
  • exclusiveMaximum

string

  • minLength
  • maxLength
  • pattern
  • format

array

  • minLength
  • maxLength
  • uniqueItems

/@schema-kit/json-schema/

    Package Sidebar

    Install

    npm i @schema-kit/json-schema

    Weekly Downloads

    1

    Version

    1.5.0

    License

    MIT

    Unpacked Size

    43.3 kB

    Total Files

    15

    Last publish

    Collaborators

    • seangenabe