docs: replace jsonT with json (#328)
parent
616afbcd03
commit
009cc77cf5
|
@ -88,7 +88,7 @@ const app = new OpenAPIHono()
|
||||||
|
|
||||||
app.openapi(route, (c) => {
|
app.openapi(route, (c) => {
|
||||||
const { id } = c.req.valid('param')
|
const { id } = c.req.valid('param')
|
||||||
return c.jsonT({
|
return c.json({
|
||||||
id,
|
id,
|
||||||
age: 20,
|
age: 20,
|
||||||
name: 'Ultra-man',
|
name: 'Ultra-man',
|
||||||
|
@ -157,7 +157,7 @@ app.openapi(
|
||||||
route,
|
route,
|
||||||
(c) => {
|
(c) => {
|
||||||
const { id } = c.req.valid('param')
|
const { id } = c.req.valid('param')
|
||||||
return c.jsonT({
|
return c.json({
|
||||||
id,
|
id,
|
||||||
age: 20,
|
age: 20,
|
||||||
name: 'Ultra-man',
|
name: 'Ultra-man',
|
||||||
|
@ -166,7 +166,7 @@ app.openapi(
|
||||||
// Hook
|
// Hook
|
||||||
(result, c) => {
|
(result, c) => {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
return c.jsonT(
|
return c.json(
|
||||||
{
|
{
|
||||||
code: 400,
|
code: 400,
|
||||||
message: 'Validation Error',
|
message: 'Validation Error',
|
||||||
|
@ -186,7 +186,7 @@ In the case that you have a common error formatter, you can initialize the `Open
|
||||||
const app = new OpenAPIHono({
|
const app = new OpenAPIHono({
|
||||||
defaultHook: (result, c) => {
|
defaultHook: (result, c) => {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
return c.jsonT(
|
return c.json(
|
||||||
{
|
{
|
||||||
ok: false,
|
ok: false,
|
||||||
errors: formatZodErrors(result),
|
errors: formatZodErrors(result),
|
||||||
|
@ -205,7 +205,7 @@ You can still override the `defaultHook` by providing the hook at the call site
|
||||||
// uses the defaultHook
|
// uses the defaultHook
|
||||||
app.openapi(createPostRoute, (c) => {
|
app.openapi(createPostRoute, (c) => {
|
||||||
const { title } = c.req.valid('json')
|
const { title } = c.req.valid('json')
|
||||||
return c.jsonT({ title })
|
return c.json({ title })
|
||||||
})
|
})
|
||||||
|
|
||||||
// override the defaultHook by passing in a hook
|
// override the defaultHook by passing in a hook
|
||||||
|
@ -213,11 +213,11 @@ app.openapi(
|
||||||
createBookRoute,
|
createBookRoute,
|
||||||
(c) => {
|
(c) => {
|
||||||
const { title } = c.req.valid('json')
|
const { title } = c.req.valid('json')
|
||||||
return c.jsonT({ title })
|
return c.json({ title })
|
||||||
},
|
},
|
||||||
(result, c) => {
|
(result, c) => {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
return c.jsonT(
|
return c.json(
|
||||||
{
|
{
|
||||||
ok: false,
|
ok: false,
|
||||||
source: 'routeHook' as const,
|
source: 'routeHook' as const,
|
||||||
|
@ -279,7 +279,7 @@ import { hc } from 'hono/client'
|
||||||
|
|
||||||
const appRoutes = app.openapi(route, (c) => {
|
const appRoutes = app.openapi(route, (c) => {
|
||||||
const data = c.req.valid('json')
|
const data = c.req.valid('json')
|
||||||
return c.jsonT({
|
return c.json({
|
||||||
id: data.id,
|
id: data.id,
|
||||||
message: 'Success',
|
message: 'Success',
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue