@hono/zod-openapi 0.15.1 → 0.15.2

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
@@ -269,7 +269,7 @@ You can configure middleware for each endpoint from a route created by `createRo
269
269
 
270
270
  ```ts
271
271
  import { prettyJSON } from 'hono/pretty-json'
272
- import { cache } from 'honoc/cache'
272
+ import { cache } from 'hono/cache'
273
273
 
274
274
  app.use(route.getRoutingPath(), prettyJSON(), cache({ cacheName: 'my-cache' }))
275
275
  app.openapi(route, handler)
package/dist/index.js CHANGED
@@ -99,13 +99,31 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
99
99
  if (!(schema instanceof import_zod.ZodType)) {
100
100
  continue;
101
101
  }
102
- if (/^application\/([a-z-\.]+\+)?json/.test(mediaType)) {
102
+ if (isJSONContentType(mediaType)) {
103
103
  const validator = (0, import_zod_validator.zValidator)("json", schema, hook);
104
- validators.push(validator);
104
+ const mw = async (c, next) => {
105
+ if (c.req.header("content-type")) {
106
+ if (isJSONContentType(c.req.header("content-type"))) {
107
+ return await validator(c, next);
108
+ }
109
+ }
110
+ c.req.addValidatedData("json", {});
111
+ await next();
112
+ };
113
+ validators.push(mw);
105
114
  }
106
- if (mediaType.startsWith("multipart/form-data") || mediaType.startsWith("application/x-www-form-urlencoded")) {
115
+ if (isFormContentType(mediaType)) {
107
116
  const validator = (0, import_zod_validator.zValidator)("form", schema, hook);
108
- validators.push(validator);
117
+ const mw = async (c, next) => {
118
+ if (c.req.header("content-type")) {
119
+ if (isFormContentType(c.req.header("content-type"))) {
120
+ return await validator(c, next);
121
+ }
122
+ }
123
+ c.req.addValidatedData("form", {});
124
+ await next();
125
+ };
126
+ validators.push(mw);
109
127
  }
110
128
  }
111
129
  }
@@ -210,6 +228,12 @@ function addBasePathToDocument(document, basePath) {
210
228
  paths: updatedPaths
211
229
  };
212
230
  }
231
+ function isJSONContentType(contentType) {
232
+ return /^application\/([a-z-\.]+\+)?json/.test(contentType);
233
+ }
234
+ function isFormContentType(contentType) {
235
+ return contentType.startsWith("multipart/form-data") || contentType.startsWith("application/x-www-form-urlencoded");
236
+ }
213
237
  // Annotate the CommonJS export names for ESM import in node:
214
238
  0 && (module.exports = {
215
239
  OpenAPIHono,
package/dist/index.mjs CHANGED
@@ -77,13 +77,31 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
77
77
  if (!(schema instanceof ZodType)) {
78
78
  continue;
79
79
  }
80
- if (/^application\/([a-z-\.]+\+)?json/.test(mediaType)) {
80
+ if (isJSONContentType(mediaType)) {
81
81
  const validator = zValidator("json", schema, hook);
82
- validators.push(validator);
82
+ const mw = async (c, next) => {
83
+ if (c.req.header("content-type")) {
84
+ if (isJSONContentType(c.req.header("content-type"))) {
85
+ return await validator(c, next);
86
+ }
87
+ }
88
+ c.req.addValidatedData("json", {});
89
+ await next();
90
+ };
91
+ validators.push(mw);
83
92
  }
84
- if (mediaType.startsWith("multipart/form-data") || mediaType.startsWith("application/x-www-form-urlencoded")) {
93
+ if (isFormContentType(mediaType)) {
85
94
  const validator = zValidator("form", schema, hook);
86
- validators.push(validator);
95
+ const mw = async (c, next) => {
96
+ if (c.req.header("content-type")) {
97
+ if (isFormContentType(c.req.header("content-type"))) {
98
+ return await validator(c, next);
99
+ }
100
+ }
101
+ c.req.addValidatedData("form", {});
102
+ await next();
103
+ };
104
+ validators.push(mw);
87
105
  }
88
106
  }
89
107
  }
@@ -188,6 +206,12 @@ function addBasePathToDocument(document, basePath) {
188
206
  paths: updatedPaths
189
207
  };
190
208
  }
209
+ function isJSONContentType(contentType) {
210
+ return /^application\/([a-z-\.]+\+)?json/.test(contentType);
211
+ }
212
+ function isFormContentType(contentType) {
213
+ return contentType.startsWith("multipart/form-data") || contentType.startsWith("application/x-www-form-urlencoded");
214
+ }
191
215
  export {
192
216
  OpenAPIHono,
193
217
  createRoute,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/zod-openapi",
3
- "version": "0.15.1",
3
+ "version": "0.15.2",
4
4
  "description": "A wrapper class of Hono which supports OpenAPI.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "@cloudflare/workers-types": "^4.20240117.0",
45
- "hono": "^4.3.6",
45
+ "hono": "^4.5.4",
46
46
  "jest": "^29.7.0",
47
47
  "tsup": "^8.0.1",
48
48
  "typescript": "^5.4.4",