Skip to content

Commit 01d1a00

Browse files
yoitsrokanadgupta
andauthored
fix: ensure prepareServer respects server variables when custom url is the same as the OAS url (#855)
* fix: ensure prepareServer respects server variables when custom url is the same as the OAS url A truthy check was being performed on the `serverIdx`, which would effectively ignore the value when `serverIdx` was 0. This fixes that to ensure that server variables are respected when the server URL passed in is the same as the server URL defined in the OAS. * chore: stricter type --------- Co-authored-by: Kanad Gupta <[email protected]>
1 parent f95874b commit 01d1a00

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/core/src/lib/prepareServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function stripTrailingSlash(url: string) {
1414
*
1515
*/
1616
export default function prepareServer(spec: Oas, url: string, variables: Record<string, string | number> = {}) {
17-
let serverIdx;
17+
let serverIdx: number | undefined;
1818
const sanitizedUrl = stripTrailingSlash(url);
1919
(spec.api.servers || []).forEach((server, i) => {
2020
if (server.url === sanitizedUrl) {
@@ -25,7 +25,7 @@ export default function prepareServer(spec: Oas, url: string, variables: Record<
2525
// If we were able to find the passed in server in the OAS servers, we should use that! If we
2626
// couldn't and server variables were passed in we should try our best to handle that, otherwise
2727
// we should ignore the passed in server and use whever the default from the OAS is.
28-
if (serverIdx) {
28+
if (serverIdx !== undefined) {
2929
return {
3030
selected: serverIdx,
3131
variables,

0 commit comments

Comments
 (0)