Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hono/zod-openapi route groups don't populate into doc endpoint #493

Open
DaveLo opened this issue May 2, 2024 · 4 comments
Open

hono/zod-openapi route groups don't populate into doc endpoint #493

DaveLo opened this issue May 2, 2024 · 4 comments

Comments

@DaveLo
Copy link

DaveLo commented May 2, 2024

Following along the route groups documentation with openapi and the app is functional, but the openapi docs are empty. If I move the customer route into the main app file the docs generate as expected.

//customers.ts

const customers = new OpenAPIHono<EnvBindings>();

const customerRoute = createRoute({
  method: "get",
  path: "/{id}"
  request: { ...request schema }
  responses: { ...response schema }
});

customers.openapi(customerRoute, (c) => c.json({foo:'bar'}));

export default customers;

// main.ts
import customers from "./customers";

const app = new OpenAPIHono<EnvBindings>();
app.route("/customers", customers);

app.doc("/doc", {
  openapi: "3.0.0",
  info: { title: "my api" }
});

export const handler = handle(app)

Expected behavior

The generated openapi doc in the separate file merges with the main app to stitch the api together.

Actual behavior

The /doc route displays an empty {}

@tialki
Copy link

tialki commented May 9, 2024

Not the same OpenAPIHono instances?

@DaveLo
Copy link
Author

DaveLo commented May 10, 2024

Not the same OpenAPIHono instances?

No, I was trying to use route grouping with the openapi middleware. Would I need to pass the app around more like a dependency injection to a create{X}Routes function? I'm trying to colocate the code and the route for clarity in maintaining each base route branch.

@vthang95
Copy link

I encountered the same issue after separating APIs into multiple route files.

@raiyansarker
Copy link

Having the same issue, is there any update so far?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants