File tree 5 files changed +14
-16
lines changed
5 files changed +14
-16
lines changed Original file line number Diff line number Diff line change @@ -29,18 +29,19 @@ npm i --save-dev @manifoldco/swagger-to-ts
29
29
``` js
30
30
const swaggerToTS = require (' @manifoldco/swagger-to-ts' );
31
31
32
- graphqlGen (spec, [options]);
32
+ swaggerToTS (spec, [options]);
33
33
```
34
34
35
35
` spec ` must be in JSON format. For an example of converting YAML to JSON, see
36
36
the [ generate.js] ( ./scripts/generate.js ) script.
37
37
38
38
### Options
39
39
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 ` . |
44
45
45
46
[ namespace ] : https://www.typescriptlang.org/docs/handbook/namespaces.html
46
47
[ prettier ] : https://npmjs.com/prettier
Original file line number Diff line number Diff line change 69
69
) ;
70
70
}
71
71
72
- const result = swaggerToTS ( spec , cli . flags . namespace , cli . flags ) ;
72
+ const result = swaggerToTS ( spec , cli . flags ) ;
73
73
74
74
// Write to file if specifying output
75
75
if ( cli . flags . output ) {
@@ -81,11 +81,7 @@ if (cli.flags.output) {
81
81
82
82
const timeEnd = process . hrtime ( timeStart ) ;
83
83
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]` ) ) ;
89
85
return ;
90
86
}
91
87
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @manifoldco/swagger-to-ts" ,
3
- "version" : " 1.0.0 " ,
3
+ "version" : " 1.0.1 " ,
4
4
"description" : " Generate TypeScript types from Swagger OpenAPI specs" ,
5
5
"main" : " dist/cjs" ,
6
6
"engines" : {
Original file line number Diff line number Diff line change @@ -20,13 +20,13 @@ if (!existsSync(output)) {
20
20
// Build JS
21
21
const build = format =>
22
22
rollup ( {
23
- input : ` ./src/index.ts` ,
23
+ input : ' ./src/index.ts' ,
24
24
plugins : PLUGINS [ format ] ,
25
25
} ) . then ( bundle =>
26
26
bundle . write ( {
27
27
file : resolve ( output , `${ format } .js` ) ,
28
28
format,
29
- name : 'graphqlGen ' ,
29
+ name : 'SwaggerToTS ' ,
30
30
} )
31
31
) ;
32
32
Original file line number Diff line number Diff line change 1
1
import swagger2 , { Swagger2 } from './swagger-2' ;
2
2
3
- export default ( spec : Swagger2 , namespace ?: string , options ?: { version ?: number } ) => {
3
+ export default ( spec : Swagger2 , options ?: { namespace ?: string ; version ?: number } ) => {
4
4
const version = ( options && options . version ) || 2 ;
5
+ const namespace = ( options && options . namespace ) || `OpenAPI${ version } ` ;
5
6
6
7
if ( version === 1 || version === 3 ) {
7
8
console . error ( 'That version is not supported' ) ;
8
9
return ;
9
10
}
10
11
11
- return swagger2 ( spec , namespace || `OpenAPI ${ version } ` ) ;
12
+ return swagger2 ( spec , namespace ) ;
12
13
} ;
You can’t perform that action at this time.
0 commit comments