Skip to content

Commit 9ff09b6

Browse files
committed
- Updated documentation
1 parent fe4cd3e commit 9ff09b6

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

README.md

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
- Supports tsc and @babel/plugin-transform-typescript
2020

2121

22-
## Babel support:
23-
If you use enums inside your models / definitions then those enums are by default inside a namespace with the same name
24-
as your model. This is called declaration merging. However, the [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript)
25-
does not support these namespaces, so if you are using babel in your project please use the `--useUnionTypes` flag
26-
to generate union types instead of traditional enums. More info can be found here: [Enums vs. Union Types](#enums-vs-union-types---useuniontypes).
27-
28-
2922
## Install
3023

3124
```
@@ -44,7 +37,7 @@ $ openapi --help
4437
-V, --version output the version number
4538
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
4639
-o, --output <value> Output directory (required)
47-
-c, --client <value> HTTP client to generate [fetch, xhr] (default: "fetch")
40+
-c, --client <value> HTTP client to generate [fetch, xhr, node] (default: "fetch")
4841
--useOptions Use options instead of arguments
4942
--useUnionTypes Use union types instead of enums
5043
--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
354347
compare against the openapi-typescript-codegen.
355348

356349
[Click here to see the comparison](https://htmlpreview.github.io/?https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/samples/index.html)
350+
351+
352+
FAQ
353+
===
354+
355+
### Babel support
356+
If you use enums inside your models / definitions then those enums are by default inside a namespace with the same name
357+
as your model. This is called declaration merging. However, the [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript)
358+
does not support these namespaces, so if you are using babel in your project please use the `--useUnionTypes` flag
359+
to generate union types instead of traditional enums. More info can be found here: [Enums vs. Union Types](#enums-vs-union-types---useuniontypes).
360+
361+
**Note:** If you are using Babel 7 and Typescript 3.8 (or higher) then you should enable the `onlyRemoveTypeImports` to
362+
ignore any 'type only' imports, see https://babeljs.io/docs/en/babel-preset-typescript#onlyremovetypeimports for more info
363+
364+
```javascript
365+
module.exports = {
366+
presets: [
367+
['@babel/preset-typescript', {
368+
onlyRemoveTypeImports: true,
369+
}],
370+
],
371+
};
372+
```
373+
374+
375+
### Node.js support
376+
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),
377+
however this client will not work inside the Node.js environment. If you want to generate a Node.js compatible client then
378+
you can specify `--client node` in the openapi call:
379+
380+
`openapi --input ./spec.json --output ./dist --client node`
381+
382+
This will generate a client that uses [`node-fetch`](https://www.npmjs.com/package/node-fetch) internally. However,
383+
in order to compile and run this client, you will need to install the `node-fetch` dependencies:
384+
385+
```
386+
npm install @types/node-fetch --save-dev
387+
npm install node-fetch --save-dev
388+
npm install form-data --save-dev
389+
```

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-typescript-codegen",
3-
"version": "0.5.0",
3+
"version": "0.5.0-alpha",
44
"description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.",
55
"author": "Ferdi Koomen",
66
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",
@@ -62,14 +62,11 @@
6262
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b"
6363
},
6464
"dependencies": {
65-
"@types/node-fetch": "2.5.7",
6665
"camelcase": "6.0.0",
6766
"commander": "6.1.0",
68-
"form-data": "3.0.0",
6967
"handlebars": "4.7.6",
7068
"js-yaml": "3.14.0",
7169
"mkdirp": "1.0.4",
72-
"node-fetch": "2.6.1",
7370
"path": "0.12.7",
7471
"rimraf": "3.0.2"
7572
},
@@ -85,6 +82,7 @@
8582
"@types/js-yaml": "3.12.5",
8683
"@types/mkdirp": "1.0.1",
8784
"@types/node": "14.11.2",
85+
"@types/node-fetch": "2.5.7",
8886
"@types/rimraf": "3.0.0",
8987
"@typescript-eslint/eslint-plugin": "4.2.0",
9088
"@typescript-eslint/parser": "4.2.0",
@@ -94,9 +92,11 @@
9492
"eslint-plugin-prettier": "3.1.4",
9593
"eslint-plugin-simple-import-sort": "5.0.3",
9694
"express": "4.17.1",
95+
"form-data": "3.0.0",
9796
"glob": "7.1.6",
9897
"jest": "26.4.2",
9998
"jest-cli": "26.4.2",
99+
"node-fetch": "2.6.1",
100100
"prettier": "2.1.2",
101101
"puppeteer": "5.3.1",
102102
"rollup": "2.28.2",

src/templates/core/xhr/sendRequest.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function sendRequest(options: ApiRequestOptions, url: string): Promise<XMLHttpRe
66
xhr.withCredentials = OpenAPI.WITH_CREDENTIALS;
77

88
const headers = getHeaders(options);
9-
headers.forEach((value, key) => {
9+
headers.forEach((value: string, key: string) => {
1010
xhr.setRequestHeader(key, value);
1111
});
1212

test/e2e/v2.node.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ describe('v2.node', () => {
99

1010
beforeAll(async () => {
1111
await generate('v2/node', 'v2', 'node');
12-
await copy('v2/node');
1312
compile('v2/node');
1413
await server.start('v2/node');
1514
}, 30000);

test/e2e/v3.node.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ describe('v3.node', () => {
99

1010
beforeAll(async () => {
1111
await generate('v3/node', 'v3', 'node');
12-
await copy('v3/node');
1312
compile('v3/node');
1413
await server.start('v3/node');
1514
}, 30000);

0 commit comments

Comments
 (0)