@hono/zod-openapi 0.9.5 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -88,7 +88,7 @@ const app = new OpenAPIHono()
88
88
 
89
89
  app.openapi(route, (c) => {
90
90
  const { id } = c.req.valid('param')
91
- return c.jsonT({
91
+ return c.json({
92
92
  id,
93
93
  age: 20,
94
94
  name: 'Ultra-man',
@@ -157,7 +157,7 @@ app.openapi(
157
157
  route,
158
158
  (c) => {
159
159
  const { id } = c.req.valid('param')
160
- return c.jsonT({
160
+ return c.json({
161
161
  id,
162
162
  age: 20,
163
163
  name: 'Ultra-man',
@@ -166,7 +166,7 @@ app.openapi(
166
166
  // Hook
167
167
  (result, c) => {
168
168
  if (!result.success) {
169
- return c.jsonT(
169
+ return c.json(
170
170
  {
171
171
  code: 400,
172
172
  message: 'Validation Error',
@@ -186,7 +186,7 @@ In the case that you have a common error formatter, you can initialize the `Open
186
186
  const app = new OpenAPIHono({
187
187
  defaultHook: (result, c) => {
188
188
  if (!result.success) {
189
- return c.jsonT(
189
+ return c.json(
190
190
  {
191
191
  ok: false,
192
192
  errors: formatZodErrors(result),
@@ -205,7 +205,7 @@ You can still override the `defaultHook` by providing the hook at the call site
205
205
  // uses the defaultHook
206
206
  app.openapi(createPostRoute, (c) => {
207
207
  const { title } = c.req.valid('json')
208
- return c.jsonT({ title })
208
+ return c.json({ title })
209
209
  })
210
210
 
211
211
  // override the defaultHook by passing in a hook
@@ -213,11 +213,11 @@ app.openapi(
213
213
  createBookRoute,
214
214
  (c) => {
215
215
  const { title } = c.req.valid('json')
216
- return c.jsonT({ title })
216
+ return c.json({ title })
217
217
  },
218
218
  (result, c) => {
219
219
  if (!result.success) {
220
- return c.jsonT(
220
+ return c.json(
221
221
  {
222
222
  ok: false,
223
223
  source: 'routeHook' as const,
@@ -279,7 +279,7 @@ import { hc } from 'hono/client'
279
279
 
280
280
  const appRoutes = app.openapi(route, (c) => {
281
281
  const data = c.req.valid('json')
282
- return c.jsonT({
282
+ return c.json({
283
283
  id: data.id,
284
284
  message: 'Success',
285
285
  })
@@ -311,11 +311,9 @@ eg. Bearer Auth
311
311
  Register the security scheme:
312
312
 
313
313
  ```ts
314
- app.openAPIRegistry.registerComponent('securitySchema', {
315
- Bearer: {
316
- type: 'http',
317
- scheme: 'bearer',
318
- },
314
+ app.openAPIRegistry.registerComponent("securitySchemes", "Bearer", {
315
+ type: "http",
316
+ scheme: "bearer",
319
317
  })
320
318
  ```
321
319
 
package/dist/index.js CHANGED
@@ -93,15 +93,23 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
93
93
  doc = (path, configure) => {
94
94
  return this.get(path, (c) => {
95
95
  const config = typeof configure === "function" ? configure(c) : configure;
96
- const document = this.getOpenAPIDocument(config);
97
- return c.json(document);
96
+ try {
97
+ const document = this.getOpenAPIDocument(config);
98
+ return c.json(document);
99
+ } catch (e) {
100
+ return c.json(e, 500);
101
+ }
98
102
  });
99
103
  };
100
104
  doc31 = (path, configure) => {
101
105
  return this.get(path, (c) => {
102
106
  const config = typeof configure === "function" ? configure(c) : configure;
103
- const document = this.getOpenAPI31Document(config);
104
- return c.json(document);
107
+ try {
108
+ const document = this.getOpenAPI31Document(config);
109
+ return c.json(document);
110
+ } catch (e) {
111
+ return c.json(e, 500);
112
+ }
105
113
  });
106
114
  };
107
115
  route(path, app) {
package/dist/index.mjs CHANGED
@@ -71,15 +71,23 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
71
71
  doc = (path, configure) => {
72
72
  return this.get(path, (c) => {
73
73
  const config = typeof configure === "function" ? configure(c) : configure;
74
- const document = this.getOpenAPIDocument(config);
75
- return c.json(document);
74
+ try {
75
+ const document = this.getOpenAPIDocument(config);
76
+ return c.json(document);
77
+ } catch (e) {
78
+ return c.json(e, 500);
79
+ }
76
80
  });
77
81
  };
78
82
  doc31 = (path, configure) => {
79
83
  return this.get(path, (c) => {
80
84
  const config = typeof configure === "function" ? configure(c) : configure;
81
- const document = this.getOpenAPI31Document(config);
82
- return c.json(document);
85
+ try {
86
+ const document = this.getOpenAPI31Document(config);
87
+ return c.json(document);
88
+ } catch (e) {
89
+ return c.json(e, 500);
90
+ }
83
91
  });
84
92
  };
85
93
  route(path, app) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/zod-openapi",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "description": "A wrapper class of Hono which supports OpenAPI.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",