exemple for zod-openapi + rpc
does anyone has a working exemple of https://hono.dev/examples/zod-openapi + https://hono.dev/docs/guides/rpc
i know i have to chain routes, but i still got unknown (maybe because of zod-openapi ?)
Zod OpenAPI - Hono
Web framework built on Web Standards for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
RPC - Hono
Web framework built on Web Standards for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
24 Replies
I've had great success with hono-openapi
But unfortunately it doesn't type-check the return type of your routes the same way zod-openapi does
i saw your post on other thread, maybe i will go for hono-openapi instead
(do you ahve simple exemple with hono-openapi + rpc ?)
There is nothing special about that combination
Just follow the docs for both of them
It'll just work
PS: for openapi generation, it will only include routes that have the middleware
describeRoute
, routes w/o it won't show up on swagger for exampleOK
@WAAYZZz π if youβre getting
unknown
, it could be an issue w your implementation, or you might need to use generated types
Switching to hono-openapi
has its advantages, but it wonβt fix your type issuei will share my code tomorrows, it's simple implementation for the moment
(juste a function returning a hono instance with pino and error handler set, and a zodopenapi route returnin fixed data
If youβre applying middleware in a custom function, that may be the problem. Iβd recommend taking a look at the Hono factory helper
(code is splited, just grouped for demo)
ok i succed by better chaining
was needed
i migrate to hono-openapi and factories and it works
well encountred an other issue π https://github.com/rhinobase/hono-openapi/issues/91 but with hono-openapi this time
GitHub
using createFactory to add isn't detected by openapi Β· Issue #91 ...
Hi, import { createFactory } from "hono/factory"; import { describeRoute } from "hono-openapi"; import type { PinoLogger } from "hono-pino"; import { HTTPException } f...
What do you mean by βdetectedβ? Also, please avoid opening issues unless you know thereβs a problem with the library
Doesn't appear in the openapi export
You mean
/a/test
doesnβt show up in the openapi spec generated at /openapi
?Absolutely, but using new hono instead of createfacorry makes it show up
Interesting. Iβll try and repro
What runtime are you using?
Nodejs
i think problem is related to use factory with initApp
interesting. @WAAYZZz π i can repro the error. looks like it's the
onError
registration that's causing the issue
this is the line in hono-openapi
that's preventing the docs from being generated: https://github.com/rhinobase/hono-openapi/blob/7f5d0affeb538045e3718933a550b00381ceb9bc/packages/core/src/openapi.ts#L93
not sure what it is about registering onError
in createApp
that interferes with the uniqueSymbol
wow well played
last question, how to properly pass rpc client or typeof App to frontend in a monorepo architecture ?
i have this repo https://github.com/iNeoO/sirena
in
apps/backend/src/hc.ts
client or AppType are well typed
but in apps/frontend/src/lib/api/hc.ts
everything becomes any
the only way i manged to make it works it's to not use factory, new app creationand even doing that, the first level of routes are well typed, but not the second (eg: user)
Youβll want to generate types during transpilation and use those with the client instead
You might need to update your
tsconfig
I'm trying this
thx, used pkgroll and it works now
i figured out what the issue is with
onError
i added the details to the issue you opened for reference
i'm actually not sure whether i'd consider this a bug/edge-case
its certainly an unexpected behaviorthx for your huge help
happy to help!