Skip to content

Commit 36367e7

Browse files
authored
style(typescript): use Headers type (#19697)
1 parent 5e2af72 commit 36367e7

File tree

14 files changed

+112
-84
lines changed

14 files changed

+112
-84
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export class HttpException extends Error {
6363
*/
6464
export type RequestBody = undefined | string | FormData | URLSearchParams;
6565

66+
type Headers = Record<string, string>;
67+
6668
function ensureAbsoluteUrl(url: string) {
6769
if (url.startsWith("http://") || url.startsWith("https://")) {
6870
return url;
@@ -81,7 +83,7 @@ function ensureAbsoluteUrl(url: string) {
8183
* Represents an HTTP request context
8284
*/
8385
export class RequestContext {
84-
private headers: { [key: string]: string } = {};
86+
private headers: Headers = {};
8587
private body: RequestBody = undefined;
8688
private url: URL;
8789
{{#platforms}}
@@ -135,7 +137,7 @@ export class RequestContext {
135137
return this.httpMethod;
136138
}
137139

138-
public getHeaders(): { [key: string]: string } {
140+
public getHeaders(): Headers {
139141
return this.headers;
140142
}
141143

@@ -224,7 +226,7 @@ export class SelfDecodingBody implements ResponseBody {
224226
export class ResponseContext {
225227
public constructor(
226228
public httpStatusCode: number,
227-
public headers: { [key: string]: string },
229+
public headers: Headers,
228230
public body: ResponseBody
229231
) {}
230232

@@ -235,8 +237,8 @@ export class ResponseContext {
235237
* Parameter names are converted to lower case
236238
* The first parameter is returned with the key `""`
237239
*/
238-
public getParsedHeader(headerName: string): { [parameter: string]: string } {
239-
const result: { [parameter: string]: string } = {};
240+
public getParsedHeader(headerName: string): Headers {
241+
const result: Headers = {};
240242
if (!this.headers[headerName]) {
241243
return result;
242244
}
@@ -316,7 +318,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
316318
export class HttpInfo<T> extends ResponseContext {
317319
public constructor(
318320
public httpStatusCode: number,
319-
public headers: { [key: string]: string },
321+
public headers: Headers,
320322
public body: ResponseBody,
321323
public data: T,
322324
) {

samples/client/others/typescript/builds/array-of-lists/http/http.ts

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

samples/client/others/typescript/builds/with-unique-items/http/http.ts

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

samples/client/others/typescript/encode-decode/build/http/http.ts

Lines changed: 8 additions & 6 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/browser/http/http.ts

Lines changed: 8 additions & 6 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/composed-schemas/http/http.ts

Lines changed: 8 additions & 6 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/http.ts

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

0 commit comments

Comments
 (0)