-
Notifications
You must be signed in to change notification settings - Fork 45
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 of required in nested object #57
Comments
Hi @panSarin! The Is it possible for you to assemble a schema/data sample that demonstrates the problem? I could probably give you a more clear answer then. |
Hi, I'm also having trouble with nested validations, although I'm not sure I would describe the problem as @panSarin . I have the following schema:
The following data is validated as correct by the gem, but it is missing the zip_code |
Hi @mrtibs2000, I think you may have forgotten a curly brace somewhere in your schema above (specifically, the closing brace for
Here's the {
"$schema": "http://json-schema.org/draft-04/schema#",
"id" : "http://localhost:3000/schemas/address.json",
"definitions": {
"address": {
"type": "object",
"properties": {
"line1": { "type": "string" },
"line2": { "type": "string" },
"line3": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string" },
"zip_code": { "type": "string" },
"phone_number": { "type": "string" }
},
"required": ["zip_code"]
}
},
"type": "object",
"properties": {
"from_address": { "$ref": "#/definitions/address" },
"to_address": { "$ref": "#/definitions/address" }
},
"required": ["from_address", "to_address"]
} |
Hi @brandur , Thanks for looking into this. I did have the right schema, I just didn't paste it properly here. The strange part is that when I have a Ruby script, it does work fine. It doesn't behave the same when I execute this from a Rails app. Here's what I have in my controller:
|
Hey @mrtibs2000, Based on the fact that the gem seems to be doing the right thing, it seems reasonable to conclude here that the inputs may not be making it there as we would hope. Can you throw a debugger into that |
Sorry to have wasted your time. I forgot to include this in my code: |
Oops, yep that one is a bit of a gotcha! Good to hear you fixed it though, On Tuesday, April 12, 2016, Tiberiu Motoc [email protected] wrote:
|
https://gist.github.com/panSarin/6a7efcdd503a315d21fcf38213d560cc And if my response looks like:
Problem is that if i run
on this response + object, it will pass because it doesnt check nested objects schema.
so i can call it with passing which nested element i want to validate too. So is it a bug , or i am missing something?;] |
Hey @panSarin, you definitely shouldn't have to hack it that far. The gem will validate nested properties just fine, so something must be a little off here. One thing I noticed in your schema is that although you have the |
Above valdiation for filters are not taking effect. If I do not send attribute_name still validation is success while it must fail What is worng here I am not able to understand with Draft3Validation ? |
@ssgaur Hey, there should probably be a check on this somewhere in here, but given that draft 4 had been the overwhelmingly preferred spec for so long when I wrote this, the project should largely be considered only usable for draft 4 and up. Given that draft 3 is quite dated at this point, it probably makes sense for you to write your schemas targeting a newer spec anyway. In 4, |
Hello . I wonder if I do something bad, or that is #TODO
Basically i have 2 definitons
1st is the definition of response that will return Hash in JSON
2nd is the defintion of elements in Hash - that definition containst required section that define which fields in each object in hash should be displayed there. And basically if i pass my whole schema to compare it with whole response from API that validation of required won't work. I debugged json_schema gem a little , and checked that schema object in
So do i do something wrong in my .json schema , or maybe i can;'t use validation on such lvl, and i have to use it like
The text was updated successfully, but these errors were encountered: