Skip to content

Commit

Permalink
Properly validate query is specification
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy-Gonzalez committed Oct 13, 2024
1 parent 1d36c3a commit 8ffdacb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/middleware/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ export default function specification<
});
}
}

if (spec.query) {
const result = await spec.query.safeParseAsync(req.query);
if (!result.success) {
return res.status(StatusCode.ClientErrorBadRequest).json({
error: "BadRequest",
message: "Bad request made - invalid query format",
validationErrors: result.error.errors,
});
}
}

if (spec.body) {
const result = await spec.body.safeParseAsync(req.body);
if (!result.success) {
Expand Down

0 comments on commit 8ffdacb

Please sign in to comment.