Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/swagger-2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
27 changes: 27 additions & 0 deletions tests/swagger-2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down