api-def 0.12.0-alpha.49 → 0.12.0-alpha.50
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/cjs/ApiUtils.js +23 -8
- package/esm/ApiUtils.js +24 -9
- package/package.json +1 -1
package/cjs/ApiUtils.js
CHANGED
|
@@ -58,15 +58,30 @@ exports.inferResponseType = inferResponseType;
|
|
|
58
58
|
var resolvePathParams = function (path, params) {
|
|
59
59
|
var computedPath = path.startsWith("/") ? path : "/".concat(path);
|
|
60
60
|
if (params) {
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var
|
|
65
|
-
|
|
61
|
+
var computedPathParts = computedPath.split("/");
|
|
62
|
+
var unusedKeys = new Set(Object.keys(params));
|
|
63
|
+
for (var i = 0; i < computedPathParts.length; i++) {
|
|
64
|
+
var part = computedPathParts[i];
|
|
65
|
+
var paramKey = void 0;
|
|
66
|
+
if (part.startsWith(":")) {
|
|
67
|
+
paramKey = part.substring(1);
|
|
68
|
+
}
|
|
69
|
+
else if (part.startsWith("{") && part.endsWith("}")) {
|
|
70
|
+
paramKey = part.substring(1, part.length - 1);
|
|
71
|
+
}
|
|
72
|
+
if (paramKey) {
|
|
73
|
+
var paramValue = params[paramKey];
|
|
74
|
+
if (!paramValue) {
|
|
75
|
+
throw new Error("[api-def] Missing param '".concat(paramKey, "'"));
|
|
76
|
+
}
|
|
77
|
+
computedPathParts[i] = paramValue;
|
|
78
|
+
unusedKeys.delete(paramKey);
|
|
79
|
+
}
|
|
66
80
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
if (unusedKeys.size > 0) {
|
|
82
|
+
throw new Error("[api-def] Missing param '".concat(Array.from(unusedKeys)[0], "'"));
|
|
83
|
+
}
|
|
84
|
+
return computedPathParts.join("/");
|
|
70
85
|
}
|
|
71
86
|
return computedPath;
|
|
72
87
|
};
|
package/esm/ApiUtils.js
CHANGED
|
@@ -48,17 +48,32 @@ export const inferResponseType = (contentType) => {
|
|
|
48
48
|
return "text";
|
|
49
49
|
};
|
|
50
50
|
export const resolvePathParams = (path, params) => {
|
|
51
|
-
|
|
51
|
+
const computedPath = path.startsWith("/") ? path : `/${path}`;
|
|
52
52
|
if (params) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
53
|
+
const computedPathParts = computedPath.split("/");
|
|
54
|
+
const unusedKeys = new Set(Object.keys(params));
|
|
55
|
+
for (let i = 0; i < computedPathParts.length; i++) {
|
|
56
|
+
const part = computedPathParts[i];
|
|
57
|
+
let paramKey;
|
|
58
|
+
if (part.startsWith(":")) {
|
|
59
|
+
paramKey = part.substring(1);
|
|
60
|
+
}
|
|
61
|
+
else if (part.startsWith("{") && part.endsWith("}")) {
|
|
62
|
+
paramKey = part.substring(1, part.length - 1);
|
|
63
|
+
}
|
|
64
|
+
if (paramKey) {
|
|
65
|
+
const paramValue = params[paramKey];
|
|
66
|
+
if (!paramValue) {
|
|
67
|
+
throw new Error(`[api-def] Missing param '${paramKey}'`);
|
|
68
|
+
}
|
|
69
|
+
computedPathParts[i] = paramValue;
|
|
70
|
+
unusedKeys.delete(paramKey);
|
|
71
|
+
}
|
|
58
72
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
if (unusedKeys.size > 0) {
|
|
74
|
+
throw new Error(`[api-def] Missing param '${Array.from(unusedKeys)[0]}'`);
|
|
75
|
+
}
|
|
76
|
+
return computedPathParts.join("/");
|
|
62
77
|
}
|
|
63
78
|
return computedPath;
|
|
64
79
|
};
|