@@ -23,6 +23,9 @@ import {
2323 JSONSchemaWithDefinitions ,
2424 SchemaSchema ,
2525 SchemaType ,
26+ IsExternalSchema ,
27+ NormalizedJSONSchema ,
28+ Parent ,
2629} from './types/JSONSchema'
2730import { generateName , log , maybeStripDefault , maybeStripNameHints } from './utils'
2831
@@ -31,7 +34,7 @@ export type Processed = Map<LinkedJSONSchema, Map<SchemaType, AST>>
3134export type UsedNames = Set < string >
3235
3336export function parse (
34- schema : LinkedJSONSchema | JSONSchema4Type ,
37+ schema : NormalizedJSONSchema | JSONSchema4Type ,
3538 options : Options ,
3639 keyName ?: string ,
3740 processed : Processed = new Map ( ) ,
@@ -54,19 +57,17 @@ export function parse(
5457
5558 // Be careful to first process the intersection before processing its params,
5659 // 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
7071
7172 ast . params = types . map ( type =>
7273 // We hoist description (for comment) and id/title (for standaloneName)
@@ -79,7 +80,7 @@ export function parse(
7980}
8081
8182function parseAsTypeWithCache (
82- schema : LinkedJSONSchema ,
83+ schema : NormalizedJSONSchema ,
8384 type : SchemaType ,
8485 options : Options ,
8586 keyName ?: string ,
@@ -111,27 +112,30 @@ function parseAsTypeWithCache(
111112function parseBooleanSchema ( schema : boolean , keyName : string | undefined , options : Options ) : AST {
112113 if ( schema ) {
113114 return {
115+ isExternalSchema : false ,
114116 keyName,
115117 type : options . unknownAny ? 'UNKNOWN' : 'ANY' ,
116118 }
117119 }
118120
119121 return {
122+ isExternalSchema : false ,
120123 keyName,
121124 type : 'NEVER' ,
122125 }
123126}
124127
125128function parseLiteral ( schema : JSONSchema4Type , keyName : string | undefined ) : AST {
126129 return {
130+ isExternalSchema : false ,
127131 keyName,
128132 params : schema ,
129133 type : 'LITERAL' ,
130134 }
131135}
132136
133137function parseNonLiteral (
134- schema : LinkedJSONSchema ,
138+ schema : NormalizedJSONSchema ,
135139 type : SchemaType ,
136140 options : Options ,
137141 keyName : string | undefined ,
@@ -146,6 +150,7 @@ function parseNonLiteral(
146150 return {
147151 comment : schema . description ,
148152 deprecated : schema . deprecated ,
153+ isExternalSchema : schema [ IsExternalSchema ] ,
149154 keyName,
150155 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
151156 params : schema . allOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -156,13 +161,15 @@ function parseNonLiteral(
156161 ...( options . unknownAny ? T_UNKNOWN : T_ANY ) ,
157162 comment : schema . description ,
158163 deprecated : schema . deprecated ,
164+ isExternalSchema : schema [ IsExternalSchema ] ,
159165 keyName,
160166 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
161167 }
162168 case 'ANY_OF' :
163169 return {
164170 comment : schema . description ,
165171 deprecated : schema . deprecated ,
172+ isExternalSchema : schema [ IsExternalSchema ] ,
166173 keyName,
167174 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
168175 params : schema . anyOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -172,6 +179,7 @@ function parseNonLiteral(
172179 return {
173180 comment : schema . description ,
174181 deprecated : schema . deprecated ,
182+ isExternalSchema : schema [ IsExternalSchema ] ,
175183 keyName,
176184 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
177185 type : 'BOOLEAN' ,
@@ -180,6 +188,7 @@ function parseNonLiteral(
180188 return {
181189 comment : schema . description ,
182190 deprecated : schema . deprecated ,
191+ isExternalSchema : schema [ IsExternalSchema ] ,
183192 keyName,
184193 params : schema . tsType ! ,
185194 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
@@ -189,9 +198,10 @@ function parseNonLiteral(
189198 return {
190199 comment : schema . description ,
191200 deprecated : schema . deprecated ,
201+ isExternalSchema : schema [ IsExternalSchema ] ,
192202 keyName,
193203 standaloneName : standaloneName ( schema , keyNameFromDefinition ?? keyName , usedNames , options ) ! ,
194- params : schema . enum ! . map ( ( _ , n ) => ( {
204+ params : schema . enum ! . map ( ( _ : any , n : number ) => ( {
195205 ast : parseLiteral ( _ , undefined ) ,
196206 keyName : schema . tsEnumNames ! [ n ] ,
197207 } ) ) ,
@@ -203,6 +213,7 @@ function parseNonLiteral(
203213 return {
204214 comment : schema . description ,
205215 deprecated : schema . deprecated ,
216+ isExternalSchema : schema [ IsExternalSchema ] ,
206217 keyName,
207218 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
208219 type : 'NEVER' ,
@@ -211,6 +222,7 @@ function parseNonLiteral(
211222 return {
212223 comment : schema . description ,
213224 deprecated : schema . deprecated ,
225+ isExternalSchema : schema [ IsExternalSchema ] ,
214226 keyName,
215227 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
216228 type : 'NULL' ,
@@ -219,13 +231,15 @@ function parseNonLiteral(
219231 return {
220232 comment : schema . description ,
221233 deprecated : schema . deprecated ,
234+ isExternalSchema : schema [ IsExternalSchema ] ,
222235 keyName,
223236 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
224237 type : 'NUMBER' ,
225238 }
226239 case 'OBJECT' :
227240 return {
228241 comment : schema . description ,
242+ isExternalSchema : schema [ IsExternalSchema ] ,
229243 keyName,
230244 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
231245 type : 'OBJECT' ,
@@ -235,6 +249,7 @@ function parseNonLiteral(
235249 return {
236250 comment : schema . description ,
237251 deprecated : schema . deprecated ,
252+ isExternalSchema : schema [ IsExternalSchema ] ,
238253 keyName,
239254 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
240255 params : schema . oneOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -246,6 +261,7 @@ function parseNonLiteral(
246261 return {
247262 comment : schema . description ,
248263 deprecated : schema . deprecated ,
264+ isExternalSchema : schema [ IsExternalSchema ] ,
249265 keyName,
250266 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
251267 type : 'STRING' ,
@@ -258,6 +274,7 @@ function parseNonLiteral(
258274 const arrayType : TTuple = {
259275 comment : schema . description ,
260276 deprecated : schema . deprecated ,
277+ isExternalSchema : schema [ IsExternalSchema ] ,
261278 keyName,
262279 maxItems,
263280 minItems,
@@ -275,6 +292,7 @@ function parseNonLiteral(
275292 return {
276293 comment : schema . description ,
277294 deprecated : schema . deprecated ,
295+ isExternalSchema : schema [ IsExternalSchema ] ,
278296 keyName,
279297 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
280298 params : parse ( schema . items ! , options , `{keyNameFromDefinition}Items` , processed , usedNames ) ,
@@ -285,6 +303,7 @@ function parseNonLiteral(
285303 return {
286304 comment : schema . description ,
287305 deprecated : schema . deprecated ,
306+ isExternalSchema : schema [ IsExternalSchema ] ,
288307 keyName,
289308 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
290309 params : ( schema . type as JSONSchema4TypeName [ ] ) . map ( type => {
@@ -297,9 +316,10 @@ function parseNonLiteral(
297316 return {
298317 comment : schema . description ,
299318 deprecated : schema . deprecated ,
319+ isExternalSchema : schema [ IsExternalSchema ] ,
300320 keyName,
301321 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
302- params : schema . enum ! . map ( _ => parseLiteral ( _ , undefined ) ) ,
322+ params : schema . enum ! . map ( ( _ : any ) => parseLiteral ( _ , undefined ) ) ,
303323 type : 'UNION' ,
304324 }
305325 case 'UNNAMED_SCHEMA' :
@@ -313,6 +333,7 @@ function parseNonLiteral(
313333 return {
314334 comment : schema . description ,
315335 deprecated : schema . deprecated ,
336+ isExternalSchema : schema [ IsExternalSchema ] ,
316337 keyName,
317338 maxItems : schema . maxItems ,
318339 minItems,
@@ -328,6 +349,7 @@ function parseNonLiteral(
328349 return {
329350 comment : schema . description ,
330351 deprecated : schema . deprecated ,
352+ isExternalSchema : schema [ IsExternalSchema ] ,
331353 keyName,
332354 params,
333355 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
@@ -364,6 +386,7 @@ function newInterface(
364386 return {
365387 comment : schema . description ,
366388 deprecated : schema . deprecated ,
389+ isExternalSchema : schema [ IsExternalSchema ] ,
367390 keyName,
368391 params : parseSchema ( schema , options , processed , usedNames , name ) ,
369392 standaloneName : name ,
0 commit comments