Comments (3)
Hi @ivandotv
What is the reasoning behind that decision?
This is to keep the implementation simple. If it allows multiple handlers, the type definition will be very, very complex.
Instead, you may use a Hook:
app.openapi(
route,
(c) => {
const val = c.var.val
return c.json()
},
(result, c) => {
if (result.success) {
c.set('val', 'foo')
// auth
}
}
)
from middleware.
I believe breaking the middleware contract to have a type inference on the default handler is not worth it.
Open API can also have multiple responses, and putting that logic in one giant function will not work and will not scale.
Breaking the middleware
contract (which is used in the original Hono, and other frameworks) is a bad decision
In the end I took the underlying zod-to-openapi package and did the implementation from scratch, respecting the middleware order.
Feel free to close this issue.
from middleware.
Breaking the
middleware
contract (which is used in the original Hono, and other frameworks) is a bad decision
Regarding this "Zod OpenAPI Hono", our first idea is to implement OpenAPI with keeping the RPC feature. So we can't avoid that don't support multiple handlers.
In the end I took the underlying zod-to-openapi package and did the implementation from scratch, respecting the middleware order.
It's a good idea. I think you don't need to use this Zod OpenAPI Hono.
Thanks. Closing the issue.
from middleware.
Related Issues (20)
- [zod-openapi] `defaultHook` not executed by requests routed via `app.route()` HOT 1
- [zod-openapi] Route with middleware doesn't infer context variables HOT 2
- net::ERR_INCOMPLETE_CHUNKED_ENCODING when using tRPC subscriptions and the Hono trpc-server/ HOT 1
- @hono/zod-validator not inferring app context types correctly within it's hook function HOT 2
- [zod-openapi] How to add group summary?
- [node-ws] Upgrades every path to ws HOT 1
- [zod-openapi] unable to infer response type from c.status() HOT 1
- [zod-openapi] Question - Generic createRoute generator
- Simplifying the Definition of Request and Response Bodies in `application/json` Format
- Typebox validator hook not calling HOT 2
- [firebase - auth] how i can change the message errors? HOT 1
- [oauth-providers] Problem with GitHub provider from version 0.5.0 HOT 1
- zod-openapi rpc types work only with const schema object HOT 4
- [zod-openapi] streamSSE from hono/streaming together with @hono/zod-openapi have type issues HOT 1
- zValidator parsing url queries containing nested object HOT 4
- Zod OpenAPI module resolution error for `hono/utils/url`. with monorepo setup
- [zod-openapi] Default response support
- Also publish to JSR? HOT 2
- Remove config.basePath ||= '/api/auth'
- Middleware & zod validator problem HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from middleware.