Skip to content

Commit b28ef78

Browse files
JFCotemacjohnny
authored andcommitted
typescript-fetch: allow configuration of headers and credentials (#3586)
* Fix #3402 by giving the possibility to set additional headers and the credentials parameters to the fetch query. * Fix #3402 : Changes from code review
1 parent 7f36f26 commit b28ef78

File tree

6 files changed

+84
-6
lines changed

6 files changed

+84
-6
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ export class BaseAPI {
5252
const body = (context.body instanceof FormData || isBlob(context.body))
5353
? context.body
5454
: JSON.stringify(context.body);
55+
56+
const headers = Object.assign({}, this.configuration.headers, context.headers);
5557
const init = {
5658
method: context.method,
57-
headers: context.headers,
59+
headers: headers,
5860
body,
61+
credentials: this.configuration.credentials
5962
};
6063
return { url, init };
6164
}
@@ -121,6 +124,8 @@ export interface ConfigurationParameters {
121124
password?: string; // parameter for basic security
122125
apiKey?: string | ((name: string) => string); // parameter for apiKey security
123126
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
127+
headers?: HTTPHeaders; //header params we want to use on every request
128+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
124129
}
125130

126131
export class Configuration {
@@ -165,6 +170,14 @@ export class Configuration {
165170
}
166171
return undefined;
167172
}
173+
174+
get headers(): HTTPHeaders {
175+
return this.configuration.headers;
176+
}
177+
178+
get credentials(): RequestCredentials {
179+
return this.configuration.credentials;
180+
}
168181
}
169182

170183
export type Json = any;

samples/client/petstore/typescript-fetch/builds/default/src/runtime.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ export class BaseAPI {
6363
const body = (context.body instanceof FormData || isBlob(context.body))
6464
? context.body
6565
: JSON.stringify(context.body);
66+
67+
const headers = Object.assign({}, this.configuration.headers, context.headers);
6668
const init = {
6769
method: context.method,
68-
headers: context.headers,
70+
headers: headers,
6971
body,
72+
credentials: this.configuration.credentials
7073
};
7174
return { url, init };
7275
}
@@ -132,6 +135,8 @@ export interface ConfigurationParameters {
132135
password?: string; // parameter for basic security
133136
apiKey?: string | ((name: string) => string); // parameter for apiKey security
134137
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
138+
headers?: HTTPHeaders; //header params we want to use on every request
139+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
135140
}
136141

137142
export class Configuration {
@@ -176,6 +181,14 @@ export class Configuration {
176181
}
177182
return undefined;
178183
}
184+
185+
get headers(): HTTPHeaders {
186+
return this.configuration.headers;
187+
}
188+
189+
get credentials(): RequestCredentials {
190+
return this.configuration.credentials;
191+
}
179192
}
180193

181194
export type Json = any;

samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ export class BaseAPI {
6363
const body = (context.body instanceof FormData || isBlob(context.body))
6464
? context.body
6565
: JSON.stringify(context.body);
66+
67+
const headers = Object.assign({}, this.configuration.headers, context.headers);
6668
const init = {
6769
method: context.method,
68-
headers: context.headers,
70+
headers: headers,
6971
body,
72+
credentials: this.configuration.credentials
7073
};
7174
return { url, init };
7275
}
@@ -132,6 +135,8 @@ export interface ConfigurationParameters {
132135
password?: string; // parameter for basic security
133136
apiKey?: string | ((name: string) => string); // parameter for apiKey security
134137
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
138+
headers?: HTTPHeaders; //header params we want to use on every request
139+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
135140
}
136141

137142
export class Configuration {
@@ -176,6 +181,14 @@ export class Configuration {
176181
}
177182
return undefined;
178183
}
184+
185+
get headers(): HTTPHeaders {
186+
return this.configuration.headers;
187+
}
188+
189+
get credentials(): RequestCredentials {
190+
return this.configuration.credentials;
191+
}
179192
}
180193

181194
export type Json = any;

samples/client/petstore/typescript-fetch/builds/multiple-parameters/src/runtime.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ export class BaseAPI {
6363
const body = (context.body instanceof FormData || isBlob(context.body))
6464
? context.body
6565
: JSON.stringify(context.body);
66+
67+
const headers = Object.assign({}, this.configuration.headers, context.headers);
6668
const init = {
6769
method: context.method,
68-
headers: context.headers,
70+
headers: headers,
6971
body,
72+
credentials: this.configuration.credentials
7073
};
7174
return { url, init };
7275
}
@@ -132,6 +135,8 @@ export interface ConfigurationParameters {
132135
password?: string; // parameter for basic security
133136
apiKey?: string | ((name: string) => string); // parameter for apiKey security
134137
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
138+
headers?: HTTPHeaders; //header params we want to use on every request
139+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
135140
}
136141

137142
export class Configuration {
@@ -176,6 +181,14 @@ export class Configuration {
176181
}
177182
return undefined;
178183
}
184+
185+
get headers(): HTTPHeaders {
186+
return this.configuration.headers;
187+
}
188+
189+
get credentials(): RequestCredentials {
190+
return this.configuration.credentials;
191+
}
179192
}
180193

181194
export type Json = any;

samples/client/petstore/typescript-fetch/builds/with-interfaces/src/runtime.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ export class BaseAPI {
6363
const body = (context.body instanceof FormData || isBlob(context.body))
6464
? context.body
6565
: JSON.stringify(context.body);
66+
67+
const headers = Object.assign({}, this.configuration.headers, context.headers);
6668
const init = {
6769
method: context.method,
68-
headers: context.headers,
70+
headers: headers,
6971
body,
72+
credentials: this.configuration.credentials
7073
};
7174
return { url, init };
7275
}
@@ -132,6 +135,8 @@ export interface ConfigurationParameters {
132135
password?: string; // parameter for basic security
133136
apiKey?: string | ((name: string) => string); // parameter for apiKey security
134137
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
138+
headers?: HTTPHeaders; //header params we want to use on every request
139+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
135140
}
136141

137142
export class Configuration {
@@ -176,6 +181,14 @@ export class Configuration {
176181
}
177182
return undefined;
178183
}
184+
185+
get headers(): HTTPHeaders {
186+
return this.configuration.headers;
187+
}
188+
189+
get credentials(): RequestCredentials {
190+
return this.configuration.credentials;
191+
}
179192
}
180193

181194
export type Json = any;

samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ export class BaseAPI {
6363
const body = (context.body instanceof FormData || isBlob(context.body))
6464
? context.body
6565
: JSON.stringify(context.body);
66+
67+
const headers = Object.assign({}, this.configuration.headers, context.headers);
6668
const init = {
6769
method: context.method,
68-
headers: context.headers,
70+
headers: headers,
6971
body,
72+
credentials: this.configuration.credentials
7073
};
7174
return { url, init };
7275
}
@@ -132,6 +135,8 @@ export interface ConfigurationParameters {
132135
password?: string; // parameter for basic security
133136
apiKey?: string | ((name: string) => string); // parameter for apiKey security
134137
accessToken?: string | ((name?: string, scopes?: string[]) => string); // parameter for oauth2 security
138+
headers?: HTTPHeaders; //header params we want to use on every request
139+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
135140
}
136141

137142
export class Configuration {
@@ -176,6 +181,14 @@ export class Configuration {
176181
}
177182
return undefined;
178183
}
184+
185+
get headers(): HTTPHeaders {
186+
return this.configuration.headers;
187+
}
188+
189+
get credentials(): RequestCredentials {
190+
return this.configuration.credentials;
191+
}
179192
}
180193

181194
export type Json = any;

0 commit comments

Comments
 (0)