cloudflare / chanfana

OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!
https://chanfana.pages.dev
MIT License
302 stars 40 forks source link

Nested route with HonoJS should have better documentations #162

Open kice opened 2 months ago

kice commented 2 months ago

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);