@@ -14,15 +14,22 @@ export interface JsonSchema {
14
14
writeOnly ?: boolean
15
15
}
16
16
17
- export interface NullJsonSchema extends JsonSchema {
18
- allOf ?: Array < NullJsonSchema > ,
19
- anyOf ?: Array < NullJsonSchema > ,
17
+ export interface ComposedJsonSchema < T = JsonSchema > {
18
+ allOf ?: Array < T > ,
19
+ anyOf ?: Array < T > ,
20
+ not ?: T ,
21
+ oneOf ?: Array < T >
22
+ }
23
+
24
+ export function isComposedJsonSchema ( schema : any ) : schema is ComposedJsonSchema {
25
+ return Array . isArray ( schema . allOf ) || Array . isArray ( schema . anyOf ) || Array . isArray ( schema . oneOf ) || schema . not !== undefined ;
26
+ }
27
+
28
+ export interface NullJsonSchema extends JsonSchema , ComposedJsonSchema < NullJsonSchema > {
20
29
const ?: null ,
21
30
default ?: null ,
22
31
enum ?: Array < null > ,
23
32
examples ?: Array < null > ,
24
- not ?: NullJsonSchema ,
25
- oneOf ?: Array < NullJsonSchema > ,
26
33
type ?: 'null' | Array < 'null' | 'boolean' | 'string' | 'integer' | 'number' | 'array' | 'object' > ,
27
34
}
28
35
@@ -38,15 +45,11 @@ export function isNullJsonSchema(schema: any): schema is NullJsonSchema {
38
45
return false ;
39
46
}
40
47
41
- export interface BooleanJsonSchema extends JsonSchema {
42
- allOf ?: Array < BooleanJsonSchema > ,
43
- anyOf ?: Array < BooleanJsonSchema > ,
48
+ export interface BooleanJsonSchema extends JsonSchema , ComposedJsonSchema < BooleanJsonSchema > {
44
49
const ?: boolean ,
45
50
default ?: boolean ,
46
51
enum ?: Array < boolean > ,
47
52
examples ?: Array < boolean > ,
48
- not ?: BooleanJsonSchema ,
49
- oneOf ?: Array < BooleanJsonSchema > ,
50
53
type ?: 'boolean' | Array < 'null' | 'boolean' | 'string' | 'integer' | 'number' | 'array' | 'object' > ,
51
54
}
52
55
@@ -62,17 +65,13 @@ export function isBooleanJsonSchema(schema: any): schema is BooleanJsonSchema {
62
65
return false ;
63
66
}
64
67
65
- export interface StringJsonSchema extends JsonSchema {
66
- allOf ?: Array < StringJsonSchema > ,
67
- anyOf ?: Array < StringJsonSchema > ,
68
+ export interface StringJsonSchema extends JsonSchema , ComposedJsonSchema < StringJsonSchema > {
68
69
const ?: string ,
69
70
default ?: string ,
70
71
enum ?: Array < string > ,
71
72
examples ?: Array < string > ,
72
73
maxLength ?: number ,
73
74
minLength ?: number ,
74
- not ?: StringJsonSchema ,
75
- oneOf ?: Array < StringJsonSchema > ,
76
75
pattern ?: string ,
77
76
type ?: 'string' | Array < 'null' | 'boolean' | 'string' | 'integer' | 'number' | 'array' | 'object' > ,
78
77
}
@@ -97,9 +96,7 @@ export function isStringJsonSchema(schema: any): schema is StringJsonSchema {
97
96
return false ;
98
97
}
99
98
100
- export interface NumberJsonSchema extends JsonSchema {
101
- allOf ?: Array < NumberJsonSchema > ,
102
- anyOf ?: Array < NumberJsonSchema > ,
99
+ export interface NumberJsonSchema extends JsonSchema , ComposedJsonSchema < NumberJsonSchema > {
103
100
const ?: number ,
104
101
default ?: number ,
105
102
enum ?: Array < number > ,
@@ -109,8 +106,6 @@ export interface NumberJsonSchema extends JsonSchema {
109
106
maximum ?: number ,
110
107
minimum ?: number ,
111
108
multipleOf ?: number ,
112
- not ?: NumberJsonSchema ,
113
- oneOf ?: Array < NumberJsonSchema > ,
114
109
type ?: 'number' | Array < 'null' | 'boolean' | 'string' | 'integer' | 'number' | 'array' | 'object' > ,
115
110
}
116
111
@@ -136,9 +131,7 @@ export function isNumberJsonSchema(schema: any): schema is NumberJsonSchema {
136
131
return false ;
137
132
}
138
133
139
- export interface IntegerJsonSchema extends JsonSchema {
140
- allOf ?: Array < IntegerJsonSchema > ,
141
- anyOf ?: Array < IntegerJsonSchema > ,
134
+ export interface IntegerJsonSchema extends JsonSchema , ComposedJsonSchema < IntegerJsonSchema > {
142
135
const ?: number ,
143
136
default ?: number ,
144
137
enum ?: Array < number > ,
@@ -148,8 +141,6 @@ export interface IntegerJsonSchema extends JsonSchema {
148
141
maximum ?: number ,
149
142
minimum ?: number ,
150
143
multipleOf ?: number ,
151
- not ?: IntegerJsonSchema ,
152
- oneOf ?: Array < IntegerJsonSchema > ,
153
144
type ?: 'integer' | Array < 'null' | 'boolean' | 'string' | 'integer' | 'number' | 'array' | 'object' > ,
154
145
}
155
146
@@ -175,9 +166,7 @@ export function isIntegerJsonSchema(schema: any): schema is IntegerJsonSchema {
175
166
return false ;
176
167
}
177
168
178
- export interface ArrayJsonSchema extends JsonSchema {
179
- allOf ?: Array < ArrayJsonSchema > ,
180
- anyOf ?: Array < ArrayJsonSchema > ,
169
+ export interface ArrayJsonSchema extends JsonSchema , ComposedJsonSchema < ArrayJsonSchema > {
181
170
const ?: Array < any > ,
182
171
contains ?: JsonSchema ,
183
172
default ?: Array < any > ,
@@ -188,8 +177,6 @@ export interface ArrayJsonSchema extends JsonSchema {
188
177
maxItems ?: number ,
189
178
minContains ?: number ,
190
179
minItems ?: number ,
191
- not ?: ArrayJsonSchema ,
192
- oneOf ?: Array < ArrayJsonSchema > ,
193
180
prefixItems ?: Array < JsonSchema > ,
194
181
type ?: 'array' | Array < 'null' | 'boolean' | 'string' | 'integer' | 'number' | 'array' | 'object' > ,
195
182
uniqueItems ?: boolean ,
@@ -220,25 +207,20 @@ export function isArrayJsonSchema(schema: any): schema is ArrayJsonSchema {
220
207
return false ;
221
208
}
222
209
223
- export interface ObjectJsonSchema extends JsonSchema {
210
+ export interface ObjectJsonSchema extends JsonSchema , ComposedJsonSchema < ObjectJsonSchema > {
224
211
additionalProperties ?: JsonSchema ,
225
- allOf ?: Array < ObjectJsonSchema > ,
226
- anyOf ?: Array < ObjectJsonSchema > ,
227
212
const ?: Record < string , any > ,
228
213
default ?: Record < string , any > ,
229
214
dependentRequired ?: Record < string , Array < string > > ,
230
215
enum ?: Array < Record < string , any > > ,
231
216
examples ?: Array < Record < string , any > > ,
232
217
maxProperties ?: number ,
233
218
minProperties ?: number ,
234
- not ?: ObjectJsonSchema ,
235
- oneOf ?: Array < ObjectJsonSchema > ,
236
219
patternProperties ?: { [ propertyNameRegex : string ] : JsonSchema } ,
237
220
properties ?: { [ propertyName : string ] : JsonSchema } ,
238
221
propertyNames ?: JsonSchema ,
239
222
required ?: Array < string > ,
240
223
type ?: 'object' | Array < 'null' | 'boolean' | 'string' | 'integer' | 'number' | 'array' | 'object' > ,
241
- writeOnly ?: boolean
242
224
}
243
225
244
226
export function isObjectJsonSchema ( schema : any ) : schema is ObjectJsonSchema {
@@ -266,10 +248,8 @@ export function isObjectJsonSchema(schema: any): schema is ObjectJsonSchema {
266
248
return false ;
267
249
}
268
250
269
- export interface AnyJsonSchema extends JsonSchema {
251
+ export interface AnyJsonSchema extends JsonSchema , ComposedJsonSchema {
270
252
additionalProperties ?: never ,
271
- allOf ?: Array < JsonSchema > ,
272
- anyOf ?: Array < JsonSchema > ,
273
253
const ?: any ,
274
254
contains ?: never ,
275
255
default ?: any ,
@@ -290,8 +270,6 @@ export interface AnyJsonSchema extends JsonSchema {
290
270
minProperties ?: never ,
291
271
minimum ?: never ,
292
272
multipleOf ?: never ,
293
- not ?: JsonSchema ,
294
- oneOf ?: Array < JsonSchema > ,
295
273
pattern ?: never ,
296
274
patternProperties ?: never ,
297
275
prefixItems ?: never ,
@@ -300,16 +278,4 @@ export interface AnyJsonSchema extends JsonSchema {
300
278
required ?: never ,
301
279
type ?: never ,
302
280
uniqueItems ?: never ,
303
- writeOnly ?: boolean
304
- }
305
-
306
- export function isAnyJsonSchema ( schema : any ) : schema is AnyJsonSchema {
307
- return ! isReference ( schema )
308
- && ! isNullJsonSchema ( schema )
309
- && ! isBooleanJsonSchema ( schema )
310
- && ! isStringJsonSchema ( schema )
311
- && ! isNumberJsonSchema ( schema )
312
- && ! isIntegerJsonSchema ( schema )
313
- && ! isArrayJsonSchema ( schema )
314
- && ! isObjectJsonSchema ( schema ) ;
315
281
}
0 commit comments