File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 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 {
9696
9797/** Convert $ref to TS ref */
9898export 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+
99103 const parts = ref . replace ( / ^ # \/ / , root ) . split ( "/" ) ;
100104 return `${ parts [ 0 ] } ["${ parts . slice ( 1 ) . join ( '"]["' ) } "]` ;
101105}
Original file line number Diff line number Diff line change @@ -316,6 +316,24 @@ describe("transformation", () => {
316316 }` )
317317 ) ;
318318 } ) ;
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+ } ) ;
319337 } ) ;
320338
321339 describe ( "propertyMapper" , ( ) => {
Original file line number Diff line number Diff line change @@ -266,6 +266,28 @@ describe("types", () => {
266266 }` )
267267 ) ;
268268 } ) ;
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+ } ) ;
269291} ) ;
270292
271293describe ( "OpenAPI3 features" , ( ) => {
You can’t perform that action at this time.
0 commit comments