File tree 3 files changed +44
-0
lines changed
3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,10 @@ export function swaggerVersion(definition: OpenAPI2 | OpenAPI3): 2 | 3 {
96
96
97
97
/** Convert $ref to TS ref */
98
98
export function transformRef ( ref : string , root = "" ) : string {
99
+ // TODO: load external file
100
+ const isExternalRef = ! ref . startsWith ( "#" ) ; // if # isn’t first character, we can assume this is a remote schema
101
+ if ( isExternalRef ) return "any" ;
102
+
99
103
const parts = ref . replace ( / ^ # \/ / , root ) . split ( "/" ) ;
100
104
return `${ parts [ 0 ] } ["${ parts . slice ( 1 ) . join ( '"]["' ) } "]` ;
101
105
}
Original file line number Diff line number Diff line change @@ -316,6 +316,24 @@ describe("transformation", () => {
316
316
}` )
317
317
) ;
318
318
} ) ;
319
+
320
+ // TODO: allow import later
321
+ it ( "external $ref" , ( ) => {
322
+ const schema : OpenAPI2 = {
323
+ swagger : "2.0" ,
324
+ definitions : {
325
+ externalRef : {
326
+ $ref : "./external.yaml" ,
327
+ } ,
328
+ } ,
329
+ } ;
330
+ expect ( swaggerToTS ( schema ) ) . toBe (
331
+ format ( `
332
+ export interface definitions {
333
+ externalRef: any;
334
+ }` )
335
+ ) ;
336
+ } ) ;
319
337
} ) ;
320
338
321
339
describe ( "propertyMapper" , ( ) => {
Original file line number Diff line number Diff line change @@ -266,6 +266,28 @@ describe("types", () => {
266
266
}` )
267
267
) ;
268
268
} ) ;
269
+
270
+ // TODO: allow import later
271
+ it ( "external $ref" , ( ) => {
272
+ const schema : OpenAPI3 = {
273
+ openapi : "3.0" ,
274
+ components : {
275
+ schemas : {
276
+ externalRef : {
277
+ $ref : "./external.yaml" ,
278
+ } ,
279
+ } ,
280
+ } ,
281
+ } ;
282
+ expect ( swaggerToTS ( schema ) ) . toBe (
283
+ format ( `
284
+ export interface components {
285
+ schemas: {
286
+ externalRef: any;
287
+ }
288
+ }` )
289
+ ) ;
290
+ } ) ;
269
291
} ) ;
270
292
271
293
describe ( "OpenAPI3 features" , ( ) => {
You can’t perform that action at this time.
0 commit comments