Skip to content

Commit

Permalink
- Added axios client
Browse files Browse the repository at this point in the history
- Added function to escape path and stopped replacement of ":" character in path
  • Loading branch information
ferdikoomen committed Oct 8, 2021
1 parent de3a44a commit 5b3348d
Show file tree
Hide file tree
Showing 49 changed files with 833 additions and 865 deletions.
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ updates:
interval: weekly
time: "04:00"
open-pull-requests-limit: 10
ignore:
- dependency-name: "@types/node-fetch"
- dependency-name: "node-fetch"
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
- Quick, lightweight, robust and framework agnostic 🚀
- Supports generation of TypeScript clients
- Supports generations of fetch and XHR http clients
- Supports generations of fetch, XHR and Axios http clients
- Supports OpenAPI specification v2.0 and v3.0
- Supports JSON and YAML files for input
- Supports generation through CLI, Node.js and NPX
Expand All @@ -40,7 +40,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, node] (default: "fetch")
-c, --client <value> HTTP client to generate [fetch, xhr, axios, 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)
Expand Down Expand Up @@ -403,12 +403,12 @@ as part of your types to ensure everything is able to be TypeScript generated.

External references may be:
* *relative references* - references to other files at the same location e.g.
`{ $ref: 'schemas/customer.yml' }`
`{ $ref: 'schemas/customer.yml' }`
* *remote references* - fully qualified references to another remote location
e.g. `{ $ref: 'https://myexampledomain.com/schemas/customer_schema.yml' }`
e.g. `{ $ref: 'https://myexampledomain.com/schemas/customer_schema.yml' }`

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

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

### Compare to other generators
Depending on which swagger generator you use, you will see different output.
For instance: Different ways of generating models, services, level of quality,
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
===
Expand All @@ -452,18 +444,22 @@ module.exports = {


### Node.js support
> Since version 3.x [`node-fetch`](https://www.npmjs.com/package/node-fetch) switched to ESM only, breaking many
> CommonJS based toolchains (like Jest). Right now we do not support this new version!
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 `[email protected]` dependencies:
in order to compile and run this client, you might need to install the `[email protected]` dependencies:

```
npm install node-fetch --save-dev
npm install form-data --save-dev
npm install @types/[email protected] --save-dev
npm install [email protected] --save-dev
npm install [email protected] --save-dev
```

In order to compile the project and resolve the imports, you will need to enable the `allowSyntheticDefaultImports`
Expand Down
2 changes: 1 addition & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const params = program
.version(pkg.version)
.requiredOption('-i, --input <value>', 'OpenAPI specification, can be a path, url or string content (required)')
.requiredOption('-o, --output <value>', 'Output directory (required)')
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr, node]', 'fetch')
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr, node, axios]', 'fetch')
.option('--useOptions', 'Use options instead of arguments')
.option('--useUnionTypes', 'Use union types instead of enums')
.option('--exportCore <value>', 'Write core files to disk', true)
Expand Down
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ module.exports = {
testMatch: [
'<rootDir>/test/e2e/v2.fetch.spec.js',
'<rootDir>/test/e2e/v2.xhr.spec.js',
'<rootDir>/test/e2e/v2.axios.spec.js',
'<rootDir>/test/e2e/v2.node.spec.js',
'<rootDir>/test/e2e/v2.babel.spec.js',
'<rootDir>/test/e2e/v3.fetch.spec.js',
'<rootDir>/test/e2e/v3.xhr.spec.js',
'<rootDir>/test/e2e/v3.axios.spec.js',
'<rootDir>/test/e2e/v3.node.spec.js',
'<rootDir>/test/e2e/v3.babel.spec.js',
],
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
}
],
"main": "dist/index.js",
"module": "dist/index.js",
"types": "types/index.d.ts",
"bin": {
"openapi": "bin/index.js"
Expand Down Expand Up @@ -61,31 +60,33 @@
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b"
},
"dependencies": {
"@types/node-fetch": "^3.0.3",
"@types/node-fetch": "^2.5.12",
"axios": "^0.22.0",
"camelcase": "^6.2.0",
"commander": "^8.0.0",
"form-data": "^4.0.0",
"handlebars": "^4.7.6",
"js-yaml": "^4.0.0",
"json-schema-ref-parser": "^9.0.7",
"mkdirp": "^1.0.4",
"node-fetch": "^3.0.0",
"node-fetch": "^2.6.5",
"rimraf": "^3.0.2"
},
"devDependencies": {
"@babel/cli": "7.15.7",
"@babel/core": "7.15.5",
"@babel/preset-env": "7.15.6",
"@babel/core": "7.15.8",
"@babel/preset-env": "7.15.8",
"@babel/preset-typescript": "7.15.0",
"@rollup/plugin-commonjs": "21.0.0",
"@rollup/plugin-node-resolve": "13.0.5",
"@types/express": "4.17.13",
"@types/glob": "7.1.4",
"@types/jest": "27.0.2",
"@types/js-yaml": "4.0.3",
"@types/node": "16.10.3",
"@types/qs": "6.9.7",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/parser": "4.32.0",
"@typescript-eslint/parser": "4.33.0",
"codecov": "3.8.3",
"eslint": "7.32.0",
"eslint-config-prettier": "8.3.0",
Expand Down
Loading

0 comments on commit 5b3348d

Please sign in to comment.