Skip to content

Commit f098b10

Browse files
authored
Fixes #25172: [typescript-fetch] support isolated declaration emission (#25277)
* [typescript-fetch] Add explicit runtime types for isolated declarations * [typescript-fetch] Add isolated declaration regression tests to npm test
1 parent af68e11 commit f098b10

32 files changed

Lines changed: 304 additions & 207 deletions

File tree

‎modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable */
33
{{>licenseInfo}}
44

5-
export const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");
5+
export const BASE_PATH: string = "{{{basePath}}}".replace(/\/+$/, "");
66

77
export interface ConfigurationParameters {
88
basePath?: string; // override base path
@@ -73,7 +73,7 @@ export class Configuration {
7373
}
7474
}
7575

76-
export const DefaultConfig = new Configuration();
76+
export const DefaultConfig: Configuration = new Configuration();
7777

7878
/**
7979
* This is the base class for all generated API classes.
@@ -83,22 +83,22 @@ export class BaseAPI {
8383
private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
8484
private middleware: Middleware[];
8585
86-
constructor(protected configuration = DefaultConfig) {
86+
constructor(protected configuration: Configuration = DefaultConfig) {
8787
this.middleware = configuration.middleware;
8888
}
8989

90-
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
90+
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]): T {
9191
const next = this.clone<T>();
9292
next.middleware = next.middleware.concat(...middlewares);
9393
return next;
9494
}
9595

96-
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
96+
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>): T {
9797
const middlewares = preMiddlewares.map((pre) => ({ pre }));
9898
return this.withMiddleware<T>(...middlewares);
9999
}
100100

101-
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
101+
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>): T {
102102
const middlewares = postMiddlewares.map((post) => ({ post }));
103103
return this.withMiddleware<T>(...middlewares);
104104
}
@@ -369,7 +369,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef
369369
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
370370
}
371371

372-
export function exists(json: any, key: string) {
372+
export function exists(json: any, key: string): boolean {
373373
const value = json[key];
374374
return value !== null && value !== undefined;
375375
}
@@ -453,7 +453,7 @@ export function parseDateTime(value: any): Date {
453453
{{/isDateLibraryTemporal}}
454454

455455
{{#modelSerializersEnabled}}
456-
export function mapValues(data: any, fn: (item: any) => any) {
456+
export function mapValues(data: any, fn: (item: any) => any): { [key: string]: any } {
457457
const result: { [key: string]: any } = {};
458458
for (const key of Object.keys(data)) {
459459
result[key] = fn(data[key]);

‎samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Do not edit the class manually.
1313
*/
1414

15-
export const BASE_PATH = "http://localhost:8080".replace(/\/+$/, "");
15+
export const BASE_PATH: string = "http://localhost:8080".replace(/\/+$/, "");
1616

1717
export interface ConfigurationParameters {
1818
basePath?: string; // override base path
@@ -83,7 +83,7 @@ export class Configuration {
8383
}
8484
}
8585

86-
export const DefaultConfig = new Configuration();
86+
export const DefaultConfig: Configuration = new Configuration();
8787

8888
/**
8989
* This is the base class for all generated API classes.
@@ -93,22 +93,22 @@ export class BaseAPI {
9393
private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
9494
private middleware: Middleware[];
9595

96-
constructor(protected configuration = DefaultConfig) {
96+
constructor(protected configuration: Configuration = DefaultConfig) {
9797
this.middleware = configuration.middleware;
9898
}
9999

100-
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
100+
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]): T {
101101
const next = this.clone<T>();
102102
next.middleware = next.middleware.concat(...middlewares);
103103
return next;
104104
}
105105

106-
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
106+
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>): T {
107107
const middlewares = preMiddlewares.map((pre) => ({ pre }));
108108
return this.withMiddleware<T>(...middlewares);
109109
}
110110

111-
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
111+
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>): T {
112112
const middlewares = postMiddlewares.map((post) => ({ post }));
113113
return this.withMiddleware<T>(...middlewares);
114114
}
@@ -354,7 +354,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef
354354
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
355355
}
356356

357-
export function exists(json: any, key: string) {
357+
export function exists(json: any, key: string): boolean {
358358
const value = json[key];
359359
return value !== null && value !== undefined;
360360
}
@@ -410,7 +410,7 @@ export function parseDateTime(value: any): Date {
410410
return new Date(value);
411411
}
412412

413-
export function mapValues(data: any, fn: (item: any) => any) {
413+
export function mapValues(data: any, fn: (item: any) => any): { [key: string]: any } {
414414
const result: { [key: string]: any } = {};
415415
for (const key of Object.keys(data)) {
416416
result[key] = fn(data[key]);

‎samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Do not edit the class manually.
1313
*/
1414

