File tree Expand file tree Collapse file tree 5 files changed +14
-16
lines changed Expand file tree Collapse file tree 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
2929``` js
3030const 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
3636the [ 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
Original file line number Diff line number Diff line change 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
7575if ( 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
Original file line number Diff line number Diff line change 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" : {
Original file line number Diff line number Diff line change @@ -20,13 +20,13 @@ if (!existsSync(output)) {
2020// Build JS
2121const 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
Original file line number Diff line number Diff line change 11import 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} ;
You can’t perform that action at this time.
0 commit comments