Skip to content

Commit a5951db

Browse files
committed
migrate typescript generator to undici
1 parent 8a4246c commit a5951db

7 files changed

Lines changed: 88 additions & 130 deletions

File tree

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

Lines changed: 7 additions & 9 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

@@ -182,7 +181,7 @@ export class RequestContext {
182181
this.headers["Cookie"] += name + "=" + value + "; ";
183182
}
184183

185-
public setHeaderParam(key: string, value: string): void {
184+
public setHeaderParam(key: string, value: string): void {
186185
this.headers[key] = value;
187186
}
188187

@@ -196,13 +195,12 @@ export class RequestContext {
196195

197196
{{#platforms}}
198197
{{#node}}
199-
200-
public setAgent(agent: http.Agent | https.Agent) {
201-
this.agent = agent;
198+
public setDispatcher(dispatcher: Dispatcher): void {
199+
this.dispatcher = dispatcher;
202200
}
203201

204-
public getAgent(): http.Agent | https.Agent | undefined {
205-
return this.agent;
202+
public getDispatcher(): Dispatcher | undefined {
203+
return this.dispatcher;
206204
}
207205
{{/node}}
208206
{{/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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
{{#fetch-api}}
4747
{{#platforms}}
4848
{{#node}}
49-
"node-fetch": "^2.7.0",
50-
"@types/node-fetch": "^2.6.13",
49+
"undici": "^7.16.0"
5150
{{/node}}
5251
{{#browser}}
5352
"whatwg-fetch": "^3.0.0",
@@ -61,7 +60,7 @@
6160
{{/frameworks}}
6261
{{#platforms}}
6362
{{#node}}
64-
"@types/node": "^16.18.126",
63+
"@types/node": "^20.17.10",
6564
"form-data": "^4.0.4",
6665
{{/node}}
6766
{{/platforms}}

samples/openapi3/client/petstore/typescript/builds/default/http/http.ts

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

samples/openapi3/client/petstore/typescript/builds/default/http/isomorphic-fetch.ts

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

samples/openapi3/client/petstore/typescript/builds/default/package-lock.json

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

0 commit comments

Comments
 (0)