Skip to content

Commit ff56d37

Browse files
committed
add custom properties to request object
1 parent 37885c2 commit ff56d37

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/openapi-fetch/src/index.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ const DEFAULT_HEADERS = {
55

66
const PATH_PARAM_RE = /\{[^{}]+\}/g;
77

8+
/**
9+
* Add custom parameters to Request object
10+
*/
11+
class CustomRequest extends Request {
12+
constructor(input, init) {
13+
super(input, init);
14+
15+
// add custom parameters
16+
for (const key in init) {
17+
if (!this[key]) {
18+
this[key] = init[key];
19+
}
20+
}
21+
}
22+
}
23+
824
/**
925
* Create an openapi-fetch client.
1026
* @type {import("./index.js").default}
@@ -67,7 +83,7 @@ export default function createClient(clientOptions) {
6783
if (requestInit.body instanceof FormData) {
6884
requestInit.headers.delete("Content-Type");
6985
}
70-
let request = new Request(createFinalURL(url, { baseUrl, params, querySerializer }), requestInit);
86+
let request = new CustomRequest(createFinalURL(url, { baseUrl, params, querySerializer }), requestInit);
7187
// middleware (request)
7288
const mergedOptions = {
7389
baseUrl,

0 commit comments

Comments
 (0)