@hono/zod-openapi 0.15.2 → 0.15.3

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/dist/index.js CHANGED
@@ -101,29 +101,37 @@ var OpenAPIHono = class _OpenAPIHono extends import_hono.Hono {
101
101
  }
102
102
  if (isJSONContentType(mediaType)) {
103
103
  const validator = (0, import_zod_validator.zValidator)("json", schema, hook);
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);
104
+ if (route.request?.body?.required) {
105
+ validators.push(validator);
106
+ } else {
107
+ const mw = async (c, next) => {
108
+ if (c.req.header("content-type")) {
109
+ if (isJSONContentType(c.req.header("content-type"))) {
110
+ return await validator(c, next);
111
+ }
108
112
  }
109
- }
110
- c.req.addValidatedData("json", {});
111
- await next();
112
- };
113
- validators.push(mw);
113
+ c.req.addValidatedData("json", {});
114
+ await next();
115
+ };
116
+ validators.push(mw);
117
+ }
114
118
  }
115
119
  if (isFormContentType(mediaType)) {
116
120
  const validator = (0, import_zod_validator.zValidator)("form", schema, hook);
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
+ if (route.request?.body?.required) {
122
+ validators.push(validator);
123
+ } else {
124
+ const mw = async (c, next) => {
125
+ if (c.req.header("content-type")) {
126
+ if (isFormContentType(c.req.header("content-type"))) {
127
+ return await validator(c, next);
128
+ }
121
129
  }
122
- }
123
- c.req.addValidatedData("form", {});
124
- await next();
125
- };
126
- validators.push(mw);
130
+ c.req.addValidatedData("form", {});
131
+ await next();
132
+ };
133
+ validators.push(mw);
134
+ }
127
135
  }
128
136
  }
129
137
  }
package/dist/index.mjs CHANGED
@@ -79,29 +79,37 @@ var OpenAPIHono = class _OpenAPIHono extends Hono {
79
79
  }
80
80
  if (isJSONContentType(mediaType)) {
81
81
  const validator = zValidator("json", schema, hook);
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);
82
+ if (route.request?.body?.required) {
83
+ validators.push(validator);
84
+ } else {
85
+ const mw = async (c, next) => {
86
+ if (c.req.header("content-type")) {
87
+ if (isJSONContentType(c.req.header("content-type"))) {
88
+ return await validator(c, next);
89
+ }
86
90
  }
87
- }
88
- c.req.addValidatedData("json", {});
89
- await next();
90
- };
91
- validators.push(mw);
91
+ c.req.addValidatedData("json", {});
92
+ await next();
93
+ };
94
+ validators.push(mw);
95
+ }
92
96
  }
93
97
  if (isFormContentType(mediaType)) {
94
98
  const validator = zValidator("form", schema, hook);
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
+ if (route.request?.body?.required) {
100
+ validators.push(validator);
101
+ } else {
102
+ const mw = async (c, next) => {
103
+ if (c.req.header("content-type")) {
104
+ if (isFormContentType(c.req.header("content-type"))) {
105
+ return await validator(c, next);
106
+ }
99
107
  }
100
- }
101
- c.req.addValidatedData("form", {});
102
- await next();
103
- };
104
- validators.push(mw);
108
+ c.req.addValidatedData("form", {});
109
+ await next();
110
+ };
111
+ validators.push(mw);
112
+ }
105
113
  }
106
114
  }
107
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/zod-openapi",
3
- "version": "0.15.2",
3
+ "version": "0.15.3",
4
4
  "description": "A wrapper class of Hono which supports OpenAPI.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",