@@ -23,6 +23,9 @@ import {
23
23
JSONSchemaWithDefinitions ,
24
24
SchemaSchema ,
25
25
SchemaType ,
26
+ IsExternalSchema ,
27
+ NormalizedJSONSchema ,
28
+ Parent ,
26
29
} from './types/JSONSchema'
27
30
import { generateName , log , maybeStripDefault , maybeStripNameHints } from './utils'
28
31
@@ -31,7 +34,7 @@ export type Processed = Map<LinkedJSONSchema, Map<SchemaType, AST>>
31
34
export type UsedNames = Set < string >
32
35
33
36
export function parse (
34
- schema : LinkedJSONSchema | JSONSchema4Type ,
37
+ schema : NormalizedJSONSchema | JSONSchema4Type ,
35
38
options : Options ,
36
39
keyName ?: string ,
37
40
processed : Processed = new Map ( ) ,
@@ -54,19 +57,17 @@ export function parse(
54
57
55
58
// Be careful to first process the intersection before processing its params,
56
59
// so that it gets first pick for standalone name.
57
- const ast = parseAsTypeWithCache (
58
- {
59
- $id : schema . $id ,
60
- allOf : [ ] ,
61
- description : schema . description ,
62
- title : schema . title ,
63
- } ,
64
- 'ALL_OF' ,
65
- options ,
66
- keyName ,
67
- processed ,
68
- usedNames ,
69
- ) as TIntersection
60
+ const allOf : NormalizedJSONSchema = {
61
+ [ IsExternalSchema ] : schema [ IsExternalSchema ] ,
62
+ [ Parent ] : schema [ Parent ] ,
63
+ $id : schema . $id ,
64
+ allOf : [ ] ,
65
+ description : schema . description ,
66
+ title : schema . title ,
67
+ additionalProperties : schema . additionalProperties ,
68
+ required : schema . required ,
69
+ }
70
+ const ast = parseAsTypeWithCache ( allOf , 'ALL_OF' , options , keyName , processed , usedNames ) as TIntersection
70
71
71
72
ast . params = types . map ( type =>
72
73
// We hoist description (for comment) and id/title (for standaloneName)
@@ -79,7 +80,7 @@ export function parse(
79
80
}
80
81
81
82
function parseAsTypeWithCache (
82
- schema : LinkedJSONSchema ,
83
+ schema : NormalizedJSONSchema ,
83
84
type : SchemaType ,
84
85
options : Options ,
85
86
keyName ?: string ,
@@ -111,27 +112,30 @@ function parseAsTypeWithCache(
111
112
function parseBooleanSchema ( schema : boolean , keyName : string | undefined , options : Options ) : AST {
112
113
if ( schema ) {
113
114
return {
115
+ isExternalSchema : false ,
114
116
keyName,
115
117
type : options . unknownAny ? 'UNKNOWN' : 'ANY' ,
116
118
}
117
119
}
118
120
119
121
return {
122
+ isExternalSchema : false ,
120
123
keyName,
121
124
type : 'NEVER' ,
122
125
}
123
126
}
124
127
125
128
function parseLiteral ( schema : JSONSchema4Type , keyName : string | undefined ) : AST {
126
129
return {
130
+ isExternalSchema : false ,
127
131
keyName,
128
132
params : schema ,
129
133
type : 'LITERAL' ,
130
134
}
131
135
}
132
136
133
137
function parseNonLiteral (
134
- schema : LinkedJSONSchema ,
138
+ schema : NormalizedJSONSchema ,
135
139
type : SchemaType ,
136
140
options : Options ,
137
141
keyName : string | undefined ,
@@ -146,6 +150,7 @@ function parseNonLiteral(
146
150
return {
147
151
comment : schema . description ,
148
152
deprecated : schema . deprecated ,
153
+ isExternalSchema : schema [ IsExternalSchema ] ,
149
154
keyName,
150
155
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
151
156
params : schema . allOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -156,13 +161,15 @@ function parseNonLiteral(
156
161
...( options . unknownAny ? T_UNKNOWN : T_ANY ) ,
157
162
comment : schema . description ,
158
163
deprecated : schema . deprecated ,
164
+ isExternalSchema : schema [ IsExternalSchema ] ,
159
165
keyName,
160
166
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
161
167
}
162
168
case 'ANY_OF' :
163
169
return {
164
170
comment : schema . description ,
165
171
deprecated : schema . deprecated ,
172
+ isExternalSchema : schema [ IsExternalSchema ] ,
166
173
keyName,
167
174
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
168
175
params : schema . anyOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -172,6 +179,7 @@ function parseNonLiteral(
172
179
return {
173
180
comment : schema . description ,
174
181
deprecated : schema . deprecated ,
182
+ isExternalSchema : schema [ IsExternalSchema ] ,
175
183
keyName,
176
184
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
177
185
type : 'BOOLEAN' ,
@@ -180,6 +188,7 @@ function parseNonLiteral(
180
188
return {
181
189
comment : schema . description ,
182
190
deprecated : schema . deprecated ,
191
+ isExternalSchema : schema [ IsExternalSchema ] ,
183
192
keyName,
184
193
params : schema . tsType ! ,
185
194
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
@@ -189,9 +198,10 @@ function parseNonLiteral(
189
198
return {
190
199
comment : schema . description ,
191
200
deprecated : schema . deprecated ,
201
+ isExternalSchema : schema [ IsExternalSchema ] ,
192
202
keyName,
193
203
standaloneName : standaloneName ( schema , keyNameFromDefinition ?? keyName , usedNames , options ) ! ,
194
- params : schema . enum ! . map ( ( _ , n ) => ( {
204
+ params : schema . enum ! . map ( ( _ : any , n : number ) => ( {
195
205
ast : parseLiteral ( _ , undefined ) ,
196
206
keyName : schema . tsEnumNames ! [ n ] ,
197
207
} ) ) ,
@@ -203,6 +213,7 @@ function parseNonLiteral(
203
213
return {
204
214
comment : schema . description ,
205
215
deprecated : schema . deprecated ,
216
+ isExternalSchema : schema [ IsExternalSchema ] ,
206
217
keyName,
207
218
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
208
219
type : 'NEVER' ,
@@ -211,6 +222,7 @@ function parseNonLiteral(
211
222
return {
212
223
comment : schema . description ,
213
224
deprecated : schema . deprecated ,
225
+ isExternalSchema : schema [ IsExternalSchema ] ,
214
226
keyName,
215
227
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
216
228
type : 'NULL' ,
@@ -219,13 +231,15 @@ function parseNonLiteral(
219
231
return {
220
232
comment : schema . description ,
221
233
deprecated : schema . deprecated ,
234
+ isExternalSchema : schema [ IsExternalSchema ] ,
222
235
keyName,
223
236
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
224
237
type : 'NUMBER' ,
225
238
}
226
239
case 'OBJECT' :
227
240
return {
228
241
comment : schema . description ,
242
+ isExternalSchema : schema [ IsExternalSchema ] ,
229
243
keyName,
230
244
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
231
245
type : 'OBJECT' ,
@@ -235,6 +249,7 @@ function parseNonLiteral(
235
249
return {
236
250
comment : schema . description ,
237
251
deprecated : schema . deprecated ,
252
+ isExternalSchema : schema [ IsExternalSchema ] ,
238
253
keyName,
239
254
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
240
255
params : schema . oneOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -246,6 +261,7 @@ function parseNonLiteral(
246
261
return {
247
262
comment : schema . description ,
248
263
deprecated : schema . deprecated ,
264
+ isExternalSchema : schema [ IsExternalSchema ] ,
249
265
keyName,
250
266
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
251
267
type : 'STRING' ,
@@ -258,6 +274,7 @@ function parseNonLiteral(
258
274
const arrayType : TTuple = {
259
275
comment : schema . description ,
260
276
deprecated : schema . deprecated ,
277
+ isExternalSchema : schema [ IsExternalSchema ] ,
261
278
keyName,
262
279
maxItems,
263
280
minItems,
@@ -275,6 +292,7 @@ function parseNonLiteral(
275
292
return {
276
293
comment : schema . description ,
277
294
deprecated : schema . deprecated ,
295
+ isExternalSchema : schema [ IsExternalSchema ] ,
278
296
keyName,
279
297
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
280
298
params : parse ( schema . items ! , options , `{keyNameFromDefinition}Items` , processed , usedNames ) ,
@@ -285,6 +303,7 @@ function parseNonLiteral(
285
303
return {
286
304
comment : schema . description ,
287
305
deprecated : schema . deprecated ,
306
+ isExternalSchema : schema [ IsExternalSchema ] ,
288
307
keyName,
289
308
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
290
309
params : ( schema . type as JSONSchema4TypeName [ ] ) . map ( type => {
@@ -297,9 +316,10 @@ function parseNonLiteral(
297
316
return {
298
317
comment : schema . description ,
299
318
deprecated : schema . deprecated ,
319
+ isExternalSchema : schema [ IsExternalSchema ] ,
300
320
keyName,
301
321
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
302
- params : schema . enum ! . map ( _ => parseLiteral ( _ , undefined ) ) ,
322
+ params : schema . enum ! . map ( ( _ : any ) => parseLiteral ( _ , undefined ) ) ,
303
323
type : 'UNION' ,
304
324
}
305
325
case 'UNNAMED_SCHEMA' :
@@ -313,6 +333,7 @@ function parseNonLiteral(
313
333
return {
314
334
comment : schema . description ,
315
335
deprecated : schema . deprecated ,
336
+ isExternalSchema : schema [ IsExternalSchema ] ,
316
337
keyName,
317
338
maxItems : schema . maxItems ,
318
339
minItems,
@@ -328,6 +349,7 @@ function parseNonLiteral(
328
349
return {
329
350
comment : schema . description ,
330
351
deprecated : schema . deprecated ,
352
+ isExternalSchema : schema [ IsExternalSchema ] ,
331
353
keyName,
332
354
params,
333
355
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
@@ -364,6 +386,7 @@ function newInterface(
364
386
return {
365
387
comment : schema . description ,
366
388
deprecated : schema . deprecated ,
389
+ isExternalSchema : schema [ IsExternalSchema ] ,
367
390
keyName,
368
391
params : parseSchema ( schema , options , processed , usedNames , name ) ,
369
392
standaloneName : name ,
0 commit comments