diff --git a/README.md b/README.md index 8237ecc81..b1342af44 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ also use the Node API (below). | `--namespace [name]` | `-n` | `OpenAPI2` | How should the output be namespaced? (namespacing is enforced as there’s a high chance of collision) | | `--swagger [version]` | `-s` | `2` | Which Swagger version to use. Currently only supports `2`. | | `--camelcase` | `-c` | `false` | Convert `snake_case` properties to `camelCase`? | +| `--export` | `-e` | `false` | Exports the namespace | ### Node @@ -107,6 +108,7 @@ in handy. | `namespace` | `string` | `OpenAPI2` | How should the output be namespaced? (namespacing is enforced as there’s a high chance of collision) | | `swagger` | `number` | `2` | Which Swagger version to use. Currently only supports `2`. | | `camelcase` | `boolean` | `false` | Convert `snake_case` properties to `camelCase` | +| `export` | `boolean` | `false` | Exports the namespace | [glob]: https://www.npmjs.com/package/glob [js-yaml]: https://www.npmjs.com/package/js-yaml diff --git a/bin/cli.js b/bin/cli.js index 21ab874f1..c7b09135c 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -19,6 +19,7 @@ Options --output, -o specify output file --camelcase, -c convert snake_case properties to camelCase (default: off) --swagger, -s specify Swagger version (default: 2) + --export, -e exports the namespace (default: false) `, { flags: { @@ -39,6 +40,11 @@ Options type: 'number', alias: 's', }, + export: { + type: 'boolean', + default: false, + alias: 'e', + }, }, } ); diff --git a/src/swagger-2.ts b/src/swagger-2.ts index f52e2e571..2cc6dd4d9 100644 --- a/src/swagger-2.ts +++ b/src/swagger-2.ts @@ -23,6 +23,7 @@ export interface Swagger2 { export interface Swagger2Options { camelcase?: boolean; namespace?: string; + export?: boolean; } // Primitives only! @@ -43,9 +44,12 @@ 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[] = [`namespace ${namespace} {`]; + + const output: string[] = shouldExport ? ['export '] : []; + output.push(`namespace ${namespace} {`); const { definitions } = spec;