Skip to content

Commit 21520e5

Browse files
committed
pass pathName to path builder
1 parent 14e3e6c commit 21520e5

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

src/execute/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export function buildRequest(options) {
265265
value,
266266
operation,
267267
spec,
268+
pathName,
268269
});
269270
}
270271
});

src/execute/oas3/parameter-builders.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
import { resolve as resolvePathTemplate } from 'openapi-path-templating';
22

3-
import { DEFAULT_BASE_URL } from '../../constants.js';
43
import stylize, { encodeCharacters } from './style-serializer.js';
54
import serialize from './content-serializer.js';
65

7-
export function path({ req, value, parameter }) {
6+
export function path({ req, value, parameter, pathName }) {
87
const { name, style, explode, content } = parameter;
98

109
if (value === undefined) return;
1110

12-
const url = new URL(req.url, DEFAULT_BASE_URL);
13-
const pathname = decodeURIComponent(url.pathname);
14-
1511
if (content) {
1612
const effectiveMediaType = Object.keys(content)[0];
1713

1814
const resolvedPathname = resolvePathTemplate(
19-
pathname,
15+
pathName,
2016
{ [name]: value },
2117
{ encoder: (val) => encodeCharacters(serialize(val, effectiveMediaType)) }
2218
);
2319

24-
req.url = req.url.replace(pathname, resolvedPathname);
20+
req.url = req.url.replace(pathName, resolvedPathname);
2521
} else {
2622
const resolvedPathname = resolvePathTemplate(
27-
pathname,
23+
pathName,
2824
{ [name]: value },
2925
{
3026
encoder: (val) =>
@@ -38,7 +34,7 @@ export function path({ req, value, parameter }) {
3834
}
3935
);
4036

41-
req.url = req.url.replace(pathname, resolvedPathname);
37+
req.url = req.url.replace(pathName, resolvedPathname);
4238
}
4339
}
4440

src/execute/swagger2/parameter-builders.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { resolve as resolvePathTemplate } from 'openapi-path-templating';
22

3-
import { DEFAULT_BASE_URL } from '../../constants.js';
4-
53
// These functions will update the request.
64
// They'll be given {req, value, paramter, spec, operation}.
75

@@ -53,14 +51,11 @@ function headerBuilder({ req, parameter, value }) {
5351
}
5452

5553
// Replace path paramters, with values ( ie: the URL )
56-
function pathBuilder({ req, value, parameter }) {
54+
function pathBuilder({ req, value, parameter, pathName }) {
5755
if (value !== undefined) {
58-
const url = new URL(req.url, DEFAULT_BASE_URL);
59-
const pathname = decodeURIComponent(url.pathname);
60-
61-
const resolvedPathname = resolvePathTemplate(pathname, { [parameter.name]: value });
56+
const resolvedPathname = resolvePathTemplate(pathName, { [parameter.name]: value });
6257

63-
req.url = req.url.replace(pathname, resolvedPathname);
58+
req.url = req.url.replace(pathName, resolvedPathname);
6459
}
6560
}
6661

0 commit comments

Comments
 (0)