Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): corrected the validation function #24

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/core/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ export function describeRoute<
if (status && contentType) {
const response = specs.responses[status];
if (response && "content" in response && response.content) {
const content = response.content[contentType];
const splitedContentType = contentType.split(";")[0];
const content = response.content[splitedContentType];

if (content?.schema && "validator" in content.schema) {
try {
await content.schema.validator(c.res.body);
let data: unknown;

if (splitedContentType === "application/json") {
data = await c.res.json();
} else if (splitedContentType === "text/plain") {
data = await c.res.text();
}

if (!data) throw new Error("No data to validate!");

await content.schema.validator(data);
} catch (error) {
throw new HTTPException(400, {
message: "Response validation failed!",
Expand Down