Skip to content

Commit d7c153f

Browse files
committed
Merge branch 'master' into feature/cancelable
# Conflicts: # README.md # package.json # src/utils/registerHandlebarTemplates.ts # test/__snapshots__/index.spec.js.snap # test/custom/request.ts # test/e2e/v3.fetch.spec.js # test/e2e/v3.node.spec.js # yarn.lock
2 parents 4f46fe5 + b532279 commit d7c153f

File tree

99 files changed

+2864
-3700
lines changed

Some content is hidden

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

99 files changed

+2864
-3700
lines changed

.circleci/config.yml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
version: 2
22
jobs:
3-
build:
4-
working_directory: ~/repo
5-
docker:
6-
- image: circleci/node:latest-browsers
7-
steps:
8-
- checkout
9-
- restore_cache:
10-
keys:
11-
- v1-dependencies-{{ checksum "package.json" }}
12-
- v1-dependencies-
13-
- run:
14-
name: Install dependencies
15-
command: yarn install
16-
- save_cache:
17-
key: v1-dependencies-{{ checksum "package.json" }}
18-
paths:
19-
- node_modules
20-
- run:
21-
name: Build library
22-
command: yarn run release
23-
- run:
24-
name: Run unit tests
25-
command: yarn run test:coverage
26-
- run:
27-
name: Run e2e tests
28-
command: yarn run test:e2e
29-
- run:
30-
name: Submit to Codecov
31-
command: yarn run codecov
3+
build:
4+
working_directory: ~/repo
5+
docker:
6+
- image: circleci/node:latest-browsers
7+
steps:
8+
- checkout
9+
- restore_cache:
10+
keys:
11+
- v1-dependencies-{{ checksum "package.json" }}
12+
- v1-dependencies-
13+
- run:
14+
name: Install dependencies
15+
command: yarn install
16+
- save_cache:
17+
key: v1-dependencies-{{ checksum "package.json" }}
18+
paths:
19+
- node_modules
20+
- run:
21+
name: Build library
22+
command: yarn run release
23+
- run:
24+
name: Run unit tests
25+
command: yarn run test:coverage
26+
- run:
27+
name: Run e2e tests
28+
command: yarn run test:e2e
29+
- run:
30+
name: Submit to Codecov
31+
command: yarn run codecov

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: monthly
7+
time: "04:00"
8+
open-pull-requests-limit: 10
9+
ignore:
10+
- dependency-name: "@types/node-fetch"
11+
- dependency-name: "node-fetch"

.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ https://help.github.com/articles/using-pull-requests
2727
5. Ensure the code is formatted by running: `yarn run eslint:fix`
2828
6. Commit your changes using a descriptive commit message
2929

30-
After your Pull Request is created, it will automatically be build using Circle CI
31-
and Travis. When the build is successful then the Pull Request is ready for review.
30+
After your Pull Request is created, it will automatically be build using Circle CI.
31+
When the build is successful then the Pull Request is ready for review.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Ferdi Koomen
3+
Copyright (c) 2021 Ferdi Koomen
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22

33
[![NPM][npm-image]][npm-url]
44
[![License][license-image]][license-url]
5-
[![Build Status][travis-image]][travis-url]
6-
[![Dependency Status][deps-image]][deps-url]
75
[![Coverage][coverage-image]][coverage-url]
86
[![Quality][quality-image]][quality-url]
97
[![Code Climate][climate-image]][climate-url]
108
[![Downloads][downloads-image]][downloads-url]
9+
[![Build][build-image]][build-url]
1110

1211
> Node.js library that generates Typescript clients based on the OpenAPI specification.
1312
1413
## Why?
1514
- Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds
1615
- Quick, lightweight, robust and framework agnostic 🚀
1716
- Supports generation of TypeScript clients
18-
- Supports generations of fetch and XHR http clients
17+
- Supports generations of fetch, XHR and Axios http clients
1918
- Supports OpenAPI specification v2.0 and v3.0
2019
- Supports JSON and YAML files for input
2120
- Supports generation through CLI, Node.js and NPX
@@ -41,13 +40,15 @@ $ openapi --help
4140
-V, --version output the version number
4241
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
4342
-o, --output <value> Output directory (required)
44-
-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")
4544
--useOptions Use options instead of arguments
4645
--useUnionTypes Use union types instead of enums
4746
--exportCore <value> Write core files to disk (default: true)
4847
--exportServices <value> Write services to disk (default: true)
4948
--exportModels <value> Write models to disk (default: true)
5049
--exportSchemas <value> Write schemas to disk (default: false)
50+
--request <value> Path to custom request file
51+
-h, --help display help for command
5152
5253
Examples
5354
$ openapi --input ./spec.json
@@ -404,12 +405,12 @@ as part of your types to ensure everything is able to be TypeScript generated.
404405

405406
External references may be:
406407
* *relative references* - references to other files at the same ___location e.g.
407-
`{ $ref: 'schemas/customer.yml' }`
408+
`{ $ref: 'schemas/customer.yml' }`
408409
* *remote references* - fully qualified references to another remote ___location
409-
e.g. `{ $ref: 'https://myexampledomain.com/schemas/customer_schema.yml' }`
410+
e.g. `{ $ref: 'https://myexampledomain.com/schemas/customer_schema.yml' }`
410411

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

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

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

432425
FAQ
433426
===
@@ -453,14 +446,17 @@ module.exports = {
453446

454447

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

460456
`openapi --input ./spec.json --output ./dist --client node`
461457

462458
This will generate a client that uses [`node-fetch`](https://www.npmjs.com/package/node-fetch) internally. However,
463-
in order to compile and run this client, you will need to install the `node-fetch` dependencies:
459+
in order to compile and run this client, you might need to install the `node-fetch@2.x` dependencies:
464460

465461
```
466462
npm install @types/node-fetch --save-dev
@@ -483,10 +479,6 @@ in your `tsconfig.json` file.
483479
[npm-image]: https://img.shields.io/npm/v/openapi-typescript-codegen.svg
484480
[license-url]: LICENSE
485481
[license-image]: http://img.shields.io/npm/l/openapi-typescript-codegen.svg
486-
[travis-url]: https://travis-ci.org/ferdikoomen/openapi-typescript-codegen
487-
[travis-image]: https://img.shields.io/travis/ferdikoomen/openapi-typescript-codegen.svg
488-
[deps-url]: https://david-dm.org/ferdikoomen/openapi-typescript-codegen
489-
[deps-image]: https://img.shields.io/david/ferdikoomen/openapi-typescript-codegen.svg
490482
[coverage-url]: https://codecov.io/gh/ferdikoomen/openapi-typescript-codegen
491483
[coverage-image]: https://img.shields.io/codecov/c/github/ferdikoomen/openapi-typescript-codegen.svg
492484
[quality-url]: https://lgtm.com/projects/g/ferdikoomen/openapi-typescript-codegen
@@ -495,3 +487,5 @@ in your `tsconfig.json` file.
495487
[climate-image]: https://img.shields.io/codeclimate/maintainability/ferdikoomen/openapi-typescript-codegen.svg
496488
[downloads-url]: http://npm-stat.com/charts.html?package=openapi-typescript-codegen
497489
[downloads-image]: http://img.shields.io/npm/dm/openapi-typescript-codegen.svg
490+
[build-url]: https://circleci.com/gh/ferdikoomen/openapi-typescript-codegen/tree/master
491+
[build-image]: https://circleci.com/gh/ferdikoomen/openapi-typescript-codegen/tree/master.svg?style=svg

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: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-typescript-codegen",
3-
"version": "0.10.0",
3+
"version": "0.11.0",
44
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
55
"author": "Ferdi Koomen",
66
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",
@@ -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,47 +60,48 @@
6160
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b"
6261
},
6362
"dependencies": {
63+
"@types/node-fetch": "^2.5.12",
64+
"abort-controller": "^3.0.0",
65+
"axios": "^0.23.0",
6466
"camelcase": "^6.2.0",
65-
"commander": "^7.0.0",
67+
"commander": "^8.0.0",
68+
"form-data": "^4.0.0",
6669
"handlebars": "^4.7.6",
67-
"js-yaml": "^4.0.0",
6870
"json-schema-ref-parser": "^9.0.7",
6971
"mkdirp": "^1.0.4",
72+
"node-fetch": "^2.6.5",
7073
"rimraf": "^3.0.2"
7174
},
7275
"devDependencies": {
73-
"@babel/cli": "7.13.10",
74-
"@babel/core": "7.13.10",
75-
"@babel/preset-env": "7.13.10",
76-
"@babel/preset-typescript": "7.13.0",
77-
"@rollup/plugin-commonjs": "17.1.0",
78-
"@rollup/plugin-node-resolve": "11.2.0",
79-
"@types/express": "4.17.11",
80-
"@types/jest": "26.0.20",
81-
"@types/js-yaml": "4.0.0",
82-
"@types/node": "14.14.32",
83-
"@types/node-fetch": "2.5.8",
84-
"@types/qs": "6.9.6",
85-
"@typescript-eslint/eslint-plugin": "4.17.0",
86-
"@typescript-eslint/parser": "4.17.0",
87-
"abort-controller": "3.0.0",
88-
"codecov": "3.8.1",
89-
"eslint": "7.21.0",
90-
"eslint-config-prettier": "8.1.0",
91-
"eslint-plugin-prettier": "3.3.1",
76+
"@babel/cli": "7.15.7",
77+
"@babel/core": "7.15.8",
78+
"@babel/preset-env": "7.15.8",
79+
"@babel/preset-typescript": "7.15.0",
80+
"@rollup/plugin-commonjs": "21.0.0",
81+
"@rollup/plugin-node-resolve": "13.0.5",
82+
"@types/express": "4.17.13",
83+
"@types/glob": "7.1.4",
84+
"@types/jest": "27.0.2",
85+
"@types/node": "16.11.1",
86+
"@types/qs": "6.9.7",
87+
"@typescript-eslint/eslint-plugin": "5.1.0",
88+
"@typescript-eslint/parser": "5.1.0",
89+
"codecov": "3.8.3",
90+
"eslint": "8.0.1",
91+
"eslint-config-prettier": "8.3.0",
92+
"eslint-plugin-prettier": "4.0.0",
9293
"eslint-plugin-simple-import-sort": "7.0.0",
9394
"express": "4.17.1",
94-
"form-data": "4.0.0",
95-
"glob": "7.1.6",
96-
"jest": "26.6.3",
97-
"jest-cli": "26.6.3",
98-
"node-fetch": "2.6.1",
99-
"prettier": "2.2.1",
100-
"puppeteer": "8.0.0",
101-
"qs": "6.9.6",
102-
"rollup": "2.41.0",
95+
"glob": "7.2.0",
96+
"jest": "27.3.0",
97+
"jest-cli": "27.3.0",
98+
"prettier": "2.4.1",
99+
"puppeteer": "10.4.0",
100+
"qs": "6.10.1",
101+
"rollup": "2.58.0",
103102
"rollup-plugin-terser": "7.0.2",
104103
"rollup-plugin-typescript2": "0.30.0",
105-
"typescript": "4.2.3"
104+
"tslib": "2.3.1",
105+
"typescript": "4.4.4"
106106
}
107107
}

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const getPlugins = () => {
5757
return plugins;
5858
}
5959
return [...plugins, terser()];
60-
}
60+
};
6161

6262
module.exports = {
6363
input: './src/index.ts',

0 commit comments

Comments
 (0)