diff --git a/src/open-api/from-open-api.ts b/src/open-api/from-open-api.ts index d54e506..0bf5733 100644 --- a/src/open-api/from-open-api.ts +++ b/src/open-api/from-open-api.ts @@ -53,7 +53,7 @@ export async function fromOpenApi( for (const baseUrl of serverUrls) { const path = normalizeSwaggerUrl(url) const requestUrl = isAbsoluteUrl(baseUrl) - ? new URL(path, baseUrl).href + ? new URL(`${baseUrl}${path}`).href : joinPaths(path, baseUrl) if ( diff --git a/test/oas/oas-servers.test.ts b/test/oas/oas-servers.test.ts index 5651d9b..ce9f5b8 100644 --- a/test/oas/oas-servers.test.ts +++ b/test/oas/oas-servers.test.ts @@ -78,6 +78,43 @@ it('supports relative server url', async () => { ]) }) +it('supports server url with subdirectory', async () => { + const handlers = await fromOpenApi( + createOpenApiSpec({ + servers: [{ url: 'https://example.com/subdir' }], + paths: { + '/numbers': { + get: { + responses: { + 200: { + content: { + 'application/json': { + example: [1, 2, 3], + }, + }, + }, + }, + }, + }, + }, + }), + ) + expect(await inspectHandlers(handlers)).toEqual([ + { + handler: { + method: 'GET', + path: 'https://example.com/subdir/numbers', + }, + response: { + status: 200, + statusText: 'OK', + headers: expect.arrayContaining([['content-type', 'application/json']]), + body: JSON.stringify([1, 2, 3]), + }, + }, + ]) +}) + it('supports multiple server urls', async () => { const handlers = await fromOpenApi( createOpenApiSpec({