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

Validation not case sensitive for JSON keys #1

Closed
drasko opened this issue May 23, 2016 · 10 comments
Closed

Validation not case sensitive for JSON keys #1

drasko opened this issue May 23, 2016 · 10 comments

Comments

@drasko
Copy link

drasko commented May 23, 2016

Both {"name" : ...} and {"Name": ...} when Schema uses only capital "Name".

@4kochi
Copy link
Contributor

4kochi commented May 24, 2016

JSON schema is treating keys as case sensitive. When you send {"name" : ...} it will be ignored by the schema, because it only knows {"Name": ...}. Depending on the JSON schema validator you use one can define what should happen which such data.

@4kochi 4kochi closed this as completed May 24, 2016
@drasko
Copy link
Author

drasko commented May 24, 2016

@4kochi I saw that I was not clear enough (I typed in speed obviously).

SW should work as you described, and that is what I expected. However, there seems to be a bug, and both {"name" : ...} and {"Name": ...} are passing validation OK, even though for {"name" : ...} validation should fail (Schema is defined with ``{"Name" : ...}`, so capital 'N').

This is the bug I wanted to report, and it is vell described in the issue subject.

Please reopen the issue.

@4kochi
Copy link
Contributor

4kochi commented May 24, 2016

Maybe you can provide an example. But in JSON schema it is totally valid to send an object {"name" : ...} although in the schema {"Name" : ...} is defined. If "Name" is required, than it should return an error. The "name" is ignored.

You can test this with this site: http://jsonschemalint.com/draft4/#

Choose the sample "Sample schema and valid document". If you then change "bar": "a" to "Bar": "a", there will be no error.

@4kochi 4kochi reopened this May 24, 2016
@drasko
Copy link
Author

drasko commented May 24, 2016

Thanks, I will check and keep you posted.

My use case is that I have {"Name" : ...} in the Schema and it is required. However, sending {"name" : ...} via curl passes validation, when it should fail.

If both "bar": "a" and "Bar": "a" are passing validation, even though the Schema is "Bar": "a" - does that means that JSON Schema is not case sensitive?

@4kochi
Copy link
Contributor

4kochi commented May 24, 2016

JSON Schema is case sensitive. If {"Name" : ...} is required and you send {"name" : ...} then there should be an error. Can you please share your schema and data.

@drasko
Copy link
Author

drasko commented May 24, 2016

@4kochi Schema is here: https://github.com/Mainflux/mainflux-core-server/blob/master/app/models/deviceSchema.json and validaion code is here: https://github.com/Mainflux/mainflux-core-server/blob/master/app/controllers/devices.js#L44

Sending "name" via curl passes the validation and adds "name" : ... to my object (here: https://github.com/Mainflux/mainflux-core-server/blob/master/app/controllers/devices.js#L56), when it should actually initialize "Name" : ...

@4kochi
Copy link
Contributor

4kochi commented May 24, 2016

Ok, i found the problem. It was actually a problem with lx-valid. The required array you used in your schema "required": ["Name"] was not supported yet.

I released a new version 1.2.0 of lx-valid. Please check if its working now.

@4kochi 4kochi closed this as completed May 24, 2016
@drasko
Copy link
Author

drasko commented May 24, 2016

@4kochi good work!

I confirm that it works correctly now. Bug fixed.

Thanks!

@drasko
Copy link
Author

drasko commented May 24, 2016

One more question - what happens to non-required fields? They are not validated for being capital or lowercase, as I can see. Is this OK by the spec, or this has to be corrected also?

@drasko
Copy link
Author

drasko commented May 24, 2016

@4kochi I saw now that I opened the issue on the wrong project ;).

New issue opened here: litixsoft/lx-valid#15

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

No branches or pull requests

2 participants