-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.d.ts
166 lines (154 loc) · 4.34 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// These typings are experimental and known to be incomplete.
// Help wanted at https://github.com/ExodusMovement/schemasafe/issues/130
type Json = string | number | boolean | null | Array<Json> | { [id: string]: Json }
type Schema =
| true
| false
| {
// version
$schema?: string
$vocabulary?: string
// pointers
id?: string
$id?: string
$anchor?: string
$ref?: string
definitions?: Partial<{ [id: string]: Schema }>
$defs?: Partial<{ [id: string]: Schema }>
$recursiveRef?: string
$recursiveAnchor?: boolean
// generic
type?: string | Array<string>
required?: Array<string>
default?: Json
// constant values
enum?: Array<Json>
const?: Json
// logical checks
not?: Schema
allOf?: Array<Schema>
anyOf?: Array<Schema>
oneOf?: Array<Schema>
if?: Schema
then?: Schema
else?: Schema
// numbers
maximum?: number
minimum?: number
exclusiveMaximum?: number | boolean
exclusiveMinimum?: number | boolean
multipleOf?: number
divisibleBy?: number
// arrays, basic
items?: Schema | Array<Schema>
maxItems?: number
minItems?: number
additionalItems?: Schema
// arrays, complex
contains?: Schema
minContains?: number
maxContains?: number
uniqueItems?: boolean
// strings
maxLength?: number
minLength?: number
format?: string
pattern?: string
// strings content
contentEncoding?: string
contentMediaType?: string
contentSchema?: Schema
// objects
properties?: Partial<{ [id: string]: Schema }>
maxProperties?: number
minProperties?: number
additionalProperties?: Schema
patternProperties?: Partial<{ [pattern: string]: Schema }>
propertyNames?: Schema
dependencies?: Partial<{ [id: string]: Array<string> | Schema }>
dependentRequired?: Partial<{ [id: string]: Array<string> }>
dependentSchemas?: Partial<{ [id: string]: Schema }>
// see-through
unevaluatedProperties?: Schema
unevaluatedItems?: Schema
// Unused meta keywords not affecting validation (annotations and comments)
// https://json-schema.org/understanding-json-schema/reference/generic.html
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9
title?: string
description?: string
deprecated?: boolean
readOnly?: boolean
writeOnly?: boolean
examples?: Array<Json>
$comment?: string
// optimization hint and error filtering only, does not affect validation result
discriminator?: { propertyName: string; mapping?: { [value: string]: string } }
}
interface ValidationError {
keywordLocation: string
instanceLocation: string
}
interface Validate {
(value: Json): boolean
errors?: ValidationError[]
toModule(): string
toJSON(): Schema
}
interface ValidatorOptions {
mode?: string
useDefaults?: boolean
removeAdditional?: boolean | string
includeErrors?: boolean
allErrors?: boolean
contentValidation?: boolean
dryRun?: boolean
lint?: boolean
allowUnusedKeywords?: boolean
allowUnreachable?: boolean
requireSchema?: boolean
requireValidation?: boolean
requireStringValidation?: boolean
forbidNoopValues?: boolean
complexityChecks?: boolean
unmodifiedPrototypes?: boolean
isJSON?: boolean
jsonCheck?: boolean
$schemaDefault?: string | null
formatAssertion?: boolean
formats?: { [key: string]: RegExp | ((input: string) => boolean) }
weakFormats?: boolean
extraFormats?: boolean
schemas?: Map<string, Schema> | Array<Schema> | { [id: string]: Schema }
}
interface ParseResult {
valid: boolean
value?: Json
error?: string
errors?: ValidationError[]
}
interface Parse {
(value: string): ParseResult
toModule(): string
toJSON(): Schema
}
interface LintError {
message: string
keywordLocation: string
schema: Schema
}
declare const validator: (schema: Schema, options?: ValidatorOptions) => Validate
declare const parser: (schema: Schema, options?: ValidatorOptions) => Parse
declare const lint: (schema: Schema, options?: ValidatorOptions) => LintError[]
export {
validator,
parser,
lint,
Validate,
ValidationError,
ValidatorOptions,
ParseResult,
Parse,
LintError,
Json,
Schema,
}