swagger-client 3.26.6 → 3.26.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/swagger-client.browser.js +49 -29
- package/dist/swagger-client.browser.min.js +1 -1
- package/dist/swagger-client.browser.min.js.map +1 -1
- package/es/execute/oas3/content-serializer.js +10 -1
- package/es/execute/oas3/parameter-builders.js +3 -5
- package/es/execute/oas3/style-serializer.js +11 -23
- package/lib/execute/oas3/content-serializer.js +10 -1
- package/lib/execute/oas3/parameter-builders.js +2 -4
- package/lib/execute/oas3/style-serializer.js +12 -24
- package/package.json +1 -1
|
@@ -9,7 +9,16 @@ export default function serialize(value, mediaType) {
|
|
|
9
9
|
// Assume the user has a JSON string
|
|
10
10
|
return value;
|
|
11
11
|
}
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
value = value.map(v => {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(v);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return v;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
12
21
|
return JSON.stringify(value);
|
|
13
22
|
}
|
|
14
|
-
return value
|
|
23
|
+
return String(value);
|
|
15
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import stylize, {
|
|
1
|
+
import stylize, { encodeCharacters } from './style-serializer.js';
|
|
2
2
|
import serialize from './content-serializer.js';
|
|
3
3
|
export function path({
|
|
4
4
|
req,
|
|
@@ -14,16 +14,14 @@ export function path({
|
|
|
14
14
|
if (value === undefined) return;
|
|
15
15
|
if (content) {
|
|
16
16
|
const effectiveMediaType = Object.keys(content)[0];
|
|
17
|
-
req.url = req.url.split(`{${name}}`).join(
|
|
18
|
-
escape: true
|
|
19
|
-
}));
|
|
17
|
+
req.url = req.url.split(`{${name}}`).join(encodeCharacters(serialize(value, effectiveMediaType)));
|
|
20
18
|
} else {
|
|
21
19
|
const styledValue = stylize({
|
|
22
20
|
key: parameter.name,
|
|
23
21
|
value,
|
|
24
22
|
style: style || 'simple',
|
|
25
23
|
explode: explode || false,
|
|
26
|
-
escape:
|
|
24
|
+
escape: 'reserved'
|
|
27
25
|
});
|
|
28
26
|
req.url = req.url.replace(new RegExp(`{${name}}`, 'g'), styledValue);
|
|
29
27
|
}
|
|
@@ -1,32 +1,17 @@
|
|
|
1
1
|
const isRfc3986Reserved = char => ":/?#[]@!$&'()*+,;=".indexOf(char) > -1;
|
|
2
|
-
const
|
|
2
|
+
const isRfc3986Unreserved = char => /^[a-z0-9\-._~]+$/i.test(char);
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line default-param-last
|
|
5
|
-
export function
|
|
6
|
-
escape
|
|
7
|
-
} = {}, parse) {
|
|
8
|
-
if (typeof str === 'number') {
|
|
9
|
-
str = str.toString();
|
|
10
|
-
}
|
|
11
|
-
if (typeof str !== 'string' || !str.length) {
|
|
12
|
-
return str;
|
|
13
|
-
}
|
|
14
|
-
if (!escape) {
|
|
15
|
-
return str;
|
|
16
|
-
}
|
|
17
|
-
if (parse) {
|
|
18
|
-
return JSON.parse(str);
|
|
19
|
-
}
|
|
20
|
-
|
|
5
|
+
export function encodeCharacters(str, characterSet = 'reserved') {
|
|
21
6
|
// In ES6 you can do this quite easily by using the new ... spread operator.
|
|
22
7
|
// This causes the string iterator (another new ES6 feature) to be used internally,
|
|
23
8
|
// and because that iterator is designed to deal with
|
|
24
9
|
// code points rather than UCS-2/UTF-16 code units.
|
|
25
10
|
return [...str].map(char => {
|
|
26
|
-
if (
|
|
11
|
+
if (isRfc3986Unreserved(char)) {
|
|
27
12
|
return char;
|
|
28
13
|
}
|
|
29
|
-
if (isRfc3986Reserved(char) &&
|
|
14
|
+
if (isRfc3986Reserved(char) && characterSet === 'unsafe') {
|
|
30
15
|
return char;
|
|
31
16
|
}
|
|
32
17
|
const encoder = new TextEncoder();
|
|
@@ -46,13 +31,16 @@ export default function stylize(config) {
|
|
|
46
31
|
}
|
|
47
32
|
return encodePrimitive(config);
|
|
48
33
|
}
|
|
49
|
-
export function valueEncoder(value, escape) {
|
|
34
|
+
export function valueEncoder(value, escape = false) {
|
|
50
35
|
if (Array.isArray(value) || value !== null && typeof value === 'object') {
|
|
51
36
|
value = JSON.stringify(value);
|
|
37
|
+
} else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
38
|
+
value = String(value);
|
|
39
|
+
}
|
|
40
|
+
if (escape && value.length > 0) {
|
|
41
|
+
return encodeCharacters(value, escape);
|
|
52
42
|
}
|
|
53
|
-
return
|
|
54
|
-
escape
|
|
55
|
-
});
|
|
43
|
+
return value;
|
|
56
44
|
}
|
|
57
45
|
function encodeArray({
|
|
58
46
|
key,
|
|
@@ -13,7 +13,16 @@ function serialize(value, mediaType) {
|
|
|
13
13
|
// Assume the user has a JSON string
|
|
14
14
|
return value;
|
|
15
15
|
}
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
value = value.map(v => {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(v);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
return v;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
16
25
|
return JSON.stringify(value);
|
|
17
26
|
}
|
|
18
|
-
return value
|
|
27
|
+
return String(value);
|
|
19
28
|
}
|
|
@@ -23,16 +23,14 @@ function path({
|
|
|
23
23
|
if (value === undefined) return;
|
|
24
24
|
if (content) {
|
|
25
25
|
const effectiveMediaType = Object.keys(content)[0];
|
|
26
|
-
req.url = req.url.split(`{${name}}`).join((0, _styleSerializer.
|
|
27
|
-
escape: true
|
|
28
|
-
}));
|
|
26
|
+
req.url = req.url.split(`{${name}}`).join((0, _styleSerializer.encodeCharacters)((0, _contentSerializer.default)(value, effectiveMediaType)));
|
|
29
27
|
} else {
|
|
30
28
|
const styledValue = (0, _styleSerializer.default)({
|
|
31
29
|
key: parameter.name,
|
|
32
30
|
value,
|
|
33
31
|
style: style || 'simple',
|
|
34
32
|
explode: explode || false,
|
|
35
|
-
escape:
|
|
33
|
+
escape: 'reserved'
|
|
36
34
|
});
|
|
37
35
|
req.url = req.url.replace(new RegExp(`{${name}}`, 'g'), styledValue);
|
|
38
36
|
}
|
|
@@ -2,37 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = stylize;
|
|
5
|
-
exports.
|
|
5
|
+
exports.encodeCharacters = encodeCharacters;
|
|
6
6
|
exports.valueEncoder = valueEncoder;
|
|
7
7
|
const isRfc3986Reserved = char => ":/?#[]@!$&'()*+,;=".indexOf(char) > -1;
|
|
8
|
-
const
|
|
8
|
+
const isRfc3986Unreserved = char => /^[a-z0-9\-._~]+$/i.test(char);
|
|
9
9
|
|
|
10
10
|
// eslint-disable-next-line default-param-last
|
|
11
|
-
function
|
|
12
|
-
escape
|
|
13
|
-
} = {}, parse) {
|
|
14
|
-
if (typeof str === 'number') {
|
|
15
|
-
str = str.toString();
|
|
16
|
-
}
|
|
17
|
-
if (typeof str !== 'string' || !str.length) {
|
|
18
|
-
return str;
|
|
19
|
-
}
|
|
20
|
-
if (!escape) {
|
|
21
|
-
return str;
|
|
22
|
-
}
|
|
23
|
-
if (parse) {
|
|
24
|
-
return JSON.parse(str);
|
|
25
|
-
}
|
|
26
|
-
|
|
11
|
+
function encodeCharacters(str, characterSet = 'reserved') {
|
|
27
12
|
// In ES6 you can do this quite easily by using the new ... spread operator.
|
|
28
13
|
// This causes the string iterator (another new ES6 feature) to be used internally,
|
|
29
14
|
// and because that iterator is designed to deal with
|
|
30
15
|
// code points rather than UCS-2/UTF-16 code units.
|
|
31
16
|
return [...str].map(char => {
|
|
32
|
-
if (
|
|
17
|
+
if (isRfc3986Unreserved(char)) {
|
|
33
18
|
return char;
|
|
34
19
|
}
|
|
35
|
-
if (isRfc3986Reserved(char) &&
|
|
20
|
+
if (isRfc3986Reserved(char) && characterSet === 'unsafe') {
|
|
36
21
|
return char;
|
|
37
22
|
}
|
|
38
23
|
const encoder = new TextEncoder();
|
|
@@ -52,13 +37,16 @@ function stylize(config) {
|
|
|
52
37
|
}
|
|
53
38
|
return encodePrimitive(config);
|
|
54
39
|
}
|
|
55
|
-
function valueEncoder(value, escape) {
|
|
40
|
+
function valueEncoder(value, escape = false) {
|
|
56
41
|
if (Array.isArray(value) || value !== null && typeof value === 'object') {
|
|
57
42
|
value = JSON.stringify(value);
|
|
43
|
+
} else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
44
|
+
value = String(value);
|
|
45
|
+
}
|
|
46
|
+
if (escape && value.length > 0) {
|
|
47
|
+
return encodeCharacters(value, escape);
|
|
58
48
|
}
|
|
59
|
-
return
|
|
60
|
-
escape
|
|
61
|
-
});
|
|
49
|
+
return value;
|
|
62
50
|
}
|
|
63
51
|
function encodeArray({
|
|
64
52
|
key,
|