Skip to content

Commit 485b60a

Browse files
committed
Add missing namespace option to README, alter API
1 parent 02628a0 commit 485b60a

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

Diff for: README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@ npm i --save-dev @manifoldco/swagger-to-ts
2929
```js
3030
const swaggerToTS = require('@manifoldco/swagger-to-ts');
3131

32-
graphqlGen(spec, [options]);
32+
swaggerToTS(spec, [options]);
3333
```
3434

3535
`spec` must be in JSON format. For an example of converting YAML to JSON, see
3636
the [generate.js](./scripts/generate.js) script.
3737

3838
### Options
3939

40-
| Name | Default | Description |
41-
| :-------- | :------- | :--------------------------------------------------------- |
42-
| `output` | (stdout) | Where should the output file be saved? |
43-
| `swagger` | `2` | Which Swagger version to use. Currently only supports `2`. |
40+
| Name | Default | Description |
41+
| :---------- | :--------- | :--------------------------------------------------------------------------------------------------- |
42+
| `output` | (stdout) | Where should the output file be saved? |
43+
| `namespace` | `OpenAPI2` | How should the output be namespaced? (namespacing is enforced as there’s a high chance of collision) |
44+
| `swagger` | `2` | Which Swagger version to use. Currently only supports `2`. |
4445

4546
[namespace]: https://www.typescriptlang.org/docs/handbook/namespaces.html
4647
[prettier]: https://npmjs.com/prettier

Diff for: bin/cli.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ try {
6969
);
7070
}
7171

72-
const result = swaggerToTS(spec, cli.flags.namespace, cli.flags);
72+
const result = swaggerToTS(spec, cli.flags);
7373

7474
// Write to file if specifying output
7575
if (cli.flags.output) {
@@ -81,11 +81,7 @@ if (cli.flags.output) {
8181

8282
const timeEnd = process.hrtime(timeStart);
8383
const time = timeEnd[0] + Math.round(timeEnd[1] / 1e6);
84-
console.log(
85-
chalk.green(
86-
`🚀 ${cli.input[0]} -> ${chalk.bold(cli.flags.output)} [${time}ms]`
87-
)
88-
);
84+
console.log(chalk.green(`🚀 ${cli.input[0]} -> ${chalk.bold(cli.flags.output)} [${time}ms]`));
8985
return;
9086
}
9187

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@manifoldco/swagger-to-ts",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Generate TypeScript types from Swagger OpenAPI specs",
55
"main": "dist/cjs",
66
"engines": {

Diff for: scripts/build.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ if (!existsSync(output)) {
2020
// Build JS
2121
const build = format =>
2222
rollup({
23-
input: `./src/index.ts`,
23+
input: './src/index.ts',
2424
plugins: PLUGINS[format],
2525
}).then(bundle =>
2626
bundle.write({
2727
file: resolve(output, `${format}.js`),
2828
format,
29-
name: 'graphqlGen',
29+
name: 'SwaggerToTS',
3030
})
3131
);
3232

Diff for: src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import swagger2, { Swagger2 } from './swagger-2';
22

3-
export default (spec: Swagger2, namespace?: string, options?: { version?: number }) => {
3+
export default (spec: Swagger2, options?: { namespace?: string; version?: number }) => {
44
const version = (options && options.version) || 2;
5+
const namespace = (options && options.namespace) || `OpenAPI${version}`;
56

67
if (version === 1 || version === 3) {
78
console.error('That version is not supported');
89
return;
910
}
1011

11-
return swagger2(spec, namespace || `OpenAPI${version}`);
12+
return swagger2(spec, namespace);
1213
};

0 commit comments

Comments
 (0)