Skip to content

Commit

Permalink
fix(fromOpenApi): support subdirectories in the server URL (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmymcpeter authored Aug 1, 2024
1 parent 7723ae8 commit 13a57a9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/open-api/from-open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
37 changes: 37 additions & 0 deletions test/oas/oas-servers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InspectedHandler[]>([
{
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({
Expand Down

0 comments on commit 13a57a9

Please sign in to comment.