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

Grouped Route Path Parameters Not Recognized in @hono/zod-openapi #547

Closed
HiraiKyo opened this issue May 25, 2024 · 2 comments
Closed

Grouped Route Path Parameters Not Recognized in @hono/zod-openapi #547

HiraiKyo opened this issue May 25, 2024 · 2 comments

Comments

@HiraiKyo
Copy link

HiraiKyo commented May 25, 2024

Issue description:
I'm encountering a problem with the hono/zod-openapi package where path parameters are not recognized when they're used in a sub-application routing configuration. Here's a detailed description of the issue:

  • @hono/zod-openapi: 0.12.1

Not working (sub-application with parameterized route):

const appGet = new Hono();
const route = createRoute({
  path: "/",
  method: "get",
  description: "test",
  request: {
    params: z.object({
      matchOngoingId: z.string(),
    }),
  },
  // ...
});

const app = new Hono();
app.route("/{matchOngoingId}/get", appGet); // Path parameter not captured, returns 404

In this configuration, the path parameter matchOngoingId does not get recognized and results in an error when trying to access the parameter in the sub-application.

Working (direct application route with parameter):

const appGet = new Hono();
const route = createRoute({
  path: "/{matchOngoingId}/get", // This works when directly placed here
  method: "get",
  description: "test",
  request: {
    params: z.object({
      matchOngoingId: z.string(),
    }),
  },
  // ...
});

const app = new Hono();
app.route("/", appGet);

Here, when the parameterized route is directly set in the main application, it works perfectly fine.

Expected behavior:
I would expect the path parameters to be captured regardless of whether they are defined in the main application or a sub-application.

Actual behavior:
The path parameters are not being captured when set via a sub-application.

It seems like a bug with routing in sub-applications. Could you please look into this?

Thank you!

@yusukebe
Copy link
Member

yusukebe commented Jun 9, 2024

Hi @HiraiKyo

This is not a bug. The following format is not supported. We don't have a plan to implement it because to support it, we have to change the hono core code. Thanks.

app.route("/{matchOngoingId}/get", appGet)

@HiraiKyo
Copy link
Author

Sorry for misunderstanding, this is the right way to implement path parameters.

app.route("/:matchOngoingId/get", appGet)

Thanks for the reply!

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

2 participants