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

Validate parameters name in a case insensitive way #927

Closed
StefanoTesla opened this issue Aug 28, 2023 · 2 comments
Closed

Validate parameters name in a case insensitive way #927

StefanoTesla opened this issue Aug 28, 2023 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@StefanoTesla
Copy link

I need a little help to validate the presence of a parameter in an uncase sensitive way.

At the moment my schema is this one.
Everything is working fine, but my api protocol provide that the parameters validation should be case insensitive so I should accept olso clIENTid pr clientid or CLIENTID or any way to write clientid wito lower and uppercase.

How can I do? should I use an Hook and cycle over all the parameters name and converting them in lowercase?

const querySchema = { type: 'object', properties: { ClientID: { type: 'number' }, ClientTransactionID: { type: 'number' } }, required: ['ClientID', 'ClientTransactionID'] };

@StefanoTesla StefanoTesla added the help wanted Extra attention is needed label Aug 28, 2023
@metcoder95
Copy link
Member

The RFC-3986, is kind of ambiguous as does not specifies if the key of the key=value pairs should be case sensitive or not, so it is up to each implementation to decide how to handle it.

You can use the patternProperties feature from ajv to construct a regex that covers both cases of your properties (i.e. either clientid or clientId, etc.).

Another option is to use the preValidation hook to intercept the request before validation and parse your query object to a lower (or upper) case version of it.

@simoneb
Copy link

simoneb commented Jun 7, 2024

Can this be closed? It looks like the above answers provides at least a couple of options

@Eomm Eomm closed this as completed Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants