Skip to content

Commit 08858a9

Browse files
authored
[typescript] migrate node-fetch to undici (#22408)
* migrate typescript generator to undici * smaples * missing comma * upgrade types in encode test * remove EOL node versions, add new LTS * fix export issue in encode/decode * d.js issue and commonjs module in tsconfig for esm dual support * update samples merge master * sync samples * files samples
1 parent e9c842f commit 08858a9

File tree

50 files changed

+398
-321
lines changed

Some content is hidden

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

50 files changed

+398
-321
lines changed

.github/workflows/samples-typescript-encode-decode.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
# clients
1717
- samples/client/others/typescript/encode-decode/test
1818
node-version:
19-
- 16
20-
- 18
2119
- 20
20+
- 22
21+
- 24
2222
steps:
2323
- uses: actions/checkout@v5
2424

modules/openapi-generator/src/main/resources/typescript/http/http.mustache

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// TODO: evaluate if we can easily get rid of this library
44
import {{^supportsES6}}* as{{/supportsES6}} FormData from "form-data";
55
import { URL, URLSearchParams } from 'url';
6-
import * as http from 'http';
7-
import * as https from 'https';
6+
import { type Dispatcher } from 'undici';
87
{{/node}}
98
{{/platforms}}
109
import { Observable, from } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub{{importFileExtension}}'{{/useRxJS}};
@@ -106,7 +105,7 @@ export class RequestContext {
106105
private signal: AbortSignal | undefined = undefined;
107106
{{#platforms}}
108107
{{#node}}
109-
private agent: http.Agent | https.Agent | undefined = undefined;
108+
private dispatcher: Dispatcher | undefined = undefined;
110109
{{/node}}
111110
{{/platforms}}
112111

@@ -203,13 +202,12 @@ export class RequestContext {
203202

204203
{{#platforms}}
205204
{{#node}}
206-
207-
public setAgent(agent: http.Agent | https.Agent) {
208-
this.agent = agent;
205+
public setDispatcher(dispatcher: Dispatcher): void {
206+
this.dispatcher = dispatcher;
209207
}
210208

211-
public getAgent(): http.Agent | https.Agent | undefined {
212-
return this.agent;
209+
public getDispatcher(): Dispatcher | undefined {
210+
return this.dispatcher;
213211
}
214212
{{/node}}
215213
{{/platforms}}

modules/openapi-generator/src/main/resources/typescript/http/isomorphic-fetch.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {HttpLibrary, RequestContext, ResponseContext} from './http{{importFileEx
22
import { from, Observable } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub{{importFileExtension}}'{{/useRxJS}};
33
{{#platforms}}
44
{{#node}}
5-
import fetch from "node-fetch";
5+
import { fetch } from 'undici';
66
{{/node}}
77
{{#browser}}
88
import "whatwg-fetch";
@@ -22,7 +22,7 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
2222
signal: request.getSignal(),
2323
{{#platforms}}
2424
{{#node}}
25-
agent: request.getAgent(),
25+
dispatcher: request.getDispatcher(),
2626
{{/node}}
2727
{{#browser}}
2828
credentials: "same-origin"

modules/openapi-generator/src/main/resources/typescript/package.mustache

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
{{/supportsES6}}
2525
"exports": {
2626
".": {
27-
{{#supportsES6}}
2827
"import": "./dist/index.js",
29-
{{/supportsES6}}
3028
{{^supportsES6}}
3129
"require": "./dist/index.js",
3230
{{/supportsES6}}
33-
"types": "./dist/index.d.js"
31+
"types": "./dist/index.d.ts"
3432
}
3533
},
3634
"files": [
@@ -46,8 +44,7 @@
4644
{{#fetch-api}}
4745
{{#platforms}}
4846
{{#node}}
49-
"node-fetch": "^2.7.0",
50-
"@types/node-fetch": "^2.6.13",
47+
"undici": "^7.16.0",
5148
{{/node}}
5249
{{#browser}}
5350
"whatwg-fetch": "^3.0.0",
@@ -61,7 +58,7 @@
6158
{{/frameworks}}
6259
{{#platforms}}
6360
{{#node}}
64-
"@types/node": "^16.18.126",
61+
"@types/node": "^20.17.10",
6562
"form-data": "^4.0.4",
6663
{{/node}}
6764
{{/platforms}}

modules/openapi-generator/src/main/resources/typescript/tsconfig.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{{/supportsES6}}
99
{{^supportsES6}}
1010
"target": "es5",
11+
"module": "commonjs",
1112
{{/supportsES6}}
1213
"moduleResolution": "node",
1314
"declaration": true,

samples/client/echo_api/typescript/build/http/http.ts

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/echo_api/typescript/build/http/isomorphic-fetch.ts

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/echo_api/typescript/build/package.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/echo_api/typescript/build/tsconfig.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/client/others/typescript/builds/array-of-lists/package.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)