@@ -25,6 +25,7 @@ import {
2525 Parent ,
2626 SchemaSchema ,
2727 SchemaType ,
28+ IsExternalSchema ,
2829} from './types/JSONSchema'
2930import { generateName , log , maybeStripDefault , maybeStripNameHints } from './utils'
3031
@@ -56,22 +57,17 @@ export function parse(
5657
5758 // Be careful to first process the intersection before processing its params,
5859 // 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
7571
7672 ast . params = types . map ( type =>
7773 // We hoist description (for comment) and id/title (for standaloneName)
@@ -116,19 +112,22 @@ function parseAsTypeWithCache(
116112function parseBooleanSchema ( schema : boolean , keyName : string | undefined , options : Options ) : AST {
117113 if ( schema ) {
118114 return {
115+ isExternalSchema : false ,
119116 keyName,
120117 type : options . unknownAny ? 'UNKNOWN' : 'ANY' ,
121118 }
122119 }
123120
124121 return {
122+ isExternalSchema : false ,
125123 keyName,
126124 type : 'NEVER' ,
127125 }
128126}
129127
130128function parseLiteral ( schema : JSONSchema4Type , keyName : string | undefined ) : AST {
131129 return {
130+ isExternalSchema : false ,
132131 keyName,
133132 params : schema ,
134133 type : 'LITERAL' ,
@@ -151,6 +150,7 @@ function parseNonLiteral(
151150 return {
152151 comment : schema . description ,
153152 deprecated : schema . deprecated ,
153+ isExternalSchema : schema [ IsExternalSchema ] ,
154154 keyName,
155155 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
156156 params : schema . allOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -161,13 +161,15 @@ function parseNonLiteral(
161161 ...( options . unknownAny ? T_UNKNOWN : T_ANY ) ,
162162 comment : schema . description ,
163163 deprecated : schema . deprecated ,
164+ isExternalSchema : schema [ IsExternalSchema ] ,
164165 keyName,
165166 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
166167 }
167168 case 'ANY_OF' :
168169 return {
169170 comment : schema . description ,
170171 deprecated : schema . deprecated ,
172+ isExternalSchema : schema [ IsExternalSchema ] ,
171173 keyName,
172174 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
173175 params : schema . anyOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -177,6 +179,7 @@ function parseNonLiteral(
177179 return {
178180 comment : schema . description ,
179181 deprecated : schema . deprecated ,
182+ isExternalSchema : schema [ IsExternalSchema ] ,
180183 keyName,
181184 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
182185 type : 'BOOLEAN' ,
@@ -185,6 +188,7 @@ function parseNonLiteral(
185188 return {
186189 comment : schema . description ,
187190 deprecated : schema . deprecated ,
191+ isExternalSchema : schema [ IsExternalSchema ] ,
188192 keyName,
189193 params : schema . tsType ! ,
190194 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
@@ -194,6 +198,7 @@ function parseNonLiteral(
194198 return {
195199 comment : schema . description ,
196200 deprecated : schema . deprecated ,
201+ isExternalSchema : schema [ IsExternalSchema ] ,
197202 keyName,
198203 standaloneName : standaloneName ( schema , keyNameFromDefinition ?? keyName , usedNames , options ) ! ,
199204 params : ( schema as EnumJSONSchema ) . enum ! . map ( ( _ , n ) => ( {
@@ -208,6 +213,7 @@ function parseNonLiteral(
208213 return {
209214 comment : schema . description ,
210215 deprecated : schema . deprecated ,
216+ isExternalSchema : schema [ IsExternalSchema ] ,
211217 keyName,
212218 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
213219 type : 'NEVER' ,
@@ -216,6 +222,7 @@ function parseNonLiteral(
216222 return {
217223 comment : schema . description ,
218224 deprecated : schema . deprecated ,
225+ isExternalSchema : schema [ IsExternalSchema ] ,
219226 keyName,
220227 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
221228 type : 'NULL' ,
@@ -224,13 +231,15 @@ function parseNonLiteral(
224231 return {
225232 comment : schema . description ,
226233 deprecated : schema . deprecated ,
234+ isExternalSchema : schema [ IsExternalSchema ] ,
227235 keyName,
228236 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
229237 type : 'NUMBER' ,
230238 }
231239 case 'OBJECT' :
232240 return {
233241 comment : schema . description ,
242+ isExternalSchema : schema [ IsExternalSchema ] ,
234243 keyName,
235244 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
236245 type : 'OBJECT' ,
@@ -240,6 +249,7 @@ function parseNonLiteral(
240249 return {
241250 comment : schema . description ,
242251 deprecated : schema . deprecated ,
252+ isExternalSchema : schema [ IsExternalSchema ] ,
243253 keyName,
244254 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
245255 params : schema . oneOf ! . map ( _ => parse ( _ , options , undefined , processed , usedNames ) ) ,
@@ -251,6 +261,7 @@ function parseNonLiteral(
251261 return {
252262 comment : schema . description ,
253263 deprecated : schema . deprecated ,
264+ isExternalSchema : schema [ IsExternalSchema ] ,
254265 keyName,
255266 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
256267 type : 'STRING' ,
@@ -263,6 +274,7 @@ function parseNonLiteral(
263274 const arrayType : TTuple = {
264275 comment : schema . description ,
265276 deprecated : schema . deprecated ,
277+ isExternalSchema : schema [ IsExternalSchema ] ,
266278 keyName,
267279 maxItems,
268280 minItems,
@@ -280,6 +292,7 @@ function parseNonLiteral(
280292 return {
281293 comment : schema . description ,
282294 deprecated : schema . deprecated ,
295+ isExternalSchema : schema [ IsExternalSchema ] ,
283296 keyName,
284297 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
285298 params : parse ( schema . items ! , options , `{keyNameFromDefinition}Items` , processed , usedNames ) ,
@@ -290,6 +303,7 @@ function parseNonLiteral(
290303 return {
291304 comment : schema . description ,
292305 deprecated : schema . deprecated ,
306+ isExternalSchema : schema [ IsExternalSchema ] ,
293307 keyName,
294308 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
295309 params : ( schema . type as JSONSchema4TypeName [ ] ) . map ( type => {
@@ -307,6 +321,7 @@ function parseNonLiteral(
307321 return {
308322 comment : schema . description ,
309323 deprecated : schema . deprecated ,
324+ isExternalSchema : schema [ IsExternalSchema ] ,
310325 keyName,
311326 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
312327 params : ( schema as EnumJSONSchema ) . enum ! . map ( _ => parseLiteral ( _ , undefined ) ) ,
@@ -323,6 +338,7 @@ function parseNonLiteral(
323338 return {
324339 comment : schema . description ,
325340 deprecated : schema . deprecated ,
341+ isExternalSchema : schema [ IsExternalSchema ] ,
326342 keyName,
327343 maxItems : schema . maxItems ,
328344 minItems,
@@ -338,6 +354,7 @@ function parseNonLiteral(
338354 return {
339355 comment : schema . description ,
340356 deprecated : schema . deprecated ,
357+ isExternalSchema : schema [ IsExternalSchema ] ,
341358 keyName,
342359 params,
343360 standaloneName : standaloneName ( schema , keyNameFromDefinition , usedNames , options ) ,
@@ -374,6 +391,7 @@ function newInterface(
374391 return {
375392 comment : schema . description ,
376393 deprecated : schema . deprecated ,
394+ isExternalSchema : schema [ IsExternalSchema ] ,
377395 keyName,
378396 params : parseSchema ( schema , options , processed , usedNames , name ) ,
379397 standaloneName : name ,
0 commit comments