Which OpenAPI Generator to Use? Zod OpenAPI vs Hono OpenAPI vs Hono Docs Generator #4621
-
|
Which OpenAPI Generator to Use? What's difference between Zod OpenAPI vs Hono OpenAPI vs Hono Docs Generator? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Here's a comparison of the three OpenAPI generators for Hono: Quick Comparison
RecommendationsUse
import { OpenAPIHono, createRoute, z } from '@hono/zod-openapi'
const route = createRoute({
method: 'get',
path: '/users/{id}',
request: {
params: z.object({ id: z.string() })
},
responses: {
200: { description: 'User found' }
}
})Use
Use Hono Docs Generator if:
My RecommendationGo with Docs: https://hono.dev/examples/zod-openapi If this solves your problem, please mark it as the answer! ✅ |
Beta Was this translation helpful? Give feedback.
-
|
Shameless plug as I'm an author but I'd like to recommend my library The main goal of this library is easy adoption to existing codebases. With The only real downside is that it's not as flexible when it comes to library choice as it only supports Zod v4 (for v3 use 0.x versions, but I won't be adding any new features there). A simple example on how it works: import { Hono } from 'hono';
import * as z from 'zod';
import { createOpenApiDocument, openApi } from 'hono-zod-openapi';
export const app = new Hono().get(
'/user',
openApi({
tags: ['User'],
responses: {
200: z.object({ hi: z.string() }).meta({ examples: [{ hi: 'user' }] }),
},
request: {
query: z.object({ id: z.string() }),
},
}),
(c) => {
// works identically to @hono/zod-validator
const { id } = c.req.valid('query');
return c.json({ hi: id }, 200);
},
);
// this will add a `GET /doc` route to the `app` router
createOpenApiDocument(app, {
info: {
title: 'Example API',
version: '1.0.0',
},
});Give it a try, I think the DX is pretty awesome. |
Beta Was this translation helpful? Give feedback.
Here's a comparison of the three OpenAPI generators for Hono:
Quick Comparison
Recommendations
Use
@hono/zod-openapiif: