mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Updated documentation
This commit is contained in:
parent
fe4cd3ee37
commit
9ff09b6786
49
README.md
49
README.md
@ -19,13 +19,6 @@
|
||||
- Supports tsc and @babel/plugin-transform-typescript
|
||||
|
||||
|
||||
## Babel support:
|
||||
If you use enums inside your models / definitions then those enums are by default inside a namespace with the same name
|
||||
as your model. This is called declaration merging. However, the [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript)
|
||||
does not support these namespaces, so if you are using babel in your project please use the `--useUnionTypes` flag
|
||||
to generate union types instead of traditional enums. More info can be found here: [Enums vs. Union Types](#enums-vs-union-types---useuniontypes).
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
@ -44,7 +37,7 @@ $ openapi --help
|
||||
-V, --version output the version number
|
||||
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
|
||||
-o, --output <value> Output directory (required)
|
||||
-c, --client <value> HTTP client to generate [fetch, xhr] (default: "fetch")
|
||||
-c, --client <value> HTTP client to generate [fetch, xhr, node] (default: "fetch")
|
||||
--useOptions Use options instead of arguments
|
||||
--useUnionTypes Use union types instead of enums
|
||||
--exportCore <value> Write core files to disk (default: true)
|
||||
@ -354,3 +347,43 @@ HTTP client, etc. I've compiled a list with the results per area and how they
|
||||
compare against the openapi-typescript-codegen.
|
||||
|
||||
[Click here to see the comparison](https://htmlpreview.github.io/?https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/samples/index.html)
|
||||
|
||||
|
||||
FAQ
|
||||
===
|
||||
|
||||
### Babel support
|
||||
If you use enums inside your models / definitions then those enums are by default inside a namespace with the same name
|
||||
as your model. This is called declaration merging. However, the [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript)
|
||||
does not support these namespaces, so if you are using babel in your project please use the `--useUnionTypes` flag
|
||||
to generate union types instead of traditional enums. More info can be found here: [Enums vs. Union Types](#enums-vs-union-types---useuniontypes).
|
||||
|
||||
**Note:** If you are using Babel 7 and Typescript 3.8 (or higher) then you should enable the `onlyRemoveTypeImports` to
|
||||
ignore any 'type only' imports, see https://babeljs.io/docs/en/babel-preset-typescript#onlyremovetypeimports for more info
|
||||
|
||||
```javascript
|
||||
module.exports = {
|
||||
presets: [
|
||||
['@babel/preset-typescript', {
|
||||
onlyRemoveTypeImports: true,
|
||||
}],
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
### Node.js support
|
||||
By default, this library will generate a client that is compatible with the (browser based) [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API),
|
||||
however this client will not work inside the Node.js environment. If you want to generate a Node.js compatible client then
|
||||
you can specify `--client node` in the openapi call:
|
||||
|
||||
`openapi --input ./spec.json --output ./dist --client node`
|
||||
|
||||
This will generate a client that uses [`node-fetch`](https://www.npmjs.com/package/node-fetch) internally. However,
|
||||
in order to compile and run this client, you will need to install the `node-fetch` dependencies:
|
||||
|
||||
```
|
||||
npm install @types/node-fetch --save-dev
|
||||
npm install node-fetch --save-dev
|
||||
npm install form-data --save-dev
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openapi-typescript-codegen",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.0-alpha",
|
||||
"description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.",
|
||||
"author": "Ferdi Koomen",
|
||||
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",
|
||||
@ -62,14 +62,11 @@
|
||||
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node-fetch": "2.5.7",
|
||||
"camelcase": "6.0.0",
|
||||
"commander": "6.1.0",
|
||||
"form-data": "3.0.0",
|
||||
"handlebars": "4.7.6",
|
||||
"js-yaml": "3.14.0",
|
||||
"mkdirp": "1.0.4",
|
||||
"node-fetch": "2.6.1",
|
||||
"path": "0.12.7",
|
||||
"rimraf": "3.0.2"
|
||||
},
|
||||
@ -85,6 +82,7 @@
|
||||
"@types/js-yaml": "3.12.5",
|
||||
"@types/mkdirp": "1.0.1",
|
||||
"@types/node": "14.11.2",
|
||||
"@types/node-fetch": "2.5.7",
|
||||
"@types/rimraf": "3.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "4.2.0",
|
||||
"@typescript-eslint/parser": "4.2.0",
|
||||
@ -94,9 +92,11 @@
|
||||
"eslint-plugin-prettier": "3.1.4",
|
||||
"eslint-plugin-simple-import-sort": "5.0.3",
|
||||
"express": "4.17.1",
|
||||
"form-data": "3.0.0",
|
||||
"glob": "7.1.6",
|
||||
"jest": "26.4.2",
|
||||
"jest-cli": "26.4.2",
|
||||
"node-fetch": "2.6.1",
|
||||
"prettier": "2.1.2",
|
||||
"puppeteer": "5.3.1",
|
||||
"rollup": "2.28.2",
|
||||
|
||||
@ -6,7 +6,7 @@ function sendRequest(options: ApiRequestOptions, url: string): Promise<XMLHttpRe
|
||||
xhr.withCredentials = OpenAPI.WITH_CREDENTIALS;
|
||||
|
||||
const headers = getHeaders(options);
|
||||
headers.forEach((value, key) => {
|
||||
headers.forEach((value: string, key: string) => {
|
||||
xhr.setRequestHeader(key, value);
|
||||
});
|
||||
|
||||
|
||||
@ -9,7 +9,6 @@ describe('v2.node', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
await generate('v2/node', 'v2', 'node');
|
||||
await copy('v2/node');
|
||||
compile('v2/node');
|
||||
await server.start('v2/node');
|
||||
}, 30000);
|
||||
|
||||
@ -9,7 +9,6 @@ describe('v3.node', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
await generate('v3/node', 'v3', 'node');
|
||||
await copy('v3/node');
|
||||
compile('v3/node');
|
||||
await server.start('v3/node');
|
||||
}, 30000);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user