15-
export const BASE_PATH = "http://localhost:8080".replace(/\/+$/, "");
15+
export const BASE_PATH: string = "http://localhost:8080".replace(/\/+$/, "");
1616

1717
export interface ConfigurationParameters {
1818
basePath?: string; // override base path
@@ -83,7 +83,7 @@ export class Configuration {
8383
}
8484
}
8585

86-
export const DefaultConfig = new Configuration();
86+
export const DefaultConfig: Configuration = new Configuration();
8787

8888
/**
8989
* This is the base class for all generated API classes.
@@ -93,22 +93,22 @@ export class BaseAPI {
9393
private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
9494
private middleware: Middleware[];
9595

96-
constructor(protected configuration = DefaultConfig) {
96+
constructor(protected configuration: Configuration = DefaultConfig) {
9797
this.middleware = configuration.middleware;
9898
}
9999

100-
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
100+
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]): T {
101101
const next = this.clone<T>();
102102
next.middleware = next.middleware.concat(...middlewares);
103103
return next;
104104
}
105105

106-
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
106+
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>): T {
107107
const middlewares = preMiddlewares.map((pre) => ({ pre }));
108108
return this.withMiddleware<T>(...middlewares);
109109
}
110110

111-
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
111+
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>): T {
112112
const middlewares = postMiddlewares.map((post) => ({ post }));
113113
return this.withMiddleware<T>(...middlewares);
114114
}
@@ -354,7 +354,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef
354354
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
355355
}
356356

357-
export function exists(json: any, key: string) {
357+
export function exists(json: any, key: string): boolean {
358358
const value = json[key];
359359
return value !== null && value !== undefined;
360360
}
@@ -410,7 +410,7 @@ export function parseDateTime(value: any): Date {
410410
return new Date(value);
411411
}
412412

413-
export function mapValues(data: any, fn: (item: any) => any) {
413+
export function mapValues(data: any, fn: (item: any) => any): { [key: string]: any } {
414414
const result: { [key: string]: any } = {};
415415
for (const key of Object.keys(data)) {
416416
result[key] = fn(data[key]);

‎samples/client/others/typescript-fetch/multipart-file-array/runtime.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Do not edit the class manually.
1313
*/
1414

15-
export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
15+
export const BASE_PATH: string = "http://localhost".replace(/\/+$/, "");
1616

1717
export interface ConfigurationParameters {
1818
basePath?: string; // override base path
@@ -83,7 +83,7 @@ export class Configuration {
8383
}
8484
}
8585

86-
export const DefaultConfig = new Configuration();
86+
export const DefaultConfig: Configuration = new Configuration();
8787

8888
/**
8989
* This is the base class for all generated API classes.
@@ -93,22 +93,22 @@ export class BaseAPI {
9393
private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
9494
private middleware: Middleware[];
9595

96-
constructor(protected configuration = DefaultConfig) {
96+
constructor(protected configuration: Configuration = DefaultConfig) {
9797
this.middleware = configuration.middleware;
9898
}
9999

100-
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
100+
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]): T {
101101
const next = this.clone<T>();
102102
next.middleware = next.middleware.concat(...middlewares);
103103
return next;
104104
}
105105

106-
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
106+
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>): T {
107107
const middlewares = preMiddlewares.map((pre) => ({ pre }));
108108
return this.withMiddleware<T>(...middlewares);
109109
}
110110

111-
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
111+
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>): T {
112112
const middlewares = postMiddlewares.map((post) => ({ post }));
113113
return this.withMiddleware<T>(...middlewares);
114114
}
@@ -354,7 +354,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef
354354
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
355355
}
356356

357-
export function exists(json: any, key: string) {
357+
export function exists(json: any, key: string): boolean {
358358
const value = json[key];
359359
return value !== null && value !== undefined;
360360
}
@@ -410,7 +410,7 @@ export function parseDateTime(value: any): Date {
410410
return new Date(value);
411411
}
412412

413-
export function mapValues(data: any, fn: (item: any) => any) {
413+
export function mapValues(data: any, fn: (item: any) => any): { [key: string]: any } {
414414
const result: { [key: string]: any } = {};
415415
for (const key of Object.keys(data)) {
416416
result[key] = fn(data[key]);

‎samples/client/others/typescript-fetch/self-import-issue/runtime.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Do not edit the class manually.
1313
*/
1414

