H
Honoβ€’7d ago
Mike

@hono/zod-openapi generates :param instead of {param} β€” breaks openapi-fetch compatibility

I'm using @hono/zod-openapi to generate an OpenAPI spec for my Hono backend, but it outputs paths like /channels/:handle instead of the OpenAPI standard /channels/{handle}. This breaks compatibility with openapi-fetch, which expects {param} syntax. Is there a way to configure @hono/zod-openapi to output {param} format instead of :param? Or is post-processing the generated OpenAPI JSON the only option? Appreciate any suggestions πŸ™
8 Replies
Arjix
Arjixβ€’6d ago
I actually don't think it even understands path params It looks like it takes the path string as is I mean, it doesn't have to, since you provide it a schema describing them So yeah, modifying the schema in a middleware would probably be the easiest solution to this You could maybe cache the result in-memory?
Mike
MikeOPβ€’6d ago
It’s odd that the generated OpenAPI doc doesn’t adhere to the specs by default β€” having to manually fix it would be quite a hassle.
Arjix
Arjixβ€’6d ago
as I said, I don't think it "generates" the path parameter in the url it leaves it as-is
ambergristle
ambergristleβ€’6d ago
you're meant to specify the openapi-compatible path in the spec: https://hono.dev/examples/zod-openapi createRoute takes a path param
Arjix
Arjixβ€’6d ago
that's ass
ambergristle
ambergristleβ€’6d ago
🀷 hono-openapi might do it automatically
Arjix
Arjixβ€’6d ago
it does
Mike
MikeOPβ€’6d ago
Oops, my mistake! I can just switch :param to {param} and it still works. The documentation notes that {param} only fails when using app.route, not createRoute.
No description

Did you find this page helpful?