File tree 2 files changed +29
-3
lines changed
2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -44,12 +44,11 @@ function camelCase(name: string): string {
44
44
function parse ( spec : Swagger2 , options : Swagger2Options = { } ) : string {
45
45
const namespace = options . namespace || 'OpenAPI2' ;
46
46
const shouldCamelCase = options . camelcase || false ;
47
- const shouldExport = options . export || false ;
48
47
49
48
const queue : [ string , Swagger2Definition ] [ ] = [ ] ;
50
49
51
- const output : string [ ] = shouldExport ? [ 'export ' ] : [ ] ;
52
- output . push ( `namespace ${ namespace } {` ) ;
50
+ const output : string [ ] = [ ] ;
51
+ output . push ( `${ options . export === true ? 'export ' : '' } namespace ${ namespace } {` ) ;
53
52
54
53
const { definitions } = spec ;
55
54
Original file line number Diff line number Diff line change @@ -363,6 +363,33 @@ describe('Swagger 2 spec', () => {
363
363
expect ( swaggerToTS ( input ) ) . toBe ( format ( output , false ) ) ;
364
364
} ) ;
365
365
366
+ it ( 'allows exporting of namespace' , ( ) => {
367
+ const swagger : Swagger2 = {
368
+ definitions : {
369
+ Name : {
370
+ properties : {
371
+ first : { type : 'string' } ,
372
+ last : { type : 'string' } ,
373
+ } ,
374
+ type : 'object' ,
375
+ } ,
376
+ } ,
377
+ } ;
378
+
379
+ const ts = format (
380
+ `
381
+ export namespace OpenAPI2{
382
+ export interface Name {
383
+ first?: string;
384
+ last?: string;
385
+ }
386
+ }` ,
387
+ false
388
+ ) ;
389
+
390
+ expect ( swaggerToTS ( swagger , { export : true } ) ) . toBe ( ts ) ;
391
+ } ) ;
392
+
366
393
it ( 'skips top-level array definitions' , ( ) => {
367
394
const swagger : Swagger2 = {
368
395
definitions : {
You can’t perform that action at this time.
0 commit comments