Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface ConfigurationParameters {
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
credentials?: FetchCredentials; //value for the credentials param we want to use on each request
}

export class Configuration {
Expand Down Expand Up @@ -77,7 +77,7 @@ export class Configuration {
return this.configuration.headers;
}

get credentials(): RequestCredentials | undefined {
get credentials(): FetchCredentials | undefined {
return this.configuration.credentials;
}
}
Expand Down Expand Up @@ -301,7 +301,11 @@ export const COLLECTION_FORMATS = {
pipes: "|",
};

export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
// Node's fetch types declare RequestInit, URL and Request but not the DOM fetch global.
// FetchAPI is a method type, so a fetch that takes only a string URL or a required
// init still fits, as it did with typeof fetch.
export type FetchCredentials = NonNullable<RequestInit['credentials']>;
export type FetchAPI = { fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> }['fetch'];

{{#splitOperationsByContentType}}
type AllKeys<T> = T extends unknown ? keyof T : never;
Expand All @@ -323,7 +327,7 @@ export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'
export type HTTPHeaders = { [key: string]: string };
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
export type HTTPBody = Json | FormData | URLSearchParams;
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: FetchCredentials; body?: HTTPBody };
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';

export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,44 @@ public void testExplodedObjectQueryParameter() throws IOException {
TestUtils.assertFileNotContains(api, "Object.keys(requestParameters['flatFilter'])");
}

@Test(description = "Generated runtime.ts declares fetch types without DOM-only names")
public void testRuntimeDeclaresFetchTypesWithoutDomNames() throws IOException {
Path spec = Files.createTempFile("typescript-fetch-node-fetch", ".json");
spec.toFile().deleteOnExit();
// Same minimal document as OpenAPITools/openapi-generator#25244.
Files.writeString(spec, String.join("\n",
"{",
" \"openapi\": \"3.0.3\",",
" \"info\": { \"title\": \"Reproduction\", \"version\": \"1.0.0\" },",
" \"paths\": {",
" \"/ping\": {",
" \"get\": {",
" \"operationId\": \"ping\",",
" \"responses\": {",
" \"204\": { \"description\": \"No content\" }",
" }",
" }",
" }",
" }",
"}",
""));

Map<String, Object> properties = new HashMap<>();
properties.put("supportsES6", true);
File output = generate(properties, spec.toAbsolutePath().toString());

Path runtime = Paths.get(output.getPath(), "runtime.ts");
// These names exist only in the DOM lib. Node's fetch types do not declare them.
TestUtils.assertFileNotContains(runtime,
"WindowOrWorkerGlobalScope",
"RequestCredentials");
TestUtils.assertFileContains(runtime,
"export type FetchCredentials = NonNullable<RequestInit['credentials']>;",
"export type FetchAPI = { fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> }['fetch'];",
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
"credentials?: FetchCredentials;",
"get credentials(): FetchCredentials | undefined {");
}

private static final String DATE_HANDLING_SPEC = "src/test/resources/3_0/typescript-fetch/date-handling.yaml";

private static File generate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ConfigurationParameters {
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
credentials?: FetchCredentials; //value for the credentials param we want to use on each request
}

export class Configuration {
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Configuration {
return this.configuration.headers;
}

get credentials(): RequestCredentials | undefined {
get credentials(): FetchCredentials | undefined {
return this.configuration.credentials;
}
}
Expand Down Expand Up @@ -302,14 +302,18 @@ export const COLLECTION_FORMATS = {
pipes: "|",
};

export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
// Node's fetch types declare RequestInit, URL and Request but not the DOM fetch global.
// FetchAPI is a method type, so a fetch that takes only a string URL or a required
// init still fits, as it did with typeof fetch.
export type FetchCredentials = NonNullable<RequestInit['credentials']>;
export type FetchAPI = { fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> }['fetch'];

export type Json = any;
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HTTPHeaders = { [key: string]: string };
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
export type HTTPBody = Json | FormData | URLSearchParams;
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: FetchCredentials; body?: HTTPBody };
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';

export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ConfigurationParameters {
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
credentials?: FetchCredentials; //value for the credentials param we want to use on each request
}

export class Configuration {
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Configuration {
return this.configuration.headers;
}

get credentials(): RequestCredentials | undefined {
get credentials(): FetchCredentials | undefined {
return this.configuration.credentials;
}
}
Expand Down Expand Up @@ -302,14 +302,18 @@ export const COLLECTION_FORMATS = {
pipes: "|",
};

export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
// Node's fetch types declare RequestInit, URL and Request but not the DOM fetch global.
// FetchAPI is a method type, so a fetch that takes only a string URL or a required
// init still fits, as it did with typeof fetch.
export type FetchCredentials = NonNullable<RequestInit['credentials']>;
export type FetchAPI = { fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> }['fetch'];

export type Json = any;
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HTTPHeaders = { [key: string]: string };
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
export type HTTPBody = Json | FormData | URLSearchParams;
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: FetchCredentials; body?: HTTPBody };
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';

export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ConfigurationParameters {
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
credentials?: FetchCredentials; //value for the credentials param we want to use on each request
}

export class Configuration {
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Configuration {
return this.configuration.headers;
}

get credentials(): RequestCredentials | undefined {
get credentials(): FetchCredentials | undefined {
return this.configuration.credentials;
}
}
Expand Down Expand Up @@ -302,14 +302,18 @@ export const COLLECTION_FORMATS = {
pipes: "|",
};

export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
// Node's fetch types declare RequestInit, URL and Request but not the DOM fetch global.
// FetchAPI is a method type, so a fetch that takes only a string URL or a required
// init still fits, as it did with typeof fetch.
export type FetchCredentials = NonNullable<RequestInit['credentials']>;
export type FetchAPI = { fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> }['fetch'];

export type Json = any;
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HTTPHeaders = { [key: string]: string };
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
export type HTTPBody = Json | FormData | URLSearchParams;
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: FetchCredentials; body?: HTTPBody };
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';

export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ConfigurationParameters {
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
credentials?: FetchCredentials; //value for the credentials param we want to use on each request
}

export class Configuration {
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Configuration {
return this.configuration.headers;
}

get credentials(): RequestCredentials | undefined {
get credentials(): FetchCredentials | undefined {
return this.configuration.credentials;
}
}
Expand Down Expand Up @@ -302,14 +302,18 @@ export const COLLECTION_FORMATS = {
pipes: "|",
};

export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
// Node's fetch types declare RequestInit, URL and Request but not the DOM fetch global.
// FetchAPI is a method type, so a fetch that takes only a string URL or a required
// init still fits, as it did with typeof fetch.
export type FetchCredentials = NonNullable<RequestInit['credentials']>;
export type FetchAPI = { fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> }['fetch'];

export type Json = any;
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HTTPHeaders = { [key: string]: string };
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
export type HTTPBody = Json | FormData | URLSearchParams;
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: FetchCredentials; body?: HTTPBody };
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';

export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ConfigurationParameters {
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
credentials?: FetchCredentials; //value for the credentials param we want to use on each request
}

export class Configuration {
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Configuration {
return this.configuration.headers;
}

get credentials(): RequestCredentials | undefined {
get credentials(): FetchCredentials | undefined {
return this.configuration.credentials;
}
}
Expand Down Expand Up @@ -302,14 +302,18 @@ export const COLLECTION_FORMATS = {
pipes: "|",
};

export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
// Node's fetch types declare RequestInit, URL and Request but not the DOM fetch global.
// FetchAPI is a method type, so a fetch that takes only a string URL or a required
// init still fits, as it did with typeof fetch.
export type FetchCredentials = NonNullable<RequestInit['credentials']>;
export type FetchAPI = { fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> }['fetch'];

export type Json = any;
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HTTPHeaders = { [key: string]: string };
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
export type HTTPBody = Json | FormData | URLSearchParams;
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: FetchCredentials; body?: HTTPBody };
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';

export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ConfigurationParameters {
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
headers?: HTTPHeaders; //header params we want to use on every request
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
credentials?: FetchCredentials; //value for the credentials param we want to use on each request
}

export class Configuration {
Expand Down Expand Up @@ -78,7 +78,7 @@ export class Configuration {
return this.configuration.headers;
}

get credentials(): RequestCredentials | undefined {
get credentials(): FetchCredentials | undefined {
return this.configuration.credentials;
}
}
Expand Down Expand Up @@ -302,14 +302,18 @@ export const COLLECTION_FORMATS = {
pipes: "|",
};

export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
// Node's fetch types declare RequestInit, URL and Request but not the DOM fetch global.
// FetchAPI is a method type, so a fetch that takes only a string URL or a required
// init still fits, as it did with typeof fetch.
export type FetchCredentials = NonNullable<RequestInit['credentials']>;
export type FetchAPI = { fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> }['fetch'];

export type Json = any;
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
export type HTTPHeaders = { [key: string]: string };
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
export type HTTPBody = Json | FormData | URLSearchParams;
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: FetchCredentials; body?: HTTPBody };
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';

export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
Expand Down
Loading
Loading