Skip to content

Commit 11a1d3a

Browse files
tpdewolfDangoDev
authored andcommitted
Add an option to export the namespace (#11)
* add export keyword to output before namespace * run test * added option to export * remove logs and make tests pass
1 parent 596d90b commit 11a1d3a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ also use the Node API (below).
7373
| `--namespace [name]` | `-n` | `OpenAPI2` | How should the output be namespaced? (namespacing is enforced as there’s a high chance of collision) |
7474
| `--swagger [version]` | `-s` | `2` | Which Swagger version to use. Currently only supports `2`. |
7575
| `--camelcase` | `-c` | `false` | Convert `snake_case` properties to `camelCase`? |
76+
| `--export` | `-e` | `false` | Exports the namespace |
7677

7778
### Node
7879

@@ -107,6 +108,7 @@ in handy.
107108
| `namespace` | `string` | `OpenAPI2` | How should the output be namespaced? (namespacing is enforced as there’s a high chance of collision) |
108109
| `swagger` | `number` | `2` | Which Swagger version to use. Currently only supports `2`. |
109110
| `camelcase` | `boolean` | `false` | Convert `snake_case` properties to `camelCase` |
111+
| `export` | `boolean` | `false` | Exports the namespace |
110112

111113
[glob]: https://www.npmjs.com/package/glob
112114
[js-yaml]: https://www.npmjs.com/package/js-yaml

bin/cli.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Options
1919
--output, -o specify output file
2020
--camelcase, -c convert snake_case properties to camelCase (default: off)
2121
--swagger, -s specify Swagger version (default: 2)
22+
--export, -e exports the namespace (default: false)
2223
`,
2324
{
2425
flags: {
@@ -39,6 +40,11 @@ Options
3940
type: 'number',
4041
alias: 's',
4142
},
43+
export: {
44+
type: 'boolean',
45+
default: false,
46+
alias: 'e',
47+
},
4248
},
4349
}
4450
);

src/swagger-2.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Swagger2 {
2323
export interface Swagger2Options {
2424
camelcase?: boolean;
2525
namespace?: string;
26+
export?: boolean;
2627
}
2728

2829
// Primitives only!
@@ -43,9 +44,12 @@ function camelCase(name: string): string {
4344
function parse(spec: Swagger2, options: Swagger2Options = {}): string {
4445
const namespace = options.namespace || 'OpenAPI2';
4546
const shouldCamelCase = options.camelcase || false;
47+
const shouldExport = options.export || false;
4648

4749
const queue: [string, Swagger2Definition][] = [];
48-
const output: string[] = [`namespace ${namespace} {`];
50+
51+
const output: string[] = shouldExport ? ['export '] : [];
52+
output.push(`namespace ${namespace} {`);
4953

5054
const { definitions } = spec;
5155

0 commit comments

Comments
 (0)