@@ -6,9 +6,13 @@ export function isReference(schema: any): schema is Reference {
6
6
return typeof schema . $ref === 'string' ;
7
7
}
8
8
9
- export interface JsonSchema {
9
+ export interface JsonSchema < T = any > {
10
+ const ?: T ,
11
+ default ?: T ,
10
12
deprecated ?: boolean ,
11
13
description ?: string ,
14
+ enum ?: Array < T > ,
15
+ examples ?: Array < T > ,
12
16
readOnly ?: boolean ,
13
17
title ?: string ,
14
18
writeOnly ?: boolean
@@ -26,10 +30,6 @@ export function isComposedJsonSchema(schema: any): schema is ComposedJsonSchema
26
30
}
27
31
28
32
export interface NullJsonSchema extends JsonSchema , ComposedJsonSchema < NullJsonSchema > {
29
- const ?: null ,
30
- default ?: null ,
31
- enum ?: Array < null > ,
32
- examples ?: Array < null > ,
33
33
type ?: 'null' | Array < 'null' | 'boolean' | 'string' | 'integer' | 'number' | 'array' | 'object' > ,
34
34
}
35
35
@@ -45,11 +45,7 @@ export function isNullJsonSchema(schema: any): schema is NullJsonSchema {
45
45
return false ;
46
46
}
47
47
48
- export interface BooleanJsonSchema extends JsonSchema , ComposedJsonSchema < BooleanJsonSchema > {
49
- const ?: boolean ,
50
- default ?: boolean ,
51
- enum ?: Array < boolean > ,
52
- examples ?: Array < boolean > ,
48
+ export interface BooleanJsonSchema extends JsonSchema < boolean > , ComposedJsonSchema < BooleanJsonSchema > {
53
49
type ?: 'boolean' | Array < 'null' | 'boolean' | 'string' | 'integer' | 'number' | 'array' | 'object' > ,
54
50
}
55
51
@@ -65,11 +61,7 @@ export function isBooleanJsonSchema(schema: any): schema is BooleanJsonSchema {
65
61
return false ;
66
62
}
67
63
68
- export interface StringJsonSchema extends JsonSchema , ComposedJsonSchema < StringJsonSchema > {
69
- const ?: string ,
70
- default ?: string ,
71
- enum ?: Array < string > ,
72
- examples ?: Array < string > ,
64
+ export interface StringJsonSchema extends JsonSchema < string > , ComposedJsonSchema < StringJsonSchema > {
73
65
maxLength ?: number ,
74
66
minLength ?: number ,
75
67
pattern ?: string ,
@@ -96,11 +88,7 @@ export function isStringJsonSchema(schema: any): schema is StringJsonSchema {
96
88
return false ;
97
89
}
98
90
99
- export interface NumberJsonSchema extends JsonSchema , ComposedJsonSchema < NumberJsonSchema > {
100
- const ?: number ,
101
- default ?: number ,
102
- enum ?: Array < number > ,
103
- examples ?: Array < number > ,
91
+ export interface NumberJsonSchema extends JsonSchema < number > , ComposedJsonSchema < NumberJsonSchema > {
104
92
exclusiveMaximum ?: number ,
105
93
exclusiveMinimum ?: number ,
106
94
maximum ?: number ,
@@ -131,11 +119,7 @@ export function isNumberJsonSchema(schema: any): schema is NumberJsonSchema {
131
119
return false ;
132
120
}
133
121
134
- export interface IntegerJsonSchema extends JsonSchema , ComposedJsonSchema < IntegerJsonSchema > {
135
- const ?: number ,
136
- default ?: number ,
137
- enum ?: Array < number > ,
138
- examples ?: Array < number > ,
122
+ export interface IntegerJsonSchema extends JsonSchema < number > , ComposedJsonSchema < IntegerJsonSchema > {
139
123
exclusiveMaximum ?: number ,
140
124
exclusiveMinimum ?: number ,
141
125
maximum ?: number ,
@@ -166,12 +150,8 @@ export function isIntegerJsonSchema(schema: any): schema is IntegerJsonSchema {
166
150
return false ;
167
151
}
168
152
169
- export interface ArrayJsonSchema extends JsonSchema , ComposedJsonSchema < ArrayJsonSchema > {
170
- const ?: Array < any > ,
153
+ export interface ArrayJsonSchema extends JsonSchema < Array < any > > , ComposedJsonSchema < ArrayJsonSchema > {
171
154
contains ?: JsonSchema ,
172
- default ?: Array < any > ,
173
- enum ?: Array < Array < any > > ,
174
- examples ?: Array < Array < any > > ,
175
155
items ?: JsonSchema ,
176
156
maxContains ?: number ,
177
157
maxItems ?: number ,
@@ -207,13 +187,9 @@ export function isArrayJsonSchema(schema: any): schema is ArrayJsonSchema {
207
187
return false ;
208
188
}
209
189
210
- export interface ObjectJsonSchema extends JsonSchema , ComposedJsonSchema < ObjectJsonSchema > {
190
+ export interface ObjectJsonSchema extends JsonSchema < Record < string , any > > , ComposedJsonSchema < ObjectJsonSchema > {
211
191
additionalProperties ?: JsonSchema ,
212
- const ?: Record < string , any > ,
213
- default ?: Record < string , any > ,
214
192
dependentRequired ?: Record < string , Array < string > > ,
215
- enum ?: Array < Record < string , any > > ,
216
- examples ?: Array < Record < string , any > > ,
217
193
maxProperties ?: number ,
218
194
minProperties ?: number ,
219
195
patternProperties ?: { [ propertyNameRegex : string ] : JsonSchema } ,
@@ -250,12 +226,8 @@ export function isObjectJsonSchema(schema: any): schema is ObjectJsonSchema {
250
226
251
227
export interface AnyJsonSchema extends JsonSchema , ComposedJsonSchema {
252
228
additionalProperties ?: never ,
253
- const ?: any ,
254
229
contains ?: never ,
255
- default ?: any ,
256
230
dependentRequired ?: never ,
257
- enum ?: Array < any > ,
258
- examples ?: Array < any > ,
259
231
exclusiveMaximum ?: never ,
260
232
exclusiveMinimum ?: never ,
261
233
items ?: never ,
0 commit comments