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

feat: add header validation utilities #25

Merged
merged 2 commits into from
Oct 21, 2024
Merged

feat: add header validation utilities #25

merged 2 commits into from
Oct 21, 2024

Conversation

mrnagydavid
Copy link
Contributor

In this PR, I added header validation utilities in the shape of:

  • validateRequest.headers using JOI
  • validateHeaders using JsonSchema

One potentially unexpected effect of these functions is
that they will produce lowercase headers (as the standard dictates)
since they rely on req.headers which contains lowercase keys.

Comment on lines +57 to +58
numeric: jsonSchema.string(),
bool: jsonSchema.string(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JsonSchema offers no casting or I didn't find it.

objectSchema<any>({
shortstring: stringSchema.min(8).max(16),
numeric: numberSchema,
bool: stringSchema,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The booleanSchema does no casting, it simply screams in horror when it sees a string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't believe it so I had to test myself, and indeed, you're right!

@mrnagydavid mrnagydavid marked this pull request as ready for review October 21, 2024 13:05
objectSchema<any>({
shortstring: stringSchema.min(8).max(16),
numeric: numberSchema,
bool: stringSchema,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't believe it so I had to test myself, and indeed, you're right!

@kirillgroshkov kirillgroshkov merged commit ac1e459 into master Oct 21, 2024
1 check passed
@kirillgroshkov kirillgroshkov deleted the DEV-19562 branch October 21, 2024 13:58
Copy link

🎉 This PR is included in version 5.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants