From 5de12c191a3735a58f4f9fc8b506232f4f2f3f9f Mon Sep 17 00:00:00 2001 From: Drew Powers Date: Thu, 18 Apr 2019 19:32:24 -0600 Subject: [PATCH] Add export option test --- src/swagger-2.ts | 5 ++--- tests/swagger-2.test.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/swagger-2.ts b/src/swagger-2.ts index 2cc6dd4d9..e86a4b984 100644 --- a/src/swagger-2.ts +++ b/src/swagger-2.ts @@ -44,12 +44,11 @@ function camelCase(name: string): string { function parse(spec: Swagger2, options: Swagger2Options = {}): string { const namespace = options.namespace || 'OpenAPI2'; const shouldCamelCase = options.camelcase || false; - const shouldExport = options.export || false; const queue: [string, Swagger2Definition][] = []; - const output: string[] = shouldExport ? ['export '] : []; - output.push(`namespace ${namespace} {`); + const output: string[] = []; + output.push(`${options.export === true ? 'export ' : ''}namespace ${namespace} {`); const { definitions } = spec; diff --git a/tests/swagger-2.test.ts b/tests/swagger-2.test.ts index c3b3c0532..2eed7cf16 100644 --- a/tests/swagger-2.test.ts +++ b/tests/swagger-2.test.ts @@ -363,6 +363,33 @@ describe('Swagger 2 spec', () => { expect(swaggerToTS(input)).toBe(format(output, false)); }); + it('allows exporting of namespace', () => { + const swagger: Swagger2 = { + definitions: { + Name: { + properties: { + first: { type: 'string' }, + last: { type: 'string' }, + }, + type: 'object', + }, + }, + }; + + const ts = format( + ` + export namespace OpenAPI2{ + export interface Name { + first?: string; + last?: string; + } + }`, + false + ); + + expect(swaggerToTS(swagger, { export: true })).toBe(ts); + }); + it('skips top-level array definitions', () => { const swagger: Swagger2 = { definitions: {