Skip to content

Commit 0f9e3ac

Browse files
authored
Merge branch 'master' into issue-3501
2 parents ee04cb2 + fc997c1 commit 0f9e3ac

File tree

6 files changed

+59
-20
lines changed

6 files changed

+59
-20
lines changed

config/webpack/browser.config.babel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const browserMin = {
6363
devtool: 'source-map',
6464
performance: {
6565
hints: 'error',
66-
maxEntrypointSize: 440000,
66+
maxEntrypointSize: 460000,
6767
maxAssetSize: 50000000,
6868
},
6969
output: {

package-lock.json

+20-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-client",
3-
"version": "3.27.3",
3+
"version": "3.27.5",
44
"description": "SwaggerJS - a collection of interfaces for OAI specs",
55
"browser": {
66
"./src/helpers/btoa.node.js": "./src/helpers/btoa.browser.js",
@@ -122,7 +122,9 @@
122122
"js-yaml": "^4.1.0",
123123
"node-abort-controller": "^3.1.1",
124124
"node-fetch-commonjs": "^3.3.2",
125+
"openapi-path-templating": "^1.5.1",
125126
"qs": "^6.10.2",
127+
"ramda-adjunct": "^5.0.0",
126128
"traverse": "=0.6.8"
127129
},
128130
"overrides": {

src/execute/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import cookie from 'cookie';
22
import { isPlainObject } from 'is-plain-object';
3+
import { escapeRegExp } from 'ramda-adjunct';
34
import { ApiDOMStructuredError } from '@swagger-api/apidom-error';
45
import { url } from '@swagger-api/apidom-reference/configuration/empty';
56

@@ -265,6 +266,7 @@ export function buildRequest(options) {
265266
value,
266267
operation,
267268
spec,
269+
pathName,
268270
});
269271
}
270272
});
@@ -352,7 +354,7 @@ function oas3BaseUrl({ spec, pathName, method, server, contextUrl, serverVariabl
352354
const variableDefinition = selectedServerObj.variables[variable];
353355
const variableValue = serverVariables[variable] || variableDefinition.default;
354356

355-
const re = new RegExp(`{${variable}}`, 'g');
357+
const re = new RegExp(`{${escapeRegExp(variable)}}`, 'g');
356358
selectedServerUrl = selectedServerUrl.replace(re, variableValue);
357359
}
358360
});

src/execute/oas3/parameter-builders.js

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
1+
import { resolve as resolvePathTemplate } from 'openapi-path-templating';
2+
13
import stylize, { encodeCharacters } from './style-serializer.js';
24
import serialize from './content-serializer.js';
35

4-
export function path({ req, value, parameter }) {
6+
export function path({ req, value, parameter, pathName }) {
57
const { name, style, explode, content } = parameter;
68

79
if (value === undefined) return;
810

11+
let resolvedPathname;
12+
913
if (content) {
1014
const effectiveMediaType = Object.keys(content)[0];
1115

12-
req.url = req.url
13-
.split(`{${name}}`)
14-
.join(encodeCharacters(serialize(value, effectiveMediaType)));
16+
resolvedPathname = resolvePathTemplate(
17+
pathName,
18+
{ [name]: value },
19+
{ encoder: (val) => encodeCharacters(serialize(val, effectiveMediaType)) }
20+
);
1521
} else {
16-
const styledValue = stylize({
17-
key: parameter.name,
18-
value,
19-
style: style || 'simple',
20-
explode: explode || false,
21-
escape: 'reserved',
22-
});
23-
24-
req.url = req.url.replace(new RegExp(`{${name}}`, 'g'), styledValue);
22+
resolvedPathname = resolvePathTemplate(
23+
pathName,
24+
{ [name]: value },
25+
{
26+
encoder: (val) =>
27+
stylize({
28+
key: parameter.name,
29+
value: val,
30+
style: style || 'simple',
31+
explode: explode || false,
32+
escape: 'reserved',
33+
}),
34+
}
35+
);
2536
}
37+
38+
req.url = req.url.replace(pathName, resolvedPathname);
2639
}
2740

2841
export function query({ req, value, parameter }) {

src/execute/swagger2/parameter-builders.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { resolve as resolvePathTemplate } from 'openapi-path-templating';
2+
13
// These functions will update the request.
24
// They'll be given {req, value, paramter, spec, operation}.
35

@@ -49,9 +51,11 @@ function headerBuilder({ req, parameter, value }) {
4951
}
5052

5153
// Replace path paramters, with values ( ie: the URL )
52-
function pathBuilder({ req, value, parameter }) {
54+
function pathBuilder({ req, value, parameter, pathName }) {
5355
if (value !== undefined) {
54-
req.url = req.url.replace(new RegExp(`{${parameter.name}}`, 'g'), encodeURIComponent(value));
56+
const resolvedPathname = resolvePathTemplate(pathName, { [parameter.name]: value });
57+
58+
req.url = req.url.replace(pathName, resolvedPathname);
5559
}
5660
}
5761

0 commit comments

Comments
 (0)