Skip to content

Add export option test #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2019
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