How do I type HTML responses using Zod OpenAPI Hono? #2498
Answered
by
yusukebe
winstxnhdw
asked this question in
Q&A
-
const route = createRoute({
method: 'post',
path: '/post/default',
request: {
query: DefaultProxyQuerySchema,
body: {
content: {
'application/json': { schema: DefaultProxyBodySchema },
},
},
},
responses: {
200: {
// content: {
// 'text/html': { schema: z.string() },
// },
description: 'The string response from the endpoint.',
},
500: {
content: {
'application/json': { schema: DefaultProxyErrorSchema },
},
description: 'Failed to fetch the endpoint.',
},
},
})
export const default_proxy = new OpenAPIHono().openapi(route, async (context) => {
const response = "<p>test html string; this is actually retrieved via fetch</p>"
return response ? context.html(response) : context.json({ error: 'Failed to fetch the endpoint!' } as const, 500)
}) I get an error if I set the 200 response to content: {
'text/html': { schema: z.string() },
}, This is because unlike |
Beta Was this translation helpful? Give feedback.
Answered by
yusukebe
Apr 16, 2024
Replies: 1 comment 3 replies
-
Hi @winstxnhdw Currently, it does not support a response that is not JSON. This is because being structured is difficult if it's not |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
winstxnhdw
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @winstxnhdw
Currently, it does not support a response that is not JSON. This is because being structured is difficult if it's not
application/json
.