UNPKG

3.77 kBTypeScriptView Raw
1/// <reference types="lodash" />
2import { JSONSchema4, JSONSchema4Type, JSONSchema4TypeName } from 'json-schema';
3export type SchemaType = 'ALL_OF' | 'UNNAMED_SCHEMA' | 'ANY' | 'ANY_OF' | 'BOOLEAN' | 'NAMED_ENUM' | 'NAMED_SCHEMA' | 'NEVER' | 'NULL' | 'NUMBER' | 'STRING' | 'OBJECT' | 'ONE_OF' | 'TYPED_ARRAY' | 'REFERENCE' | 'UNION' | 'UNNAMED_ENUM' | 'UNTYPED_ARRAY' | 'CUSTOM_TYPE';
4export type JSONSchemaTypeName = JSONSchema4TypeName;
5export type JSONSchemaType = JSONSchema4Type;
6export interface JSONSchema extends JSONSchema4 {
7 /**
8 * schema extension to support numeric enums
9 */
10 tsEnumNames?: string[];
11 /**
12 * schema extension to support custom types
13 */
14 tsType?: string;
15 /**
16 * property exists at least in https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9.3
17 */
18 deprecated?: boolean;
19}
20export declare const Parent: unique symbol;
21export interface LinkedJSONSchema extends JSONSchema {
22 /**
23 * A reference to this schema's parent node, for convenience.
24 * `null` when this is the root schema.
25 */
26 [Parent]: LinkedJSONSchema | null;
27 additionalItems?: boolean | LinkedJSONSchema;
28 additionalProperties?: boolean | LinkedJSONSchema;
29 items?: LinkedJSONSchema | LinkedJSONSchema[];
30 definitions?: {
31 [k: string]: LinkedJSONSchema;
32 };
33 properties?: {
34 [k: string]: LinkedJSONSchema;
35 };
36 patternProperties?: {
37 [k: string]: LinkedJSONSchema;
38 };
39 dependencies?: {
40 [k: string]: LinkedJSONSchema | string[];
41 };
42 allOf?: LinkedJSONSchema[];
43 anyOf?: LinkedJSONSchema[];
44 oneOf?: LinkedJSONSchema[];
45 not?: LinkedJSONSchema;
46}
47export declare const Types: unique symbol;
48export declare const Intersection: unique symbol;
49/**
50 * Normalized JSON schema.
51 *
52 * Note: `definitions` and `id` are removed by the normalizer. Use `$defs` and `$id` instead.
53 */
54export interface NormalizedJSONSchema extends Omit<LinkedJSONSchema, 'definitions' | 'id'> {
55 [Intersection]?: NormalizedJSONSchema;
56 [Parent]: NormalizedJSONSchema | null;
57 [Types]: ReadonlySet<SchemaType>;
58 additionalItems?: boolean | NormalizedJSONSchema;
59 additionalProperties: boolean | NormalizedJSONSchema;
60 extends?: string[];
61 items?: NormalizedJSONSchema | NormalizedJSONSchema[];
62 $defs?: {
63 [k: string]: NormalizedJSONSchema;
64 };
65 properties?: {
66 [k: string]: NormalizedJSONSchema;
67 };
68 patternProperties?: {
69 [k: string]: NormalizedJSONSchema;
70 };
71 dependencies?: {
72 [k: string]: NormalizedJSONSchema | string[];
73 };
74 allOf?: NormalizedJSONSchema[];
75 anyOf?: NormalizedJSONSchema[];
76 oneOf?: NormalizedJSONSchema[];
77 not?: NormalizedJSONSchema;
78 required: string[];
79}
80export interface EnumJSONSchema extends NormalizedJSONSchema {
81 enum: JSONSchema4Type[];
82}
83export interface NamedEnumJSONSchema extends NormalizedJSONSchema {
84 tsEnumNames: string[];
85}
86export interface SchemaSchema extends NormalizedJSONSchema {
87 properties: {
88 [k: string]: NormalizedJSONSchema;
89 };
90 required: string[];
91}
92export interface JSONSchemaWithDefinitions extends NormalizedJSONSchema {
93 $defs: {
94 [k: string]: NormalizedJSONSchema;
95 };
96}
97export interface CustomTypeJSONSchema extends NormalizedJSONSchema {
98 tsType: string;
99}
100export declare const getRootSchema: ((schema: NormalizedJSONSchema) => NormalizedJSONSchema) & import("lodash").MemoizedFunction;
101export declare function isBoolean(schema: LinkedJSONSchema | JSONSchemaType): schema is boolean;
102export declare function isPrimitive(schema: LinkedJSONSchema | JSONSchemaType): schema is JSONSchemaType;
103export declare function isCompound(schema: JSONSchema): boolean;
104
\No newline at end of file