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.
Files changed (2) hide show
  1. package/README.md +46 -44
  2. 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 CLI, Node.js and NPX
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
- $ openapi --help
31
-
32
- Usage: openapi [options]
33
-
34
- Options:
35
- -V, --version output the version number
36
- -i, --input <value> OpenAPI specification, can be a path, url or string content (required)
37
- -o, --output <value> Output directory (required)
38
- --useUnionTypes Use union types instead of enums
39
- --exportServices <value> Write services to disk (default: true)
40
- --exportModels <value> Write models to disk (default: true)
41
- --postfix <value> Service name postfix (default: "Service")
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": "openapi --input ./spec.json --output ./dist"
70
+ "generate": "node fetch-schema.js swagger_2 https://pokemon-api/docs/api pokemon-api"
59
71
  }
60
72
  }
61
- ```
62
73
 
63
- **NPX**
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codegen-openapi-ts",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Library that generates Typescript clients based on the OpenAPI specification.",
5
5
  "author": "devteaa",
6
6
  "homepage": "https://github.com/devteaa/codegen-openapi-ts",