JSONSchema
Encoding
Signature
declare function fromAST(
ast: AST,
options: {
readonly additionalPropertiesStrategy?: AdditionalPropertiesStrategy;
readonly definitionPath?: string;
readonly definitions: Record<string, JsonSchema7>;
readonly target?: Target;
readonly topLevelReferenceStrategy?: TopLevelReferenceStrategy;
},
): JsonSchema7;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 function make<A, I, R>(
schema: Schema<A, I, R>,
options?: {
readonly target?: Target;
},
): JsonSchema7Root;Model
JsonSchema7 type
Added in v3.10.0
Source
Signature
type JsonSchema7 =
| JsonSchema7Never
| JsonSchema7Any
| JsonSchema7Unknown
| JsonSchema7Void
| JsonSchema7object
| JsonSchema7empty
| JsonSchema7Ref
| JsonSchema7Null
| JsonSchema7String
| JsonSchema7Number
| JsonSchema7Integer
| JsonSchema7Boolean
| JsonSchema7Array
| JsonSchema7Enum
| JsonSchema7Enums
| JsonSchema7AnyOf
| JsonSchema7Object;JsonSchema7Any interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Any extends JsonSchemaAnnotations {
$id: "/schemas/any";
}JsonSchema7AnyOf interface
Added in v3.10.0
Source
Signature
interface JsonSchema7AnyOf extends JsonSchemaAnnotations {
anyOf: Array<JsonSchema7>;
}JsonSchema7Array interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Array extends JsonSchemaAnnotations {
additionalItems?: boolean | JsonSchema7;
items?: false | JsonSchema7 | Array<JsonSchema7>;
maxItems?: number;
minItems?: number;
prefixItems?: Array<JsonSchema7>;
type: "array";
}JsonSchema7Boolean interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Boolean extends JsonSchemaAnnotations {
type: "boolean";
}JsonSchema7empty interface
Added in v3.10.0
Source
Signature
interface JsonSchema7empty extends JsonSchemaAnnotations {
$id: "/schemas/%7B%7D";
anyOf: [
{
type: "object";
},
{
type: "array";
},
];
}JsonSchema7Enum interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Enum extends JsonSchemaAnnotations {
enum: Array<string | number | boolean>;
type?: "string" | "number" | "boolean";
}JsonSchema7Enums interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Enums extends JsonSchemaAnnotations {
$comment: "/schemas/enums";
anyOf: Array<{
enum: [string | number];
title: string;
type: "string" | "number";
}>;
}JsonSchema7Integer interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Integer extends JsonSchema7Numeric {
type: "integer";
}JsonSchema7Never interface
Added in v3.11.5
Source
Signature
interface JsonSchema7Never extends JsonSchemaAnnotations {
$id: "/schemas/never";
not: {};
}JsonSchema7Null interface
Added in v3.11.7
Source
Signature
interface JsonSchema7Null extends JsonSchemaAnnotations {
type: "null";
}JsonSchema7Number interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Number extends JsonSchema7Numeric {
type: "number";
}JsonSchema7Numeric interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Numeric extends JsonSchemaAnnotations {
allOf?: Array<{
exclusiveMaximum?: number;
exclusiveMinimum?: number;
maximum?: number;
minimum?: number;
multipleOf?: number;
}>;
exclusiveMaximum?: number;
exclusiveMinimum?: number;
maximum?: number;
minimum?: number;
multipleOf?: number;
}JsonSchema7object interface
Added in v3.10.0
Source
Signature
interface JsonSchema7object extends JsonSchemaAnnotations {
$id: "/schemas/object";
anyOf: [
{
type: "object";
},
{
type: "array";
},
];
}JsonSchema7Object interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Object extends JsonSchemaAnnotations {
additionalProperties?: boolean | JsonSchema7;
patternProperties?: Record<string, JsonSchema7>;
properties: Record<string, JsonSchema7>;
propertyNames?: JsonSchema7;
required: Array<string>;
type: "object";
}JsonSchema7Ref interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Ref extends JsonSchemaAnnotations {
$ref: string;
}JsonSchema7Root type
Added in v3.10.0
Source
Signature
type JsonSchema7Root = JsonSchema7 & {
$defs?: Record<string, JsonSchema7>;
$schema?: string;
};JsonSchema7String interface
Added in v3.10.0
Source
Signature
interface JsonSchema7String extends JsonSchemaAnnotations {
allOf?: Array<{
maxLength?: number;
minLength?: number;
pattern?: string;
}>;
contentMediaType?: string;
format?: string;
maxLength?: number;
minLength?: number;
pattern?: string;
type: "string";
}JsonSchema7Unknown interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Unknown extends JsonSchemaAnnotations {
$id: "/schemas/unknown";
}JsonSchema7Void interface
Added in v3.10.0
Source
Signature
interface JsonSchema7Void extends JsonSchemaAnnotations {
$id: "/schemas/void";
}JsonSchemaAnnotations interface
Added in v3.10.0
Source
Signature
interface JsonSchemaAnnotations {
default?: JsonValue;
description?: string;
examples?: Array<JsonValue>;
title?: string;
}
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.