chanfana icon indicating copy to clipboard operation
chanfana copied to clipboard

Swagger UI example request not being properly executed if mounted at /some/path

Open carafelix opened this issue 9 months ago • 0 comments

If, for example, you mount itty-router-openapi as a child endpoint inside a hono application, for e.g:

import { OpenAPIRouter } from '@cloudflare/itty-router-openapi'
import { Hono } from 'hono'
// import exampleFetch etc

const router = OpenAPIRouter({
  docs_url: "/doc",
})
router.get('/example', ExampleFetch)

const app = new Hono()
app.mount('/api', router.handle)

Request to the /api/example would succeed, but running the examples from the swagger ui mounted at /api/doc would result in misrouted errors. Adding api as basepath to the OpenAPIRouter would only trail the error.

A solution could be to add a execution_basePath property like

const router = OpenAPIRouter({
  docs: {url: "/doc", execution_basePath: "/api"}
})

carafelix avatar May 16 '24 16:05 carafelix