Skip to content

Commit

Permalink
Update zodValidationRequestHandler.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
inkognitro committed Sep 28, 2024
1 parent 1078e30 commit 441073d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/templates/ts/core/zodValidationRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ export class ZodValidationRequestHandler implements RequestHandler {
schemaProps['headers'] = schema.headersZodSchema;
}
const contentType = response.contentType;
if (!contentType || contentType.match(/multipart\/form-data;?.*/)) {
if (!contentType) {
return z.object(schemaProps).safeParse(response);
}
const bodyZodSchema = schema.bodyByContentType[contentType]?.zodSchema;
if (bodyZodSchema) {
schemaProps['body'] = bodyZodSchema;
response['body'] = await response.revealBody();
const body = await response.revealBody();
if (!(body instanceof FormData)) {
schemaProps['body'] = bodyZodSchema;
response['body'] = body;
}
}
return await z.object(schemaProps).safeParseAsync(response);
}
Expand Down

0 comments on commit 441073d

Please sign in to comment.