From 58866ad3f5e9620867c06a88398ac1d04df3b837 Mon Sep 17 00:00:00 2001 From: Ro Ramtohul Date: Mon, 12 Feb 2024 15:53:14 +0000 Subject: [PATCH 1/2] 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. --- packages/core/src/lib/prepareServer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/lib/prepareServer.ts b/packages/core/src/lib/prepareServer.ts index ded62107..c2e60220 100644 --- a/packages/core/src/lib/prepareServer.ts +++ b/packages/core/src/lib/prepareServer.ts @@ -25,7 +25,7 @@ export default function prepareServer(spec: Oas, url: string, variables: Record< // If we were able to find the passed in server in the OAS servers, we should use that! If we // couldn't and server variables were passed in we should try our best to handle that, otherwise // we should ignore the passed in server and use whever the default from the OAS is. - if (serverIdx) { + if (serverIdx !== undefined) { return { selected: serverIdx, variables, From 0365a80b1e0a02ae0af1f0b40f317b76bcd9ce46 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 12 Feb 2024 16:53:00 -0600 Subject: [PATCH 2/2] chore: stricter type --- packages/core/src/lib/prepareServer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/lib/prepareServer.ts b/packages/core/src/lib/prepareServer.ts index c2e60220..5232aabd 100644 --- a/packages/core/src/lib/prepareServer.ts +++ b/packages/core/src/lib/prepareServer.ts @@ -14,7 +14,7 @@ function stripTrailingSlash(url: string) { * */ export default function prepareServer(spec: Oas, url: string, variables: Record = {}) { - let serverIdx; + let serverIdx: number | undefined; const sanitizedUrl = stripTrailingSlash(url); (spec.api.servers || []).forEach((server, i) => { if (server.url === sanitizedUrl) {