@hono/zod-openapi 0.15.2 → 0.16.0
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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +26 -18
- package/dist/index.mjs +26 -18
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -69,7 +69,7 @@ type StatusCodeRangeDefinitions = {
|
|
|
69
69
|
type RouteConfigStatusCode = keyof StatusCodeRangeDefinitions | StatusCode;
|
|
70
70
|
type ExtractStatusCode<T extends RouteConfigStatusCode> = T extends keyof StatusCodeRangeDefinitions ? StatusCodeRangeDefinitions[T] : T;
|
|
71
71
|
type RouteConfigToTypedResponse<R extends RouteConfig> = {
|
|
72
|
-
[Status in keyof R['responses'] & RouteConfigStatusCode]: IsJson<keyof R['responses'][Status]['content']> extends never ? TypedResponse<{}, ExtractStatusCode<Status>, string> : TypedResponse<JSONParsed<ExtractContent<R['responses'][Status]['content']>>, ExtractStatusCode<Status>, 'json'>;
|
|
72
|
+
[Status in keyof R['responses'] & RouteConfigStatusCode]: IsJson<keyof R['responses'][Status]['content']> extends never ? TypedResponse<{}, ExtractStatusCode<Status>, string> : TypedResponse<JSONParsed<ExtractContent<R['responses'][Status]['content']>>, ExtractStatusCode<Status>, 'json' | 'text'>;
|
|
73
73
|
}[keyof R['responses'] & RouteConfigStatusCode];
|
|
74
74
|
type Hook<T, E extends Env, P extends string, R> = (result: {
|
|
75
75
|
success: true;
|
package/dist/index.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ type StatusCodeRangeDefinitions = {
|
|
|
69
69
|
type RouteConfigStatusCode = keyof StatusCodeRangeDefinitions | StatusCode;
|
|
70
70
|
type ExtractStatusCode<T extends RouteConfigStatusCode> = T extends keyof StatusCodeRangeDefinitions ? StatusCodeRangeDefinitions[T] : T;
|
|
71
71
|
type RouteConfigToTypedResponse<R extends RouteConfig> = {
|
|
72
|
-
[Status in keyof R['responses'] & RouteConfigStatusCode]: IsJson<keyof R['responses'][Status]['content']> extends never ? TypedResponse<{}, ExtractStatusCode<Status>, string> : TypedResponse<JSONParsed<ExtractContent<R['responses'][Status]['content']>>, ExtractStatusCode<Status>, 'json'>;
|
|
72
|
+
[Status in keyof R['responses'] & RouteConfigStatusCode]: IsJson<keyof R['responses'][Status]['content']> extends never ? TypedResponse<{}, ExtractStatusCode<Status>, string> : TypedResponse<JSONParsed<ExtractContent<R['responses'][Status]['content']>>, ExtractStatusCode<Status>, 'json' | 'text'>;
|
|
73
73
|
}[keyof R['responses'] & RouteConfigStatusCode];
|
|
74
74
|
type Hook<T, E extends Env, P extends string, R> = (result: {
|
|
75
75
|
success: true;
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
c.req.addValidatedData("form", {});
|
|
109
|
+
await next();
|
|
110
|
+
};
|
|
111
|
+
validators.push(mw);
|
|
112
|
+
}
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
115
|
}
|