brandur / json_schema

A JSON Schema V4 and Hyperschema V4 parser and validator.
MIT License
230 stars 45 forks source link

Add a failing test case for type (string, null) + enum #54

Closed valscion closed 8 years ago

valscion commented 8 years ago

If I have understood correctly, JSON schema defines a type validator to pass if any of the types in the array pass. This gem however fails when the type is ["string", "null"] and also the enum property is defined with no explicit null value.

Funnily enough, this case passes the test:

it "validates type with enum successfully" do
  pointer("#/definitions/app/definitions/visibility").merge!(
    "type" => ["string", "null"],
    "enum" => ["private", "public", nil]
  )
  data_sample["visibility"] = nil
  assert validate
end

Seems like if the enum array also has an explicit null in there, it is the only way to get an optional enum value to pass.

I guess this issue might've been resolved by #13 already if that was done.

valscion commented 8 years ago

Oh wait, seems like I might've misunderstood the enum type. It seems to be a validation for any instance type, not just a string. So everything IS working correctly here. Sorry :sweat_smile: and thanks for this great gem!

brandur commented 8 years ago

NP! Thanks for taking a shot at this. And yes, I need to get around to finishing #13. I'm sure there's some outlying problems that it would dredge up.