codegen-openapi-ts 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 devteaa
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 devteaa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,274 +1,216 @@
1
- # OpenAPI Typescript Codegen
2
-
3
- [![NPM][npm-image]][npm-url]
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
- ![Build](https://github.com/devTeaa/codegen-openapi-ts/actions/workflows/CI.yml/badge.svg)
6
-
7
- > Node.js library that generates Typescript clients based on the OpenAPI specification.
8
-
9
- > This project is a fork from [Openapi Typescript Codegen](https://github.com/ferdikoomen/openapi-typescript-codegen) by [Ferdi Koomen](https://github.com/ferdikoomen), the reason is because I need some changes and use some of the lower level generated code that I can use on my projects.
10
-
11
- ## Why?
12
- - Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
13
- - Quick, lightweight, robust and framework-agnostic 🚀
14
- - Supports generation of TypeScript clients
15
- - Supports conversion from Swagger 1.x/2.x to OpenAPI 2.x/3.x with [`api-spec-converter`](https://github.com/LucyBot-Inc/api-spec-converter)
16
- - Supports JSON and YAML files for input
17
- - Supports generation through Node.js
18
- - Supports tsc and @babel/plugin-transform-typescript
19
- - Supports external references using [`json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser/)
20
- - Supports generate multiple api based on config file
21
- - Supports only generate specified api based on the url and http method (v0.4.1)
22
- - Supports custom map model naming (v0.4.2)
23
- - Supports fetching single file and generate type from that (v0.4.3)
24
- - Supports custom url request mapping (ex: backend gateway) (v0.5.3)
25
- - Supports config autocomplete wrapper (v0.5.8)
26
- - Supports generating relevant models if selectedOnly (v0.5.8)
27
- - Supports esm config (v0.6.0)
28
-
29
- ## Install
30
-
31
- ```
32
- npm install codegen-openapi-ts --save-dev
33
- ```
34
-
35
-
36
- ## Usage
37
-
38
- **codegen.config.js**
39
- ```
40
- codegen-openapi-ts --help
41
- Usage: codegen-openapi-ts [options]
42
-
43
- Options:
44
- -V, --version output the version number
45
- --config <value> Path to config file (default: "codegen.config.js")
46
- -h, --help display help for command
47
- ```
48
- ```
49
- 'use strict';
50
-
51
- module.exports = defineConfig([
52
- {
53
- source: OpenAPI Swagger response (can check on the network response on the spec page),
54
- from: swagger_1, swagger_2, openapi_3, api_blueprint, io_docs, google, raml, wadl,
55
- output: output folder
56
- urlMethodMapping: [
57
- [api path, http method (get/post/put/delete), output operation name, custom url api path]
58
- ],
59
- selectedOnly: this will make it so only generate services under urlMethodMapping, the default is false,
60
- modelNameMapping: [
61
- [regex model name on schema, output model name]
62
- ]
63
- },
64
- ]);
65
- ```
66
-
67
- **CLI**
68
- ```
69
- codegen-openapi-ts-cli --help
70
- Usage: codegen-openapi-ts-cli [options]
71
-
72
- Arguments:
73
- from Original response specification version
74
- source Swagger/OpenAPI response url
75
- output Output folder name (default: "output")
76
-
77
- Options:
78
- -V, --version output the version number
79
- -h, --help display help for command
80
- ```
81
-
82
- **Node**
83
- ```
84
- OpenAPI.convertAndGenerate({
85
- from: string, // swagger_1, swagger_2, openapi_3, api_blueprint, io_docs, google, raml, wadl
86
- to: string, // swagger_1, swagger_2, openapi_3, api_blueprint, io_docs, google, raml, wadl
87
- source: string // url or local file (JSON, YAML)
88
- }, {
89
- input: string, // generated conversion output path, also used as input
90
- output: string, // generated output folder location
91
- useOptions: boolean, // use options as url methods argument
92
- useUnionTypes: boolean // use union types instead of enum
93
- })
94
- ```
95
-
96
-
97
- ## Example
98
- **codegen.config.js**
99
- ```javascript
100
- 'use strict';
101
-
102
- module.exports = [
103
- {
104
- source: 'http://pokemon-api/docs/api',
105
- from: 'openapi_3',
106
- output: 'src/api-types/pokemon-api', // pokemon-api
107
- urlMethodMapping: [
108
- ['get-pokemon-list/gen1', 'get', 'GetPokemonListGen1'],
109
- ['get-pokemon-list/gen2', 'get', 'GetPokemonListGen2', 'gateway/get-pokemon-list/gen2'],
110
- ],
111
- selectedOnly: true,
112
- modelNameMapping: [
113
- ['some.custom.model.naming', 'CustomModelNaming']
114
- ],
115
- },
116
- {
117
- // source: '<git repo> <branch name> <file to path>',
118
- source: 'ssh://git@github.com/pokemon/pokemon-api.git master -- docs/evolution-path.json',
119
- from: 'openapi_3',
120
- output: 'src/api-types/evolution-path', // evolution-path
121
- },
122
- ];
123
- ```
124
-
125
- **CLI**
126
- ```bash
127
- codegen-openapi-ts-cli swagger_2 https://pokemonapi/docs/api
128
- codegen-openapi-ts-cli swagger_2 https://pokemonapi/docs/api pokemon-api
129
- ```
130
-
131
- **fetch-schema.js (Node)**
132
- ```javascript
133
- // fetch-schema.js
134
- const OpenAPI = require('codegen-openapi-ts')
135
-
136
- OpenAPI.convertAndGenerate(
137
- {
138
- from: process.argv[2], // swagger_2
139
- to: 'openapi_3',
140
- source: process.argv[3] // https://pokemon-api/docs/api
141
- },
142
- {
143
- input: 'scripts/api-schema.json',
144
- output: 'src/api-types/' + process.argv[4], // pokemon-api
145
- useOptions: true,
146
- useUnionTypes: true
147
- }
148
- )
149
- ```
150
- ```json
151
- // package.json
152
- {
153
- "scripts": {
154
- "generate": "node fetch-schema.js swagger_2 https://pokemon-api/docs/api pokemon-api"
155
- }
156
- }
157
-
158
- // npm run generate
159
- ```
160
- ### Output folder
161
- .
162
- ├── ...
163
- ├── src # output value ('src/api-types/')
164
- ├── api-types
165
- │ | ├── pokemon-api # output
166
- | | ├── models # API schema models
167
- | | ├── services # API service level with methods/url/response/request types
168
- │ | | └── index.ts
169
- | | └── ...
170
- └── ...
171
-
172
-
173
- ## Features
174
- ### Nullable in OpenAPI v2
175
- In the OpenAPI v3 spec you can create properties that can be NULL, by providing a `nullable: true` in your schema.
176
- However, the v2 spec does not allow you to do this. You can use the unofficial `x-nullable` in your specification
177
- to generate nullable properties in OpenApi v2.
178
-
179
- ```json
180
- {
181
- "ModelWithNullableString": {
182
- "required": ["requiredProp"],
183
- "description": "This is a model with one string property",
184
- "type": "object",
185
- "properties": {
186
- "prop": {
187
- "description": "This is a simple string property",
188
- "type": "string",
189
- "x-nullable": true
190
- },
191
- "requiredProp": {
192
- "description": "This is a simple string property",
193
- "type": "string",
194
- "x-nullable": true
195
- }
196
- }
197
- }
198
- }
199
- ```
200
-
201
- Generated code:
202
- ```typescript
203
- interface ModelWithNullableString {
204
- prop?: string | null,
205
- requiredProp: string | null,
206
- }
207
- ```
208
-
209
- ### References
210
-
211
- Local references to schema definitions (those beginning with `#/definitions/schemas/`)
212
- will be converted to type references to the equivalent, generated top-level type.
213
-
214
- The OpenAPI generator also supports external references, which allows you to break
215
- down your openapi.yml into multiple sub-files, or incorporate third-party schemas
216
- as part of your types to ensure everything is able to be TypeScript generated.
217
-
218
- External references may be:
219
- * *relative references* - references to other files at the same location e.g.
220
- `{ $ref: 'schemas/customer.yml' }`
221
- * *remote references* - fully qualified references to another remote location
222
- e.g. `{ $ref: 'https://myexampledomain.com/schemas/customer_schema.yml' }`
223
-
224
- For remote references, both files (when the file is on the current filesystem)
225
- and http(s) URLs are supported.
226
-
227
- External references may also contain internal paths in the external schema (e.g.
228
- `schemas/collection.yml#/definitions/schemas/Customer`) and back-references to
229
- the base openapi file or between files (so that you can reference another
230
- schema in the main file as a type of an object or array property, for example).
231
-
232
- At start-up, an OpenAPI or Swagger file with external references will be "bundled",
233
- so that all external references and back-references will be resolved (but local
234
- references preserved).
235
-
236
-
237
- FAQ
238
- ===
239
-
240
- ### Babel support
241
- If you use enums inside your models / definitions then those enums are by default inside a namespace with the same name
242
- as your model. This is called declaration merging. However, the [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript)
243
- does not support these namespaces, so if you are using babel in your project please use the `--useUnionTypes` flag
244
- to generate union types instead of traditional enums. More info can be found here: [Enums vs. Union Types](#enums-vs-union-types---useuniontypes).
245
-
246
- **Note:** If you are using Babel 7 and Typescript 3.8 (or higher) then you should enable the `onlyRemoveTypeImports` to
247
- ignore any 'type only' imports, see https://babeljs.io/docs/en/babel-preset-typescript#onlyremovetypeimports for more info
248
-
249
- ```javascript
250
- module.exports = {
251
- presets: [
252
- ['@babel/preset-typescript', {
253
- onlyRemoveTypeImports: true,
254
- }],
255
- ],
256
- };
257
- ```
258
-
259
- In order to compile the project and resolve the imports, you will need to enable the `allowSyntheticDefaultImports`
260
- in your `tsconfig.json` file.
261
-
262
-
263
- [npm-url]: https://npmjs.org/package/
264
- [npm-image]: https://img.shields.io/npm/v/codegen-openapi-ts.svg
265
- [coverage-url]: https://codecov.io/gh/ferdikoomen/codegen-openapi-ts
266
- [coverage-image]: https://img.shields.io/codecov/c/github/ferdikoomen/codegen-openapi-ts.svg
267
- [quality-url]: https://lgtm.com/projects/g/ferdikoomen/codegen-openapi-ts
268
- [quality-image]: https://img.shields.io/lgtm/grade/javascript/g/ferdikoomen/codegen-openapi-ts.svg
269
- [climate-url]: https://codeclimate.com/github/ferdikoomen/codegen-openapi-ts
270
- [climate-image]: https://img.shields.io/codeclimate/maintainability/ferdikoomen/codegen-openapi-ts.svg
271
- [downloads-url]: http://npm-stat.com/charts.html?package=codegen-openapi-ts
272
- [downloads-image]: http://img.shields.io/npm/dm/codegen-openapi-ts.svg
273
- [build-url]: https://circleci.com/gh/ferdikoomen/codegen-openapi-ts/tree/master
274
- [build-image]: https://circleci.com/gh/ferdikoomen/codegen-openapi-ts/tree/master.svg?style=svg
1
+ # OpenAPI Typescript Codegen
2
+
3
+ [![NPM][npm-image]][npm-url]
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ ![Build](https://github.com/devTeaa/codegen-openapi-ts/actions/workflows/CI.yml/badge.svg)
6
+
7
+ > Node.js library that generates Typescript clients based on the OpenAPI specification.
8
+
9
+ > This project is a fork from [Openapi Typescript Codegen](https://github.com/ferdikoomen/openapi-typescript-codegen) by [Ferdi Koomen](https://github.com/ferdikoomen), the reason is because I need some changes and use some of the lower level generated code that I can use on my projects.
10
+
11
+ ## Why?
12
+ - Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
13
+ - Quick, lightweight, robust and framework-agnostic 🚀
14
+ - Supports generation of TypeScript clients
15
+ - Supports conversion from Swagger 1.x/2.x to OpenAPI 2.x/3.x with [`api-spec-converter`](https://github.com/LucyBot-Inc/api-spec-converter)
16
+ - Supports JSON and YAML files for input
17
+ - Supports generation through Node.js
18
+ - Supports tsc and @babel/plugin-transform-typescript
19
+ - Supports external references using [`json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser/)
20
+ - Supports generate multiple api based on config file
21
+ - Supports only generate specified api based on the url and http method (v0.4.1)
22
+ - Supports custom map model naming (v0.4.2)
23
+ - Supports fetching single file and generate type from that (v0.4.3)
24
+ - Supports custom url request mapping (ex: backend gateway) (v0.5.3)
25
+ - Supports config autocomplete wrapper (v0.5.8)
26
+ - Supports generating relevant models if selectedOnly (v0.5.8)
27
+ - Supports esm config (v0.6.0)
28
+
29
+ ## Install
30
+
31
+ ```
32
+ npm install codegen-openapi-ts --save-dev
33
+ ```
34
+
35
+
36
+ ## Usage
37
+
38
+ ```
39
+ codegen-openapi-ts --help
40
+ Usage: codegen-openapi-ts [options]
41
+
42
+ Options:
43
+ -V, --version output the version number
44
+ --config <value> Path to config file (default: "codegen.config.js")
45
+ -h, --help display help for command
46
+ ```
47
+
48
+ **codegen.config.js**
49
+ ```
50
+ export default defineConfig([
51
+ {
52
+ source: OpenAPI Swagger response (can check on the network response on the spec page),
53
+ from: swagger_1, swagger_2, openapi_3, api_blueprint, io_docs, google, raml, wadl,
54
+ output: output folder
55
+ urlMethodMapping: [
56
+ [api path, http method (get/post/put/delete), output operation name, custom url api path]
57
+ ],
58
+ selectedOnly: this will make it so only generate services under urlMethodMapping, the default is false,
59
+ modelNameMapping: [
60
+ [regex model name on schema, output model name]
61
+ ]
62
+ },
63
+ ]);
64
+ ```
65
+
66
+ ## Example
67
+ **codegen.config.js**
68
+ ```javascript
69
+ module.exports = [
70
+ {
71
+ source: 'http://pokemon-api/docs/api',
72
+ from: 'openapi_3',
73
+ output: 'src/api-types/pokemon-api', // pokemon-api
74
+ urlMethodMapping: [
75
+ ['get-pokemon-list/gen1', 'get', 'GetPokemonListGen1'],
76
+ ['get-pokemon-list/gen2', 'get', 'GetPokemonListGen2', 'gateway/get-pokemon-list/gen2'],
77
+ ],
78
+ selectedOnly: true,
79
+ modelNameMapping: [
80
+ ['some.custom.model.naming', 'CustomModelNaming']
81
+ ],
82
+ },
83
+ {
84
+ // source: '<git repo> <branch name> <file to path>',
85
+ source: 'ssh://git@github.com/pokemon/pokemon-api.git master -- docs/evolution-path.json',
86
+ from: 'openapi_3',
87
+ output: 'src/api-types/evolution-path', // evolution-path
88
+ },
89
+ ];
90
+ ```
91
+
92
+ **package.json**
93
+ ```json
94
+ {
95
+ "scripts": {
96
+ "codegen": "codegen-openapi-ts"
97
+ }
98
+ }
99
+
100
+ // npm run generate
101
+ ```
102
+ ### Output folder
103
+ .
104
+ ├── ...
105
+ ├── src # output value ('src/api-types/')
106
+ │ ├── api-types
107
+ │ | ├── pokemon-api # output
108
+ │ | | ├── models # API schema models
109
+ │ | | ├── services # API service level with methods/url/response/request types
110
+ │ | | └── index.ts
111
+ | | └── ...
112
+ └── ...
113
+
114
+
115
+ ## Features
116
+ ### Nullable in OpenAPI v2
117
+ In the OpenAPI v3 spec you can create properties that can be NULL, by providing a `nullable: true` in your schema.
118
+ However, the v2 spec does not allow you to do this. You can use the unofficial `x-nullable` in your specification
119
+ to generate nullable properties in OpenApi v2.
120
+
121
+ ```json
122
+ {
123
+ "ModelWithNullableString": {
124
+ "required": ["requiredProp"],
125
+ "description": "This is a model with one string property",
126
+ "type": "object",
127
+ "properties": {
128
+ "prop": {
129
+ "description": "This is a simple string property",
130
+ "type": "string",
131
+ "x-nullable": true
132
+ },
133
+ "requiredProp": {
134
+ "description": "This is a simple string property",
135
+ "type": "string",
136
+ "x-nullable": true
137
+ }
138
+ }
139
+ }
140
+ }
141
+ ```
142
+
143
+ Generated code:
144
+ ```typescript
145
+ interface ModelWithNullableString {
146
+ prop?: string | null,
147
+ requiredProp: string | null,
148
+ }
149
+ ```
150
+
151
+ ### References
152
+
153
+ Local references to schema definitions (those beginning with `#/definitions/schemas/`)
154
+ will be converted to type references to the equivalent, generated top-level type.
155
+
156
+ The OpenAPI generator also supports external references, which allows you to break
157
+ down your openapi.yml into multiple sub-files, or incorporate third-party schemas
158
+ as part of your types to ensure everything is able to be TypeScript generated.
159
+
160
+ External references may be:
161
+ * *relative references* - references to other files at the same location e.g.
162
+ `{ $ref: 'schemas/customer.yml' }`
163
+ * *remote references* - fully qualified references to another remote location
164
+ e.g. `{ $ref: 'https://myexampledomain.com/schemas/customer_schema.yml' }`
165
+
166
+ For remote references, both files (when the file is on the current filesystem)
167
+ and http(s) URLs are supported.
168
+
169
+ External references may also contain internal paths in the external schema (e.g.
170
+ `schemas/collection.yml#/definitions/schemas/Customer`) and back-references to
171
+ the base openapi file or between files (so that you can reference another
172
+ schema in the main file as a type of an object or array property, for example).
173
+
174
+ At start-up, an OpenAPI or Swagger file with external references will be "bundled",
175
+ so that all external references and back-references will be resolved (but local
176
+ references preserved).
177
+
178
+
179
+ FAQ
180
+ ===
181
+
182
+ ### Babel support
183
+ If you use enums inside your models / definitions then those enums are by default inside a namespace with the same name
184
+ as your model. This is called declaration merging. However, the [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript)
185
+ does not support these namespaces, so if you are using babel in your project please use the `--useUnionTypes` flag
186
+ to generate union types instead of traditional enums. More info can be found here: [Enums vs. Union Types](#enums-vs-union-types---useuniontypes).
187
+
188
+ **Note:** If you are using Babel 7 and Typescript 3.8 (or higher) then you should enable the `onlyRemoveTypeImports` to
189
+ ignore any 'type only' imports, see https://babeljs.io/docs/en/babel-preset-typescript#onlyremovetypeimports for more info
190
+
191
+ ```javascript
192
+ module.exports = {
193
+ presets: [
194
+ ['@babel/preset-typescript', {
195
+ onlyRemoveTypeImports: true,
196
+ }],
197
+ ],
198
+ };
199
+ ```
200
+
201
+ In order to compile the project and resolve the imports, you will need to enable the `allowSyntheticDefaultImports`
202
+ in your `tsconfig.json` file.
203
+
204
+
205
+ [npm-url]: https://npmjs.org/package/
206
+ [npm-image]: https://img.shields.io/npm/v/codegen-openapi-ts.svg
207
+ [coverage-url]: https://codecov.io/gh/ferdikoomen/codegen-openapi-ts
208
+ [coverage-image]: https://img.shields.io/codecov/c/github/ferdikoomen/codegen-openapi-ts.svg
209
+ [quality-url]: https://lgtm.com/projects/g/ferdikoomen/codegen-openapi-ts
210
+ [quality-image]: https://img.shields.io/lgtm/grade/javascript/g/ferdikoomen/codegen-openapi-ts.svg
211
+ [climate-url]: https://codeclimate.com/github/ferdikoomen/codegen-openapi-ts
212
+ [climate-image]: https://img.shields.io/codeclimate/maintainability/ferdikoomen/codegen-openapi-ts.svg
213
+ [downloads-url]: http://npm-stat.com/charts.html?package=codegen-openapi-ts
214
+ [downloads-image]: http://img.shields.io/npm/dm/codegen-openapi-ts.svg
215
+ [build-url]: https://circleci.com/gh/ferdikoomen/codegen-openapi-ts/tree/master
216
+ [build-image]: https://circleci.com/gh/ferdikoomen/codegen-openapi-ts/tree/master.svg?style=svg
package/bin/cli.js CHANGED
@@ -1,35 +1,35 @@
1
- #!/usr/bin/env node
2
-
3
- 'use strict';
4
-
5
- const path = require('path');
6
- const program = require('commander');
7
- const pkg = require('../package.json');
8
-
9
- const params = program
10
- .name('codegen-openapi-ts-cli')
11
- .usage('[options]')
12
- .version(pkg.version)
13
- .argument('<from>', 'Original response specification version')
14
- .argument('<source>', 'Swagger/OpenAPI response url')
15
- .argument('[output]', 'Output folder name', 'output')
16
- .parse(process.argv)
17
- .processedArgs;
18
-
19
- const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
20
-
21
- if (OpenAPI) {
22
- OpenAPI.convertAndGenerate(
23
- {
24
- from: params[0],
25
- to: 'openapi_3',
26
- source: params[1]
27
- },
28
- {
29
- input: 'api-schema.json',
30
- output: params[2],
31
- useOptions: true,
32
- useUnionTypes: true
33
- },
34
- )
35
- }
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const path = require('path');
6
+ const program = require('commander');
7
+ const pkg = require('../package.json');
8
+
9
+ const params = program
10
+ .name('codegen-openapi-ts-cli')
11
+ .usage('[options]')
12
+ .version(pkg.version)
13
+ .argument('<from>', 'Original response specification version')
14
+ .argument('<source>', 'Swagger/OpenAPI response url')
15
+ .argument('[output]', 'Output folder name', 'output')
16
+ .parse(process.argv)
17
+ .processedArgs;
18
+
19
+ const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
20
+
21
+ if (OpenAPI) {
22
+ OpenAPI.convertAndGenerate(
23
+ {
24
+ from: params[0],
25
+ to: 'openapi_3',
26
+ source: params[1]
27
+ },
28
+ {
29
+ input: 'api-schema.json',
30
+ output: params[2],
31
+ useOptions: true,
32
+ useUnionTypes: true
33
+ },
34
+ )
35
+ }