codegen-openapi-ts 0.3.1 → 0.3.2
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/README.md +46 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
- Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
|
|
12
12
|
- Quick, lightweight, robust and framework-agnostic 🚀
|
|
13
13
|
- Supports generation of TypeScript clients
|
|
14
|
-
- Supports conversion from Swagger 1.x/2.x to OpenAPI 2.x/3.x
|
|
14
|
+
- 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)
|
|
15
15
|
- Supports JSON and YAML files for input
|
|
16
|
-
- Supports generation through
|
|
16
|
+
- Supports generation through Node.js
|
|
17
17
|
- Supports tsc and @babel/plugin-transform-typescript
|
|
18
18
|
- Supports external references using [`json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser/)
|
|
19
19
|
|
|
@@ -27,61 +27,63 @@ npm install codegen-openapi-ts --save-dev
|
|
|
27
27
|
## Usage
|
|
28
28
|
|
|
29
29
|
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
--request <value> Path to custom request file
|
|
43
|
-
-h, --help display help for command
|
|
44
|
-
|
|
45
|
-
Examples
|
|
46
|
-
$ openapi --input ./spec.json
|
|
47
|
-
$ openapi --input ./spec.json --output ./dist
|
|
48
|
-
$ openapi --input ./spec.json --output ./dist --client xhr
|
|
30
|
+
const OpenAPI = require('codegen-openapi-ts')
|
|
31
|
+
|
|
32
|
+
OpenAPI.convertAndGenerate({
|
|
33
|
+
from: string, // swagger_1, swagger_2, openapi_3, api_blueprint, io_docs, google, raml, wadl
|
|
34
|
+
to: string, // swagger_1, swagger_2, openapi_3, api_blueprint, io_docs, google, raml, wadl
|
|
35
|
+
source: string // url or local file (JSON, YAML)
|
|
36
|
+
}, {
|
|
37
|
+
input: string, // generated conversion output path, also used as input
|
|
38
|
+
output: string, // generated output folder location
|
|
39
|
+
useOptions: boolean, // use options as url methods argument
|
|
40
|
+
useUnionTypes: boolean // use union types instead of enum
|
|
41
|
+
})
|
|
49
42
|
```
|
|
50
43
|
|
|
51
44
|
|
|
52
45
|
## Example
|
|
46
|
+
**fetch-schema.js**
|
|
47
|
+
```javascript
|
|
48
|
+
// fetch-schema.js
|
|
49
|
+
const OpenAPI = require('codegen-openapi-ts')
|
|
50
|
+
|
|
51
|
+
OpenAPI.convertAndGenerate(
|
|
52
|
+
{
|
|
53
|
+
from: process.argv[2], // swagger_2
|
|
54
|
+
to: 'openapi_3',
|
|
55
|
+
source: process.argv[3] // https://pokemon-api/docs/api
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
input: 'scripts/api-schema.json',
|
|
59
|
+
output: 'src/api-types/' + process.argv[4], // pokemon-api
|
|
60
|
+
useOptions: true,
|
|
61
|
+
useUnionTypes: true
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
```
|
|
53
65
|
|
|
54
66
|
**package.json**
|
|
55
67
|
```json
|
|
56
68
|
{
|
|
57
69
|
"scripts": {
|
|
58
|
-
"generate": "
|
|
70
|
+
"generate": "node fetch-schema.js swagger_2 https://pokemon-api/docs/api pokemon-api"
|
|
59
71
|
}
|
|
60
72
|
}
|
|
61
|
-
```
|
|
62
73
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
```
|
|
66
|
-
npx codegen-openapi-ts --input ./spec.json --output ./dist
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
**Node.js API**
|
|
70
|
-
|
|
71
|
-
```javascript
|
|
72
|
-
const OpenAPI = require('codegen-openapi-ts');
|
|
73
|
-
|
|
74
|
-
OpenAPI.generate({
|
|
75
|
-
input: './spec.json',
|
|
76
|
-
output: './dist'
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// Or by providing the content of the spec directly 🚀
|
|
80
|
-
OpenAPI.generate({
|
|
81
|
-
input: require('./spec.json'),
|
|
82
|
-
output: './dist'
|
|
83
|
-
});
|
|
74
|
+
// npm run generate
|
|
84
75
|
```
|
|
76
|
+
### Output folder
|
|
77
|
+
.
|
|
78
|
+
├── ...
|
|
79
|
+
├── src # output value ('src/api-types/')
|
|
80
|
+
│ ├── api-types
|
|
81
|
+
│ | ├── pokemon-api # process.argv[4]
|
|
82
|
+
│ | | ├── models # API schema models
|
|
83
|
+
│ | | ├── services # API service level with methods/url/response/request types
|
|
84
|
+
│ | | └── index.ts
|
|
85
|
+
| | └── ...
|
|
86
|
+
└── ...
|
|
85
87
|
|
|
86
88
|
|
|
87
89
|
## Features
|
package/package.json
CHANGED