mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 08:22:45 +00:00
style(typescript): use Headers type (#19697)
This commit is contained in:
@@ -63,6 +63,8 @@ export class HttpException extends Error {
|
||||
*/
|
||||
export type RequestBody = undefined | string | FormData | URLSearchParams;
|
||||
|
||||
type Headers = Record<string, string>;
|
||||
|
||||
function ensureAbsoluteUrl(url: string) {
|
||||
if (url.startsWith("http://") || url.startsWith("https://")) {
|
||||
return url;
|
||||
@@ -81,7 +83,7 @@ function ensureAbsoluteUrl(url: string) {
|
||||
* Represents an HTTP request context
|
||||
*/
|
||||
export class RequestContext {
|
||||
private headers: { [key: string]: string } = {};
|
||||
private headers: Headers = {};
|
||||
private body: RequestBody = undefined;
|
||||
private url: URL;
|
||||
{{#platforms}}
|
||||
@@ -135,7 +137,7 @@ export class RequestContext {
|
||||
return this.httpMethod;
|
||||
}
|
||||
|
||||
public getHeaders(): { [key: string]: string } {
|
||||
public getHeaders(): Headers {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
@@ -224,7 +226,7 @@ export class SelfDecodingBody implements ResponseBody {
|
||||
export class ResponseContext {
|
||||
public constructor(
|
||||
public httpStatusCode: number,
|
||||
public headers: { [key: string]: string },
|
||||
public headers: Headers,
|
||||
public body: ResponseBody
|
||||
) {}
|
||||
|
||||
@@ -235,8 +237,8 @@ export class ResponseContext {
|
||||
* Parameter names are converted to lower case
|
||||
* The first parameter is returned with the key `""`
|
||||
*/
|
||||
public getParsedHeader(headerName: string): { [parameter: string]: string } {
|
||||
const result: { [parameter: string]: string } = {};
|
||||
public getParsedHeader(headerName: string): Headers {
|
||||
const result: Headers = {};
|
||||
if (!this.headers[headerName]) {
|
||||
return result;
|
||||
}
|
||||
@@ -316,7 +318,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
|
||||
export class HttpInfo<T> extends ResponseContext {
|
||||
public constructor(
|
||||
public httpStatusCode: number,
|
||||
public headers: { [key: string]: string },
|
||||
public headers: Headers,
|
||||
public body: ResponseBody,
|
||||
public data: T,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user