From b2bd76d6125df964f8e23935792ce46cede802ca Mon Sep 17 00:00:00 2001 From: Matthijs van Henten <440737+mvhenten@users.noreply.github.com> Date: Mon, 3 Aug 2026 15:38:25 +0200 Subject: [PATCH] fix(typescript-fetch): emit erasable syntax in runtime template Replace constructor parameter properties in runtime.mustache with explicit field declarations and constructor assignments, and declare FetchError.cause through an interface so it needs no override modifier. fixes #22400 fixes #14515 --- .../typescript-fetch/runtime.mustache | 53 +++++++++++++++---- .../runtime.ts | 53 +++++++++++++++---- .../infinite-recursion-issue/runtime.ts | 53 +++++++++++++++---- .../multipart-file-array/runtime.ts | 53 +++++++++++++++---- .../self-import-issue/runtime.ts | 53 +++++++++++++++---- .../builds/allOf-nullable/runtime.ts | 53 +++++++++++++++---- .../builds/allOf-readonly/runtime.ts | 53 +++++++++++++++---- .../builds/default-v3.0/runtime.ts | 53 +++++++++++++++---- .../builds/default/runtime.ts | 53 +++++++++++++++---- .../typescript-fetch/builds/enum/runtime.ts | 53 +++++++++++++++---- .../builds/es6-target/src/runtime.ts | 53 +++++++++++++++---- .../builds/kebab-case/runtime.ts | 53 +++++++++++++++---- .../builds/multiple-parameters/runtime.ts | 53 +++++++++++++++---- .../typescript-fetch/builds/oneOf/runtime.ts | 53 +++++++++++++++---- .../src/runtime.ts | 53 +++++++++++++++---- .../builds/sagas-and-records/src/runtime.ts | 53 +++++++++++++++---- .../builds/snakecase-discriminator/runtime.ts | 53 +++++++++++++++---- .../builds/validation-attributes/runtime.ts | 53 +++++++++++++++---- .../builds/with-interfaces/runtime.ts | 53 +++++++++++++++---- .../builds/with-npm-version/src/runtime.ts | 53 +++++++++++++++---- .../builds/with-string-enums/runtime.ts | 53 +++++++++++++++---- .../without-runtime-checks/src/runtime.ts | 53 +++++++++++++++---- 22 files changed, 968 insertions(+), 198 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache index 235458a2df2f..63546417014e 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache @@ -18,7 +18,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -82,8 +86,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -248,8 +254,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -259,10 +267,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -274,8 +289,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -414,7 +431,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -422,7 +445,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -430,7 +457,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -438,7 +469,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts b/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts index cc66cbfbb3af..4222faa85838 100644 --- a/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts +++ b/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts b/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts index cc66cbfbb3af..4222faa85838 100644 --- a/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts +++ b/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts b/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts index a49c6563b888..255e5d8c577a 100644 --- a/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts +++ b/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/others/typescript-fetch/self-import-issue/runtime.ts b/samples/client/others/typescript-fetch/self-import-issue/runtime.ts index 8aa237368f4f..cbde4458d1f1 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/runtime.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts index a9a8ee84339c..3a983be816e3 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts index a9a8ee84339c..3a983be816e3 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts index e52a36947b03..24431db21777 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts index 3389e4beb1cc..cb8aec2230cb 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts index 2d2f267ce4a8..21a0212700f8 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts index 3389e4beb1cc..cb8aec2230cb 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts index e52a36947b03..24431db21777 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts index 3389e4beb1cc..cb8aec2230cb 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts index 8c8a505df958..fbdf395d2acc 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts index 3389e4beb1cc..cb8aec2230cb 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts index 3389e4beb1cc..cb8aec2230cb 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts index e52a36947b03..24431db21777 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts index 3389e4beb1cc..cb8aec2230cb 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts index 3389e4beb1cc..cb8aec2230cb 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts index 3389e4beb1cc..cb8aec2230cb 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts index 2d2f267ce4a8..21a0212700f8 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -422,7 +439,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -430,7 +453,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -438,7 +465,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -446,7 +477,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text(); diff --git a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts index 45dfc650f077..d1fd8a87f44f 100644 --- a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts @@ -28,7 +28,11 @@ export interface ConfigurationParameters { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + private configuration: ConfigurationParameters; + + constructor(configuration: ConfigurationParameters = {}) { + this.configuration = configuration; + } set config(configuration: Configuration) { this.configuration = configuration; @@ -92,8 +96,10 @@ export class BaseAPI { private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; private middleware: Middleware[]; + protected configuration: Configuration; - constructor(protected configuration = DefaultConfig) { + constructor(configuration: Configuration = DefaultConfig) { + this.configuration = configuration; this.middleware = configuration.middleware; } @@ -258,8 +264,10 @@ function isFormData(value: any): value is FormData { export class ResponseError extends Error { override name: "ResponseError" = "ResponseError"; - constructor(public response: Response, msg?: string) { + response: Response; + constructor(response: Response, msg?: string) { super(msg); + this.response = response; // restore prototype chain const actualProto = new.target.prototype; @@ -269,10 +277,17 @@ export class ResponseError extends Error { } } +// `cause` is declared through an interface so that it stays compatible with lib targets +// that already declare `Error.cause` (ES2022+) as well as the ones that do not +export interface FetchError { + cause: Error; +} + export class FetchError extends Error { override name: "FetchError" = "FetchError"; - constructor(public cause: Error, msg?: string) { + constructor(cause: Error, msg?: string) { super(msg); + this.cause = cause; // restore prototype chain const actualProto = new.target.prototype; @@ -284,8 +299,10 @@ export class FetchError extends Error { export class RequiredError extends Error { override name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { + field: string; + constructor(field: string, msg?: string) { super(msg); + this.field = field; // restore prototype chain const actualProto = new.target.prototype; @@ -410,7 +427,13 @@ export interface ResponseTransformer { } export class JSONApiResponse { - constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + raw: Response; + private transformer: ResponseTransformer; + + constructor(raw: Response, transformer: ResponseTransformer = (jsonValue: any) => jsonValue) { + this.raw = raw; + this.transformer = transformer; + } async value(): Promise { return this.transformer(await this.raw.json()); @@ -418,7 +441,11 @@ export class JSONApiResponse { } export class VoidApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return undefined; @@ -426,7 +453,11 @@ export class VoidApiResponse { } export class BlobApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.blob(); @@ -434,7 +465,11 @@ export class BlobApiResponse { } export class TextApiResponse { - constructor(public raw: Response) {} + raw: Response; + + constructor(raw: Response) { + this.raw = raw; + } async value(): Promise { return await this.raw.text();