|
12 | 12 |
|
13 | 13 | ## Why?
|
14 | 14 | - Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
|
15 |
| -- Quick, lightweight, robust and framework agnostic 🚀 |
| 15 | +- Quick, lightweight, robust and framework-agnostic 🚀 |
16 | 16 | - Supports generation of TypeScript clients
|
17 |
| -- Supports generations of fetch, XHR and Axios http clients |
| 17 | +- Supports generations of Fetch, [Node-Fetch](#node-fetch-support), [Axios](#axios-support) and XHR http clients |
18 | 18 | - Supports OpenAPI specification v2.0 and v3.0
|
19 | 19 | - Supports JSON and YAML files for input
|
20 | 20 | - Supports generation through CLI, Node.js and NPX
|
@@ -445,19 +445,45 @@ module.exports = {
|
445 | 445 | };
|
446 | 446 | ```
|
447 | 447 |
|
| 448 | +### Axios support |
| 449 | +This tool allows you to generate a client based on the [`axios`](https://www.npmjs.com/package/axios) client. |
| 450 | +The advantage of the Axios client is that it works in both NodeJS and Browser based environments. |
| 451 | +If you want to generate the Axios based client then you can specify `--client axios` in the openapi call: |
448 | 452 |
|
449 |
| -### Node.js support |
450 |
| -> Since version 3.x [`node-fetch`](https://www.npmjs.com/package/node-fetch) switched to ESM only, breaking many |
451 |
| -> CommonJS based toolchains (like Jest). Right now we do not support this new version! |
| 453 | +`openapi --input ./spec.json --output ./dist --client axios` |
452 | 454 |
|
453 |
| -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), |
454 |
| -however this client will not work inside the Node.js environment. If you want to generate a Node.js compatible client then |
455 |
| -you can specify `--client node` in the openapi call: |
| 455 | +The only downside is that this client needs some additional dependencies to work, due to the missing Blob and FormData |
| 456 | +classes in NodeJS. |
| 457 | + |
| 458 | +``` |
| 459 | +npm install axios --save-dev |
| 460 | +npm install [email protected] --save-dev |
| 461 | +npm install [email protected] --save-dev |
| 462 | +npm install [email protected] --save-dev |
| 463 | +``` |
| 464 | + |
| 465 | +In order to compile the project and resolve the imports, you will need to enable the `allowSyntheticDefaultImports` |
| 466 | +in your `tsconfig.json` file. |
| 467 | + |
| 468 | +```json |
| 469 | +{ |
| 470 | + "allowSyntheticDefaultImports": true |
| 471 | +} |
| 472 | +``` |
| 473 | + |
| 474 | + |
| 475 | +### Node-Fetch support |
| 476 | +By default, this tool will generate a client that is compatible with the (browser based) Fetch API. |
| 477 | +However, this client will not work inside the Node.js environment. If you want to generate the Node.js compatible |
| 478 | +client then you can specify `--client node` in the openapi call: |
456 | 479 |
|
457 | 480 | `openapi --input ./spec.json --output ./dist --client node`
|
458 | 481 |
|
459 | 482 | This will generate a client that uses [`node-fetch`](https://www.npmjs.com/package/node-fetch) internally. However,
|
460 |
| -in order to compile and run this client, you might need to install the `[email protected]` dependencies: |
| 483 | +in order to compile and run this client, you might need to install the `[email protected]` dependencies. |
| 484 | + |
| 485 | +> Since version 3.x [`node-fetch`](https://www.npmjs.com/package/node-fetch) switched to ESM only, |
| 486 | +> breaking many CommonJS based toolchains (like Jest). Right now we do not support this new version! |
461 | 487 |
|
462 | 488 | ```
|
463 | 489 | npm install @types/[email protected] --save-dev
|
|
0 commit comments