15-
export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
15+
export const BASE_PATH: string = "http://localhost".replace(/\/+$/, "");
1616

1717
export interface ConfigurationParameters {
1818
basePath?: string; // override base path
@@ -83,7 +83,7 @@ export class Configuration {
8383
}
8484
}
8585

86-
export const DefaultConfig = new Configuration();
86+
export const DefaultConfig: Configuration = new Configuration();
8787

8888
/**
8989
* This is the base class for all generated API classes.
@@ -93,22 +93,22 @@ export class BaseAPI {
9393
private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
9494
private middleware: Middleware[];
9595

96-
constructor(protected configuration = DefaultConfig) {
96+
constructor(protected configuration: Configuration = DefaultConfig) {
9797
this.middleware = configuration.middleware;
9898
}
9999

100-
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
100+
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]): T {
101101
const next = this.clone<T>();
102102
next.middleware = next.middleware.concat(...middlewares);
103103
return next;
104104
}
105105

106-
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
106+
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>): T {
107107
const middlewares = preMiddlewares.map((pre) => ({ pre }));
108108
return this.withMiddleware<T>(...middlewares);
109109
}
110110

111-
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
111+
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>): T {
112112
const middlewares = postMiddlewares.map((post) => ({ post }));
113113
return this.withMiddleware<T>(...middlewares);
114114
}
@@ -354,7 +354,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef
354354
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
355355
}
356356

357-
export function exists(json: any, key: string) {
357+
export function exists(json: any, key: string): boolean {
358358
const value = json[key];
359359
return value !== null && value !== undefined;
360360
}
@@ -410,7 +410,7 @@ export function parseDateTime(value: any): Date {
410410
return new Date(value);
411411
}
412412

413-
export function mapValues(data: any, fn: (item: any) => any) {
413+
export function mapValues(data: any, fn: (item: any) => any): { [key: string]: any } {
414414
const result: { [key: string]: any } = {};
415415
for (const key of Object.keys(data)) {
416416
result[key] = fn(data[key]);

‎samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Do not edit the class manually.
1313
*/
1414

15-
export const BASE_PATH = "http://api.example.xyz/v1".replace(/\/+$/, "");
15+
export const BASE_PATH: string = "http://api.example.xyz/v1".replace(/\/+$/, "");
1616

1717
export interface ConfigurationParameters {
1818
basePath?: string; // override base path
@@ -83,7 +83,7 @@ export class Configuration {
8383
}
8484
}
8585

86-
export const DefaultConfig = new Configuration();
86+
export const DefaultConfig: Configuration = new Configuration();
8787

8888
/**
8989
* This is the base class for all generated API classes.
@@ -93,22 +93,22 @@ export class BaseAPI {
9393
private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i;
9494
private middleware: Middleware[];
9595

96-
constructor(protected configuration = DefaultConfig) {
96+
constructor(protected configuration: Configuration = DefaultConfig) {
9797
this.middleware = configuration.middleware;
9898
}
9999

100-
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
100+
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]): T {
101101
const next = this.clone<T>();
102102
next.middleware = next.middleware.concat(...middlewares);
103103
return next;
104104
}
105105

106-
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
106+
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>): T {
107107
const middlewares = preMiddlewares.map((pre) => ({ pre }));
108108
return this.withMiddleware<T>(...middlewares);
109109
}
110110

111-
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
111+
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>): T {
112112
const middlewares = postMiddlewares.map((post) => ({ post }));
113113
return this.withMiddleware<T>(...middlewares);
114114
}
@@ -354,7 +354,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef
354354
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
355355
}
356356

357-
export function exists(json: any, key: string) {
357+
export function exists(json: any, key: string): boolean {
358358
const value = json[key];
359359
return value !== null && value !== undefined;
360360
}
@@ -410,7 +410,7 @@ export function parseDateTime(value: any): Date {
410410
return new Date(value);
411411
}
412412

413-
export function mapValues(data: any, fn: (item: any) => any) {
413+
export function mapValues(data: any, fn: (item: any) => any): { [key: string]: any } {
414414
const result: { [key: string]: any } = {};
415415
for (const key of Object.keys(data)) {
416416
result[key] = fn(data[key]);

0 commit comments

Comments
 (0)