Skip to content

Commit 5b3348d

Browse files
committed
- Added axios client
- Added function to escape path and stopped replacement of ":" character in path
1 parent de3a44a commit 5b3348d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+833
-865
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ updates:
66
interval: weekly
77
time: "04:00"
88
open-pull-requests-limit: 10
9+
ignore:
10+
- dependency-name: "@types/node-fetch"
11+
- dependency-name: "node-fetch"

README.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
1616
- Quick, lightweight, robust and framework agnostic 🚀
1717
- Supports generation of TypeScript clients
18-
- Supports generations of fetch and XHR http clients
18+
- Supports generations of fetch, XHR and Axios http clients
1919
- Supports OpenAPI specification v2.0 and v3.0
2020
- Supports JSON and YAML files for input
2121
- Supports generation through CLI, Node.js and NPX
@@ -40,7 +40,7 @@ $ openapi --help
4040
-V, --version output the version number
4141
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
4242
-o, --output <value> Output directory (required)
43-
-c, --client <value> HTTP client to generate [fetch, xhr, node] (default: "fetch")
43+
-c, --client <value> HTTP client to generate [fetch, xhr, axios, node] (default: "fetch")
4444
--useOptions Use options instead of arguments
4545
--useUnionTypes Use union types instead of enums
4646
--exportCore <value> Write core files to disk (default: true)
@@ -403,12 +403,12 @@ as part of your types to ensure everything is able to be TypeScript generated.
403403

404404
External references may be:
405405
* *relative references* - references to other files at the same ___location e.g.
406-
`{ $ref: 'schemas/customer.yml' }`
406+
`{ $ref: 'schemas/customer.yml' }`
407407
* *remote references* - fully qualified references to another remote ___location
408-
e.g. `{ $ref: 'https://myexampledomain.com/schemas/customer_schema.yml' }`
408+
e.g. `{ $ref: 'https://myexampledomain.com/schemas/customer_schema.yml' }`
409409

410-
For remote references, both files (when the file is on the current filesystem)
411-
and http(s) URLs are supported.
410+
For remote references, both files (when the file is on the current filesystem)
411+
and http(s) URLs are supported.
412412

413413
External references may also contain internal paths in the external schema (e.g.
414414
`schemas/collection.yml#/definitions/schemas/Customer`) and back-references to
@@ -419,14 +419,6 @@ At start-up, an OpenAPI or Swagger file with external references will be "bundle
419419
so that all external references and back-references will be resolved (but local
420420
references preserved).
421421

422-
### Compare to other generators
423-
Depending on which swagger generator you use, you will see different output.
424-
For instance: Different ways of generating models, services, level of quality,
425-
HTTP client, etc. I've compiled a list with the results per area and how they
426-
compare against the openapi-typescript-codegen.
427-
428-
[Click here to see the comparison](https://htmlpreview.github.io/?https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/samples/index.html)
429-
430422

431423
FAQ
432424
===
@@ -452,18 +444,22 @@ module.exports = {
452444

453445

454446
### Node.js support
447+
> Since version 3.x [`node-fetch`](https://www.npmjs.com/package/node-fetch) switched to ESM only, breaking many
448+
> CommonJS based toolchains (like Jest). Right now we do not support this new version!
449+
455450
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),
456451
however this client will not work inside the Node.js environment. If you want to generate a Node.js compatible client then
457452
you can specify `--client node` in the openapi call:
458453

459454
`openapi --input ./spec.json --output ./dist --client node`
460455

461456
This will generate a client that uses [`node-fetch`](https://www.npmjs.com/package/node-fetch) internally. However,
462-
in order to compile and run this client, you will need to install the `[email protected]` dependencies:
457+
in order to compile and run this client, you might need to install the `[email protected]` dependencies:
463458

464459
```
465-
npm install node-fetch --save-dev
466-
npm install form-data --save-dev
460+
npm install @types/[email protected] --save-dev
461+
npm install [email protected] --save-dev
462+
npm install [email protected] --save-dev
467463
```
468464

469465
In order to compile the project and resolve the imports, you will need to enable the `allowSyntheticDefaultImports`

bin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const params = program
1212
.version(pkg.version)
1313
.requiredOption('-i, --input <value>', 'OpenAPI specification, can be a path, url or string content (required)')
1414
.requiredOption('-o, --output <value>', 'Output directory (required)')
15-
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr, node]', 'fetch')
15+
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr, node, axios]', 'fetch')
1616
.option('--useOptions', 'Use options instead of arguments')
1717
.option('--useUnionTypes', 'Use union types instead of enums')
1818
.option('--exportCore <value>', 'Write core files to disk', true)

jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ module.exports = {
2020
testMatch: [
2121
'<rootDir>/test/e2e/v2.fetch.spec.js',
2222
'<rootDir>/test/e2e/v2.xhr.spec.js',
23+
'<rootDir>/test/e2e/v2.axios.spec.js',
2324
'<rootDir>/test/e2e/v2.node.spec.js',
2425
'<rootDir>/test/e2e/v2.babel.spec.js',
2526
'<rootDir>/test/e2e/v3.fetch.spec.js',
2627
'<rootDir>/test/e2e/v3.xhr.spec.js',
28+
'<rootDir>/test/e2e/v3.axios.spec.js',
2729
'<rootDir>/test/e2e/v3.node.spec.js',
2830
'<rootDir>/test/e2e/v3.babel.spec.js',
2931
],

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
}
3333
],
3434
"main": "dist/index.js",
35-
"module": "dist/index.js",
3635
"types": "types/index.d.ts",
3736
"bin": {
3837
"openapi": "bin/index.js"
@@ -61,31 +60,33 @@
6160
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b"
6261
},
6362
"dependencies": {
64-
"@types/node-fetch": "^3.0.3",
63+
"@types/node-fetch": "^2.5.12",
64+
"axios": "^0.22.0",
6565
"camelcase": "^6.2.0",
6666
"commander": "^8.0.0",
6767
"form-data": "^4.0.0",
6868
"handlebars": "^4.7.6",
6969
"js-yaml": "^4.0.0",
7070
"json-schema-ref-parser": "^9.0.7",
7171
"mkdirp": "^1.0.4",
72-
"node-fetch": "^3.0.0",
72+
"node-fetch": "^2.6.5",
7373
"rimraf": "^3.0.2"
7474
},
7575
"devDependencies": {
7676
"@babel/cli": "7.15.7",
77-
"@babel/core": "7.15.5",
78-
"@babel/preset-env": "7.15.6",
77+
"@babel/core": "7.15.8",
78+
"@babel/preset-env": "7.15.8",
7979
"@babel/preset-typescript": "7.15.0",
8080
"@rollup/plugin-commonjs": "21.0.0",
8181
"@rollup/plugin-node-resolve": "13.0.5",
8282
"@types/express": "4.17.13",
83+
"@types/glob": "7.1.4",
8384
"@types/jest": "27.0.2",
8485
"@types/js-yaml": "4.0.3",
8586
"@types/node": "16.10.3",
8687
"@types/qs": "6.9.7",
8788
"@typescript-eslint/eslint-plugin": "4.33.0",
88-
"@typescript-eslint/parser": "4.32.0",
89+
"@typescript-eslint/parser": "4.33.0",
8990
"codecov": "3.8.3",
9091
"eslint": "7.32.0",
9192
"eslint-config-prettier": "8.3.0",

0 commit comments

Comments
 (0)