voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.53k stars 242 forks source link

oneOf and patternProperties validates incorrectly #291

Closed lengarvey closed 8 years ago

lengarvey commented 8 years ago

I would expect the following test to pass:

  def test_one_of_pattern_properties
    schema = {
      "$schema" => "http://json-schema.org/draft-04/schema#",
      "oneOf" => [
        {
          "patternProperties" => {
            "^([a-z_0-9])+$" => {
              "type": "object",
              "properties" => [
                "foo" => { "type" => "string", "enum" => ["bar", "hello"] }
              ]
            }
          }
        }
      ]
    }

    assert_valid schema, { "test_thing" => { "foo" => "bar" }}
    refute_valid schema, { "test_thing" => { "foo" => "no" }}
  end

It fails with:

# Running:

F

Finished in 0.004238s, 235.9452 runs/s, 471.8904 assertions/s.

  1) Failure:
OneOfTest#test_one_of_pattern_properties [test/test_one_of.rb:103]:
{"test_thing"=>{"foo"=>"no"}} should be invalid for schema:
{"$schema"=>"http://json-schema.org/draft-04/schema#", "oneOf"=>[{"patternProperties"=>{"^([a-z_0-9])+$"=>{:type=>"object", "properties"=>[{"foo"=>{"type"=>"string", "enum"=>["bar", "hello"]}}]}}}]}.
Expected [] to not be equal to [].

1 runs, 2 assertions, 1 failures, 0 errors, 0 skips

Is this a bug? or am I missing something with my schema?

lengarvey commented 8 years ago

Fairly sure I was mistaken here.