Skip to content

Commit 24393e5

Browse files
committed
fix: provide fallback values for path params
1 parent a3761d0 commit 24393e5

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,28 +114,29 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
114114
function setPathParams(postman: sdk.Request, pathParams: Param[]) {
115115
// Map through the path parameters
116116
const source = pathParams.map((param) => {
117-
if (!param.value) {
118-
return undefined;
119-
}
117+
const value =
118+
param.value !== undefined && param.value !== ""
119+
? param.value
120+
: `<${param.name}>`;
120121

121122
let serializedValue;
122123

123124
// Handle different styles
124-
if (Array.isArray(param.value)) {
125+
if (Array.isArray(value)) {
125126
if (param.style === "label") {
126-
serializedValue = `.${param.value.join(".")}`;
127+
serializedValue = `.${value.join(".")}`;
127128
} else if (param.style === "matrix") {
128-
serializedValue = `;${param.name}=${param.value.join(";")}`;
129+
serializedValue = `;${param.name}=${value.join(";")}`;
129130
} else {
130-
serializedValue = param.value.join(",");
131+
serializedValue = value.join(",");
131132
}
132133
return new sdk.Variable({
133134
key: param.name,
134135
value: serializedValue,
135136
});
136137
}
137138

138-
const jsonResult = tryDecodeJsonParam(param.value);
139+
const jsonResult = tryDecodeJsonParam(value);
139140

140141
if (jsonResult && typeof jsonResult === "object") {
141142
if (param.style === "matrix") {
@@ -148,7 +149,7 @@ function setPathParams(postman: sdk.Request, pathParams: Param[]) {
148149
.join(",");
149150
}
150151
} else {
151-
serializedValue = param.value;
152+
serializedValue = value;
152153
}
153154

154155
return new sdk.Variable({
@@ -157,10 +158,7 @@ function setPathParams(postman: sdk.Request, pathParams: Param[]) {
157158
});
158159
});
159160

160-
postman.url.variables.assimilate(
161-
source.filter((v): v is sdk.Variable => v !== undefined),
162-
false
163-
);
161+
postman.url.variables.assimilate(source, false);
164162
}
165163

166164
function buildCookie(cookieParams: Param[]) {

0 commit comments

Comments
 (0)