Skip to content

Commit 8485931

Browse files
committed
- Added documentation on Axios
1 parent 1f9917b commit 8485931

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
1313
## Why?
1414
- 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 🚀
1616
- 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
1818
- Supports OpenAPI specification v2.0 and v3.0
1919
- Supports JSON and YAML files for input
2020
- Supports generation through CLI, Node.js and NPX
@@ -445,19 +445,45 @@ module.exports = {
445445
};
446446
```
447447

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:
448452

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`
452454

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:
456479

457480
`openapi --input ./spec.json --output ./dist --client node`
458481

459482
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!
461487
462488
```
463489
npm install @types/[email protected] --save-dev

0 commit comments

Comments
 (0)