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

some questions about addtionalproperties #112

Closed
WanliTian opened this issue Aug 1, 2014 · 2 comments
Closed

some questions about addtionalproperties #112

WanliTian opened this issue Aug 1, 2014 · 2 comments
Labels

Comments

@WanliTian
Copy link

  schema = {
    "$schema" => "http://json-schema.org/draft-03/schema#",
    "properties" => {
      "a" => {"type" => "string"},
      "b" => {"type" => "string"},
      "c" => {
        "type" => "object",
        "additionalProperties" => {
          "d" => {"type" => "string"}
        }
      }
    },
    "additionalProperties" => {"type" => "integer"}
  }

  data = {"a" => "a", "b" => "b", "c" => {"d" => "23", "f" => 32}}
  puts(JSON::Validator.validate(schema,data,:strict => true))

the result is true, is this right?

@hoxworth hoxworth added the Bug label Aug 3, 2014
@hoxworth
Copy link
Contributor

hoxworth commented Aug 3, 2014

If we are to consider just the JSON schema and validation against the spec, yes, this is correct. However, since you used the :strict => true option, this should probably be false. This may be a bug with regards to :strict; I'll take a look at this later.

@hoxworth
Copy link
Contributor

hoxworth commented Aug 3, 2014

Ack, I take that back - the schema you proposed is not officially a valid schema - the value of additionalProperties must be a valid schema, which in your case it is not. Try this schema:

  schema = {
    "$schema" => "http://json-schema.org/draft-03/schema#",
    "properties" => {
      "a" => {"type" => "string"},
      "b" => {"type" => "string"},
      "c" => {
        "type" => "object",
        "additionalProperties" => {
          "type" => "object",
          "properties" => {
            "d" => {"type" => "string"}
          }
        }
      }
    },
    "additionalProperties" => {"type" => "integer"}
  }

This will validate to false with your above example with :strict => true.

@hoxworth hoxworth closed this as completed Aug 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants