mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Added support for node fetch 3.x, but recommend 2.x for Jest and NodeJS compatibility
This commit is contained in:
parent
75c335a24a
commit
931ee9c805
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Ferdi Koomen
|
||||
Copyright (c) 2021 Ferdi Koomen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@ -459,10 +459,9 @@ 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 `node-fetch` dependencies:
|
||||
in order to compile and run this client, you will need to install the `node-fetch@2.x` dependencies:
|
||||
|
||||
```
|
||||
npm install @types/node-fetch --save-dev
|
||||
npm install node-fetch --save-dev
|
||||
npm install form-data --save-dev
|
||||
```
|
||||
|
||||
@ -61,12 +61,15 @@
|
||||
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node-fetch": "^2.5.12",
|
||||
"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": "^2.6.5",
|
||||
"rimraf": "^3.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -89,11 +92,9 @@
|
||||
"eslint-plugin-prettier": "4.0.0",
|
||||
"eslint-plugin-simple-import-sort": "7.0.0",
|
||||
"express": "4.17.1",
|
||||
"form-data": "4.0.0",
|
||||
"glob": "7.2.0",
|
||||
"jest": "27.2.2",
|
||||
"jest-cli": "27.2.2",
|
||||
"node-fetch": "3.0.0",
|
||||
"prettier": "2.4.1",
|
||||
"puppeteer": "10.4.0",
|
||||
"qs": "6.10.1",
|
||||
|
||||
@ -29,7 +29,7 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
|
||||
if (options.body) {
|
||||
if (options.mediaType) {
|
||||
headers.append('Content-Type', options.mediaType);
|
||||
} else if (isBlob(options.body)) {
|
||||
} else if (isBlob(options.body) || isBinary(options.body)) {
|
||||
headers.append('Content-Type', 'application/octet-stream');
|
||||
} else if (isString(options.body)) {
|
||||
headers.append('Content-Type', 'text/plain');
|
||||
|
||||
@ -5,8 +5,8 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
|
||||
if (options.body) {
|
||||
if (options.mediaType?.includes('/json')) {
|
||||
return JSON.stringify(options.body)
|
||||
} else if (isString(options.body) || isBlob(options.body)) {
|
||||
return options.body;
|
||||
} else if (isString(options.body) || isBlob(options.body) || isBinary(options.body)) {
|
||||
return options.body as any;
|
||||
} else {
|
||||
return JSON.stringify(options.body);
|
||||
}
|
||||
|
||||
@ -21,6 +21,9 @@ import { OpenAPI } from './OpenAPI';
|
||||
{{>functions/isBlob}}
|
||||
|
||||
|
||||
{{>functions/isBinary}}
|
||||
|
||||
|
||||
{{>functions/getQueryString}}
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{{~#equals base 'File'~}}
|
||||
{{~#equals @root.httpClient 'fetch'}}Blob{{/equals~}}
|
||||
{{~#equals @root.httpClient 'xhr'}}Blob{{/equals~}}
|
||||
{{~#equals @root.httpClient 'node'}}Blob{{/equals~}}
|
||||
{{~#equals @root.httpClient 'node'}}Blob | Buffer | ArrayBuffer | ArrayBufferView{{/equals~}}
|
||||
{{~else~}}
|
||||
{{{base}}}
|
||||
{{~/equals~}}
|
||||
|
||||
@ -17,8 +17,8 @@ describe('v2.fetch', () => {
|
||||
}, 30000);
|
||||
|
||||
afterAll(async () => {
|
||||
await server.stop();
|
||||
await browser.stop();
|
||||
await server.stop();
|
||||
});
|
||||
|
||||
it('requests token', async () => {
|
||||
|
||||
@ -17,8 +17,8 @@ describe('v2.fetch', () => {
|
||||
}, 30000);
|
||||
|
||||
afterAll(async () => {
|
||||
await server.stop();
|
||||
await browser.stop();
|
||||
await server.stop();
|
||||
});
|
||||
|
||||
it('requests token', async () => {
|
||||
|
||||
@ -18,7 +18,7 @@ describe('v2.node', () => {
|
||||
|
||||
it('requests token', async () => {
|
||||
const { OpenAPI, SimpleService } = require('./generated/v2/node/index.js');
|
||||
const tokenRequest = jest.fn().mockResolvedValue('MY_TOKEN')
|
||||
const tokenRequest = jest.fn().mockResolvedValue('MY_TOKEN');
|
||||
OpenAPI.TOKEN = tokenRequest;
|
||||
const result = await SimpleService.getCallWithoutParametersAndResponse();
|
||||
expect(tokenRequest.mock.calls.length).toBe(1);
|
||||
|
||||
@ -17,8 +17,8 @@ describe('v2.xhr', () => {
|
||||
}, 30000);
|
||||
|
||||
afterAll(async () => {
|
||||
await server.stop();
|
||||
await browser.stop();
|
||||
await server.stop();
|
||||
});
|
||||
|
||||
it('requests token', async () => {
|
||||
|
||||
@ -17,8 +17,8 @@ describe('v3.fetch', () => {
|
||||
}, 30000);
|
||||
|
||||
afterAll(async () => {
|
||||
await server.stop();
|
||||
await browser.stop();
|
||||
await server.stop();
|
||||
});
|
||||
|
||||
it('requests token', async () => {
|
||||
|
||||
@ -17,8 +17,8 @@ describe('v3.fetch', () => {
|
||||
}, 30000);
|
||||
|
||||
afterAll(async () => {
|
||||
await server.stop();
|
||||
await browser.stop();
|
||||
await server.stop();
|
||||
});
|
||||
|
||||
it('requests token', async () => {
|
||||
|
||||
@ -18,7 +18,7 @@ describe('v3.node', () => {
|
||||
|
||||
it('requests token', async () => {
|
||||
const { OpenAPI, SimpleService } = require('./generated/v3/node/index.js');
|
||||
const tokenRequest = jest.fn().mockResolvedValue('MY_TOKEN')
|
||||
const tokenRequest = jest.fn().mockResolvedValue('MY_TOKEN');
|
||||
OpenAPI.TOKEN = tokenRequest;
|
||||
OpenAPI.USERNAME = undefined;
|
||||
OpenAPI.PASSWORD = undefined;
|
||||
|
||||
@ -17,8 +17,8 @@ describe('v3.xhr', () => {
|
||||
}, 30000);
|
||||
|
||||
afterAll(async () => {
|
||||
await server.stop();
|
||||
await browser.stop();
|
||||
await server.stop();
|
||||
});
|
||||
|
||||
it('requests token', async () => {
|
||||
|
||||
79
yarn.lock
79
yarn.lock
@ -1377,15 +1377,23 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
|
||||
integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==
|
||||
|
||||
"@types/node-fetch@^2.5.12":
|
||||
version "2.5.12"
|
||||
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.12.tgz#8a6f779b1d4e60b7a57fb6fd48d84fb545b9cc66"
|
||||
integrity sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
form-data "^3.0.0"
|
||||
|
||||
"@types/node@*", "@types/node@16.10.1":
|
||||
version "16.10.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.10.1.tgz#f3647623199ca920960006b3dccf633ea905f243"
|
||||
integrity sha512-4/Z9DMPKFexZj/Gn3LylFgamNKHm4K3QDi0gz9B26Uk0c8izYf97B5fxfpspMNkWlFupblKM/nV8+NA9Ffvr+w==
|
||||
|
||||
"@types/prettier@^2.1.5":
|
||||
version "2.4.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.4.0.tgz#900b13362610ccd3570fb6eefb911a6732973d00"
|
||||
integrity sha512-WHRsy5nMpjXfU9B0LqOqPT06EI2+8Xv5NERy0pLxJLbU98q7uhcGogQzfX+rXpU7S5mgHsLxHrLCufZcV/P8TQ==
|
||||
version "2.4.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.4.1.tgz#e1303048d5389563e130f5bdd89d37a99acb75eb"
|
||||
integrity sha512-Fo79ojj3vdEZOHg3wR9ksAMRz4P3S5fDB5e/YWZiFnyFQI1WY2Vftu9XoXVVtJfxB7Bpce/QTqWSSntkz2Znrw==
|
||||
|
||||
"@types/qs@*", "@types/qs@6.9.7":
|
||||
version "6.9.7"
|
||||
@ -1881,11 +1889,9 @@ camelcase@^6.2.0:
|
||||
integrity sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==
|
||||
|
||||
caniuse-lite@^1.0.30001259:
|
||||
version "1.0.30001260"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001260.tgz#e3be3f34ddad735ca4a2736fa9e768ef34316270"
|
||||
integrity sha512-Fhjc/k8725ItmrvW5QomzxLeojewxvqiYCKeFcfFEhut28IVLdpHU19dneOmltZQIE5HNbawj1HYD+1f2bM1Dg==
|
||||
dependencies:
|
||||
nanocolors "^0.1.0"
|
||||
version "1.0.30001261"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001261.tgz#96d89813c076ea061209a4e040d8dcf0c66a1d01"
|
||||
integrity sha512-vM8D9Uvp7bHIN0fZ2KQ4wnmYFpJo/Etb4Vwsuc+ka0tfGDHvOPrFm6S/7CCNLSOkAUjenT2HnUPESdOIL91FaA==
|
||||
|
||||
chalk@^2.0.0:
|
||||
version "2.4.2"
|
||||
@ -2088,11 +2094,6 @@ cssstyle@^2.3.0:
|
||||
dependencies:
|
||||
cssom "~0.3.6"
|
||||
|
||||
data-uri-to-buffer@^3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-3.0.1.tgz#594b8973938c5bc2c33046535785341abc4f3636"
|
||||
integrity sha512-WboRycPNsVw3B3TL559F7kuBUM4d8CgMEvk6xEJlOp7OBPjt6G7z8WMWlD2rOFZLk6OYfFIUGsCOWzcQH9K2og==
|
||||
|
||||
data-urls@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/data-urls/-/data-urls-2.0.0.tgz#156485a72963a970f5d5821aaf642bef2bf2db9b"
|
||||
@ -2207,9 +2208,9 @@ ee-first@1.1.1:
|
||||
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
|
||||
|
||||
electron-to-chromium@^1.3.846:
|
||||
version "1.3.850"
|
||||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.850.tgz#c56c72abfeab051b4b328beb894461c5912d0456"
|
||||
integrity sha512-ZzkDcdzePeF4dhoGZQT77V2CyJOpwfTZEOg4h0x6R/jQhGt/rIRpbRyVreWLtD7B/WsVxo91URm2WxMKR9JQZA==
|
||||
version "1.3.851"
|
||||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.851.tgz#457846fce94d5de25511570435a94f1a622203ac"
|
||||
integrity sha512-Ak970eGtRSoHTaJkoDjdkeXYetbwm5Bl9pN/nPOQ3QzLfw1EWRjReOlWUra6o58SVgxfpwOT9U2P1BUXoJ57dw==
|
||||
|
||||
emittery@^0.8.1:
|
||||
version "0.8.1"
|
||||
@ -2568,13 +2569,6 @@ fd-slicer@~1.1.0:
|
||||
dependencies:
|
||||
pend "~1.2.0"
|
||||
|
||||
fetch-blob@^3.1.2:
|
||||
version "3.1.2"
|
||||
resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.1.2.tgz#6bc438675f3851ecea51758ac91f6a1cd1bacabd"
|
||||
integrity sha512-hunJbvy/6OLjCD0uuhLdp0mMPzP/yd2ssd1t2FCJsaA7wkWhpbp9xfuNVpv7Ll4jFhzp6T4LAupSiV9uOeg0VQ==
|
||||
dependencies:
|
||||
web-streams-polyfill "^3.0.3"
|
||||
|
||||
file-entry-cache@^6.0.1:
|
||||
version "6.0.1"
|
||||
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027"
|
||||
@ -2632,19 +2626,19 @@ flatted@^3.1.0:
|
||||
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.2.tgz#64bfed5cb68fe3ca78b3eb214ad97b63bedce561"
|
||||
integrity sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA==
|
||||
|
||||
form-data@4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
|
||||
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
|
||||
form-data@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
|
||||
integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
|
||||
dependencies:
|
||||
asynckit "^0.4.0"
|
||||
combined-stream "^1.0.8"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
form-data@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
|
||||
integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
|
||||
form-data@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
|
||||
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
|
||||
dependencies:
|
||||
asynckit "^0.4.0"
|
||||
combined-stream "^1.0.8"
|
||||
@ -2961,9 +2955,9 @@ is-ci@^3.0.0:
|
||||
ci-info "^3.1.1"
|
||||
|
||||
is-core-module@^2.2.0:
|
||||
version "2.6.0"
|
||||
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.6.0.tgz#d7553b2526fe59b92ba3e40c8df757ec8a709e19"
|
||||
integrity sha512-wShG8vs60jKfPWpF2KZRaAtvt3a20OAn7+IJ6hLPECpSABLcKtFKTTI4ZtH5QcBruBHlq+WsdHWyz0BCZW7svQ==
|
||||
version "2.7.0"
|
||||
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.7.0.tgz#3c0ef7d31b4acfc574f80c58409d568a836848e3"
|
||||
integrity sha512-ByY+tjCciCr+9nLryBYcSD50EOGWt95c7tIsKTG1J2ixKKXPvF7Ej3AVd+UfDydAJom3biBGDBALaO79ktwgEQ==
|
||||
dependencies:
|
||||
has "^1.0.3"
|
||||
|
||||
@ -3774,7 +3768,7 @@ ms@2.1.2:
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
||||
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
|
||||
|
||||
nanocolors@^0.1.0, nanocolors@^0.1.5:
|
||||
nanocolors@^0.1.5:
|
||||
version "0.1.12"
|
||||
resolved "https://registry.yarnpkg.com/nanocolors/-/nanocolors-0.1.12.tgz#8577482c58cbd7b5bb1681db4cf48f11a87fd5f6"
|
||||
integrity sha512-2nMHqg1x5PU+unxX7PGY7AuYxl2qDx7PSrTRjizr8sxdd3l/3hBuWWaki62qmtYm2U5i4Z5E7GbjlyDFhs9/EQ==
|
||||
@ -3799,15 +3793,7 @@ node-fetch@2.6.1:
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
||||
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||
|
||||
node-fetch@3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.0.0.tgz#79da7146a520036f2c5f644e4a26095f17e411ea"
|
||||
integrity sha512-bKMI+C7/T/SPU1lKnbQbwxptpCrG9ashG+VkytmXCPZyuM9jB6VU+hY0oi4lC8LxTtAeWdckNCTa3nrGsAdA3Q==
|
||||
dependencies:
|
||||
data-uri-to-buffer "^3.0.1"
|
||||
fetch-blob "^3.1.2"
|
||||
|
||||
node-fetch@^2.6.1:
|
||||
node-fetch@^2.6.1, node-fetch@^2.6.5:
|
||||
version "2.6.5"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.5.tgz#42735537d7f080a7e5f78b6c549b7146be1742fd"
|
||||
integrity sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==
|
||||
@ -4891,11 +4877,6 @@ walker@^1.0.7:
|
||||
dependencies:
|
||||
makeerror "1.0.x"
|
||||
|
||||
web-streams-polyfill@^3.0.3:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.1.1.tgz#1516f2d4ea8f1bdbfed15eb65cb2df87098c8364"
|
||||
integrity sha512-Czi3fG883e96T4DLEPRvufrF2ydhOOW1+1a6c3gNjH2aIh50DNFBdfwh2AKoOf1rXvpvavAoA11Qdq9+BKjE0Q==
|
||||
|
||||
webidl-conversions@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user