@@ -25,6 +25,7 @@ import {
25
25
Parent ,
26
26
SchemaSchema ,
27
27
SchemaType ,
28
+ IsExternalSchema ,
28
29
} from './types/JSONSchema'
29
30
import { generateName , log , maybeStripDefault , maybeStripNameHints } from './utils'
30
31
@@ -56,22 +57,17 @@ export function parse(
56
57
57
58
// Be careful to first process the intersection before processing its params,
58
59
// so that it gets first pick for standalone name.
59
- const ast = parseAsTypeWithCache (
60
- {
61
- [ Parent ] : schema [ Parent ] ,
62
- $id : schema . $id ,
63
- additionalProperties : schema . additionalProperties ,
64
- allOf : [ ] ,
65
- description : schema . description ,
66
- required : schema . required ,
67
- title : schema . title ,
68
- } ,
69
- 'ALL_OF' ,
70
- options ,
71
- keyName ,
72
- processed ,
73
- usedNames ,
74
- ) 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
75
71
76
72
ast . params = types . map ( type =>
77
73
// We hoist description (for comment) and id/title (for standaloneName)
@@ -116,19 +112,22 @@ function parseAsTypeWithCache(
116
112
function parseBooleanSchema ( schema : boolean , keyName : string | undefined , options : Options ) : AST {
117
113
if ( schema ) {
118
114
return {
115
+ isExternalSchema : false ,
119
116
keyName,
120
117
type : options . unknownAny ? 'UNKNOWN' : 'ANY' ,
121
118
}
122
119
}
123
120
124
121
return {
122
+ isExternalSchema : false ,
125
123
keyName,
126
124
type : 'NEVER' ,
127
125
}
128
126
}
129
127
130
128
function parseLiteral ( schema : JSONSchema4Type , keyName : string | undefined ) : AST {
131
129
return {
130
+ isExternalSchema : false ,
132
131
keyName,
133
132
params : schema ,
134
133
type : 'LITERAL' ,
@@ -151,6 +150,7 @@ function parseNonLiteral(
151
150
return {
152
151
comment : schema . description ,
153
152
deprecated : schema . deprecated ,
153
+ isExternalSchema : schema [ IsExternalSchema ] ,
154
154
keyName,
155
155
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
156
156
params : schema . allOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -161,13 +161,15 @@ function parseNonLiteral(
161
161
...( options . unknownAny ? T_UNKNOWN : T_ANY ) ,
162
162
comment : schema . description ,
163
163
deprecated : schema . deprecated ,
164
+ isExternalSchema : schema [ IsExternalSchema ] ,
164
165
keyName,
165
166
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
166
167
}
167
168
case 'ANY_OF' :
168
169
return {
169
170
comment : schema . description ,
170
171
deprecated : schema . deprecated ,
172
+ isExternalSchema : schema [ IsExternalSchema ] ,
171
173
keyName,
172
174
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
173
175
params : schema . anyOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -177,6 +179,7 @@ function parseNonLiteral(
177
179
return {
178
180
comment : schema . description ,
179
181
deprecated : schema . deprecated ,
182
+ isExternalSchema : schema [ IsExternalSchema ] ,
180
183
keyName,
181
184
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
182
185
type : 'BOOLEAN' ,
@@ -185,6 +188,7 @@ function parseNonLiteral(
185
188
return {
186
189
comment : schema . description ,
187
190
deprecated : schema . deprecated ,
191
+ isExternalSchema : schema [ IsExternalSchema ] ,
188
192
keyName,
189
193
params : schema . tsType ! ,
190
194
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
@@ -194,6 +198,7 @@ function parseNonLiteral(
194
198
return {
195
199
comment : schema . description ,
196
200
deprecated : schema . deprecated ,
201
+ isExternalSchema : schema [ IsExternalSchema ] ,
197
202
keyName,
198
203
standaloneName : standaloneName ( schema , keyNameFromDefinition ?? keyName , usedNames , options ) ! ,
199
204
params : ( schema as EnumJSONSchema ) . enum ! . map ( ( _ , n ) => ( {
@@ -208,6 +213,7 @@ function parseNonLiteral(
208
213
return {
209
214
comment : schema . description ,
210
215
deprecated : schema . deprecated ,
216
+ isExternalSchema : schema [ IsExternalSchema ] ,
211
217
keyName,
212
218
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
213
219
type : 'NEVER' ,
@@ -216,6 +222,7 @@ function parseNonLiteral(
216
222
return {
217
223
comment : schema . description ,
218
224
deprecated : schema . deprecated ,
225
+ isExternalSchema : schema [ IsExternalSchema ] ,
219
226
keyName,
220
227
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
221
228
type : 'NULL' ,
@@ -224,13 +231,15 @@ function parseNonLiteral(
224
231
return {
225
232
comment : schema . description ,
226
233
deprecated : schema . deprecated ,
234
+ isExternalSchema : schema [ IsExternalSchema ] ,
227
235
keyName,
228
236
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
229
237
type : 'NUMBER' ,
230
238
}
231
239
case 'OBJECT' :
232
240
return {
233
241
comment : schema . description ,
242
+ isExternalSchema : schema [ IsExternalSchema ] ,
234
243
keyName,
235
244
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
236
245
type : 'OBJECT' ,
@@ -240,6 +249,7 @@ function parseNonLiteral(
240
249
return {
241
250
comment : schema . description ,
242
251
deprecated : schema . deprecated ,
252
+ isExternalSchema : schema [ IsExternalSchema ] ,
243
253
keyName,
244
254
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
245
255
params : schema . oneOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -251,6 +261,7 @@ function parseNonLiteral(
251
261
return {
252
262
comment : schema . description ,
253
263
deprecated : schema . deprecated ,
264
+ isExternalSchema : schema [ IsExternalSchema ] ,
254
265
keyName,
255
266
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
256
267
type : 'STRING' ,
@@ -263,6 +274,7 @@ function parseNonLiteral(
263
274
const arrayType : TTuple = {
264
275
comment : schema . description ,
265
276
deprecated : schema . deprecated ,
277
+ isExternalSchema : schema [ IsExternalSchema ] ,
266
278
keyName,
267
279
maxItems,
268
280
minItems,
@@ -280,6 +292,7 @@ function parseNonLiteral(
280
292
return {
281
293
comment : schema . description ,
282
294
deprecated : schema . deprecated ,
295
+ isExternalSchema : schema [ IsExternalSchema ] ,
283
296
keyName,
284
297
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
285
298
params : parse ( schema . items ! , options , `{keyNameFromDefinition}Items` , processed , usedNames ) ,
@@ -290,6 +303,7 @@ function parseNonLiteral(
290
303
return {
291
304
comment : schema . description ,
292
305
deprecated : schema . deprecated ,
306
+ isExternalSchema : schema [ IsExternalSchema ] ,
293
307
keyName,
294
308
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
295
309
params : ( schema . type as JSONSchema4TypeName [ ] ) . map ( type => {
@@ -307,6 +321,7 @@ function parseNonLiteral(
307
321
return {
308
322
comment : schema . description ,
309
323
deprecated : schema . deprecated ,
324
+ isExternalSchema : schema [ IsExternalSchema ] ,
310
325
keyName,
311
326
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
312
327
params : ( schema as EnumJSONSchema ) . enum ! . map ( _ => parseLiteral ( _ , undefined ) ) ,
@@ -323,6 +338,7 @@ function parseNonLiteral(
323
338
return {
324
339
comment : schema . description ,
325
340
deprecated : schema . deprecated ,
341
+ isExternalSchema : schema [ IsExternalSchema ] ,
326
342
keyName,
327
343
maxItems : schema . maxItems ,
328
344
minItems,
@@ -338,6 +354,7 @@ function parseNonLiteral(
338
354
return {
339
355
comment : schema . description ,
340
356
deprecated : schema . deprecated ,
357
+ isExternalSchema : schema [ IsExternalSchema ] ,
341
358
keyName,
342
359
params,
343
360
standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
@@ -374,6 +391,7 @@ function newInterface(
374
391
return {
375
392
comment : schema . description ,
376
393
deprecated : schema . deprecated ,
394
+ isExternalSchema : schema [ IsExternalSchema ] ,
377
395
keyName,
378
396
params : parseSchema ( schema , options , processed , usedNames , name ) ,
379
397
standaloneName : name ,
0 commit comments