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: lowercase type-providers headers types #4928
fix: lowercase type-providers headers types #4928
Conversation
Thanks for opening a PR! Can you please add a unit test? We use tsd for types. |
Hi @mcollina! Of course, I've just added a few test cases targeting request headers types. Extra pointI've realised that user provided route schemas can set headers value to any value even though headers can only be of type Shall we consider tackling this issue in another PR to try and set request header types different then Cheers! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
I'm not sure I understand this, maybe open an issue first, or you can do a PR and talk there. |
Yeah the last point can be an issue, as there imho is no casting in place. The values will be imho just tested if they pass the schema validation. So if you type a header as number you can expect that the value can be casted to a number, but is still a string. Well that is what i know so far. |
Yep, good point @Uzlopak :) |
Ajv will internally cast it to a number. If it can be casted it will pass. Fastify sets an option of ajv by default to cast the values. But they are only casted for the validation. It will not pass the casted values to the request. So there will be issues... |
Ah, seems like a bummer, how should we address that? Leave things as is? |
Nope:
|
well, then this PR is ready for merging |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [fastify](https://www.fastify.io/) ([source](https://togithub.com/fastify/fastify)) | [`4.20.0` -> `4.21.0`](https://renovatebot.com/diffs/npm/fastify/4.20.0/4.21.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/fastify/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/fastify/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/fastify/4.20.0/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/fastify/4.20.0/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>fastify/fastify (fastify)</summary> ### [`v4.21.0`](https://togithub.com/fastify/fastify/releases/tag/v4.21.0) [Compare Source](https://togithub.com/fastify/fastify/compare/v4.20.0...v4.21.0) #### What's Changed - chore: remove license-checker package by [@​Uzlopak](https://togithub.com/Uzlopak) in [fastify/fastify#4914 - chore: remove pump devDependency by [@​Uzlopak](https://togithub.com/Uzlopak) in [fastify/fastify#4913 - ci: create artifacts in coverage workflows by [@​Uzlopak](https://togithub.com/Uzlopak) in [fastify/fastify#4909 - docs(server): grammar and structure fixes by [@​Fdawgs](https://togithub.com/Fdawgs) in [fastify/fastify#4904 - docs: Fix typo in TypeScript docs ("[@​types/node](https://togithub.com/types/node)", not "[@​node/types](https://togithub.com/node/types)") by [@​jasongwartz](https://togithub.com/jasongwartz) in [fastify/fastify#4922 - \[readme] add CII Best Practices Badge by [@​ljharb](https://togithub.com/ljharb) in [fastify/fastify#4926 - fix: lowercase type-providers headers types by [@​toomuchdesign](https://togithub.com/toomuchdesign) in [fastify/fastify#4928 - ERR_REP_ALREADY_SENT hint that a route may be missing "return reply" by [@​mcollina](https://togithub.com/mcollina) in [fastify/fastify#4921 - fix: ReplyTypeConstrainer array type inference by [@​pedroescumalha](https://togithub.com/pedroescumalha) in [fastify/fastify#4885 #### New Contributors - [@​jasongwartz](https://togithub.com/jasongwartz) made their first contribution in [fastify/fastify#4922 - [@​ljharb](https://togithub.com/ljharb) made their first contribution in [fastify/fastify#4926 - [@​toomuchdesign](https://togithub.com/toomuchdesign) made their first contribution in [fastify/fastify#4928 - [@​pedroescumalha](https://togithub.com/pedroescumalha) made their first contribution in [fastify/fastify#4885 **Full Changelog**: fastify/fastify@v4.20.0...v4.21.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/tomacheese/telcheck). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yNC4yIiwidXBkYXRlZEluVmVyIjoiMzYuMjQuMiIsInRhcmdldEJyYW5jaCI6Im1hc3RlciJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [fastify](https://www.fastify.io/) ([source](https://togithub.com/fastify/fastify)) | [`4.20.0` -> `4.21.0`](https://renovatebot.com/diffs/npm/fastify/4.20.0/4.21.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/fastify/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/fastify/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/fastify/4.20.0/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/fastify/4.20.0/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>fastify/fastify (fastify)</summary> ### [`v4.21.0`](https://togithub.com/fastify/fastify/releases/tag/v4.21.0) [Compare Source](https://togithub.com/fastify/fastify/compare/v4.20.0...v4.21.0) #### What's Changed - chore: remove license-checker package by [@​Uzlopak](https://togithub.com/Uzlopak) in [fastify/fastify#4914 - chore: remove pump devDependency by [@​Uzlopak](https://togithub.com/Uzlopak) in [fastify/fastify#4913 - ci: create artifacts in coverage workflows by [@​Uzlopak](https://togithub.com/Uzlopak) in [fastify/fastify#4909 - docs(server): grammar and structure fixes by [@​Fdawgs](https://togithub.com/Fdawgs) in [fastify/fastify#4904 - docs: Fix typo in TypeScript docs ("[@​types/node](https://togithub.com/types/node)", not "[@​node/types](https://togithub.com/node/types)") by [@​jasongwartz](https://togithub.com/jasongwartz) in [fastify/fastify#4922 - \[readme] add CII Best Practices Badge by [@​ljharb](https://togithub.com/ljharb) in [fastify/fastify#4926 - fix: lowercase type-providers headers types by [@​toomuchdesign](https://togithub.com/toomuchdesign) in [fastify/fastify#4928 - ERR_REP_ALREADY_SENT hint that a route may be missing "return reply" by [@​mcollina](https://togithub.com/mcollina) in [fastify/fastify#4921 - fix: ReplyTypeConstrainer array type inference by [@​pedroescumalha](https://togithub.com/pedroescumalha) in [fastify/fastify#4885 #### New Contributors - [@​jasongwartz](https://togithub.com/jasongwartz) made their first contribution in [fastify/fastify#4922 - [@​ljharb](https://togithub.com/ljharb) made their first contribution in [fastify/fastify#4926 - [@​toomuchdesign](https://togithub.com/toomuchdesign) made their first contribution in [fastify/fastify#4928 - [@​pedroescumalha](https://togithub.com/pedroescumalha) made their first contribution in [fastify/fastify#4885 **Full Changelog**: fastify/fastify@v4.20.0...v4.21.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/redwoodjs/redwood). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yNy4xIiwidXBkYXRlZEluVmVyIjoiMzYuMjcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
As far as I understand, Fastify converts request headers to lowercase, while Fastify type provider seems to pass down to the type provider libraries the headers with the same casing provided in the route handler schemas.
Here is an example:
This PR is an attempt to align Fastify type provider types with the actual Fastify implementation. Where:
Technically speaking we might maybe considering typing the original uppercase version of the header as
undefined
but it would be probably too much :)The case conversion happens on the types returned by the type provider libraries, therefore it should be transparent to them.
Open points
Happy to review this PR based on your suggestions!
Thank you!
Checklist
npm run test
andnpm run benchmark
and the Code of conduct