cloudflare/chanfana

Nested route with HonoJS should have better documentations

kice opened this issue · 0 comments

kice commented

I just get confused as a 🔥Hono user. My issue is in the comment in the code.

const api = new Hono();
const openapi = fromHono(api, {
    // only use "base" option if schema.servers do not append nested route, like "https://api.example.com"
    // and okay with /v1/ everywhere on the Swagger UI
    // base: "/v1",   
    
    // but here it is okay either use "/docs" or "docs",
    docs_url: "/docs",

    // must not use the default "/openapi.json" will not work
    openapi_url: 'openapi.json',
    schema: {
        servers: [
            {
                // this must be set and the append the nested route, or "Try it out" button will break
                url: 'https://api.example.com/v1',
            }
        ]
    }
});

// the final url for this endpoint will be "https://api.example.com/v1/api/tasks"
openapi.get("/api/tasks", TaskList);

const app = new Hono();
app.route('/v1', api);