Skip to content

Commit 9ee11b4

Browse files
authored
Add export option test (#12)
1 parent 11a1d3a commit 9ee11b4

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/swagger-2.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ function camelCase(name: string): string {
4444
function parse(spec: Swagger2, options: Swagger2Options = {}): string {
4545
const namespace = options.namespace || 'OpenAPI2';
4646
const shouldCamelCase = options.camelcase || false;
47-
const shouldExport = options.export || false;
4847

4948
const queue: [string, Swagger2Definition][] = [];
5049

51-
const output: string[] = shouldExport ? ['export '] : [];
52-
output.push(`namespace ${namespace} {`);
50+
const output: string[] = [];
51+
output.push(`${options.export === true ? 'export ' : ''}namespace ${namespace} {`);
5352

5453
const { definitions } = spec;
5554

tests/swagger-2.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,33 @@ describe('Swagger 2 spec', () => {
363363
expect(swaggerToTS(input)).toBe(format(output, false));
364364
});
365365

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+
366393
it('skips top-level array definitions', () => {
367394
const swagger: Swagger2 = {
368395
definitions: {

0 commit comments

Comments
 (0)