Skip to content

Commit 48436f2

Browse files
committedApr 15, 2024
fix(hono): handle correctly response validation empty
1 parent 39d9682 commit 48436f2

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed
 

‎packages/hono/src/index.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ ${
139139
? `zValidator('json', ${verbOption.operationName}Body),\n`
140140
: ''
141141
}${
142-
verbOption.response.contentTypes.length === 1 &&
143-
verbOption.response.contentTypes[0] === 'application/json'
142+
!!verbOption.response.originalSchema?.['200']?.content?.['application/json']
144143
? `zValidator('response', ${verbOption.operationName}Response),\n`
145144
: ''
146145
}(c: ${contextTypeName}) => {
@@ -169,8 +168,7 @@ const getZvalidatorImports = (verbOption: GeneratorVerbOptions) => {
169168
}
170169

171170
if (
172-
verbOption.response.contentTypes.length === 1 &&
173-
verbOption.response.contentTypes[0] === 'application/json'
171+
!!verbOption.response.originalSchema?.['200']?.content?.['application/json']
174172
) {
175173
imports.push(`${verbOption.operationName}Response`);
176174
}
@@ -201,17 +199,14 @@ const getHandlerFix = ({
201199
const getVerbOptionGroupByTag = (
202200
verbOptions: Record<string, GeneratorVerbOptions>,
203201
) => {
204-
return Object.values(verbOptions).reduce(
205-
(acc, value) => {
206-
const tag = value.tags[0];
207-
if (!acc[tag]) {
208-
acc[tag] = [];
209-
}
210-
acc[tag].push(value);
211-
return acc;
212-
},
213-
{} as Record<string, GeneratorVerbOptions[]>,
214-
);
202+
return Object.values(verbOptions).reduce((acc, value) => {
203+
const tag = value.tags[0];
204+
if (!acc[tag]) {
205+
acc[tag] = [];
206+
}
207+
acc[tag].push(value);
208+
return acc;
209+
}, {} as Record<string, GeneratorVerbOptions[]>);
215210
};
216211

217212
const generateHandlers = async (

0 commit comments

Comments
 (0)
Please sign in to comment.