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

Schema nesting with id key is not validating as expected #270

Closed
pelted opened this issue Oct 31, 2015 · 2 comments
Closed

Schema nesting with id key is not validating as expected #270

pelted opened this issue Oct 31, 2015 · 2 comments

Comments

@pelted
Copy link

pelted commented Oct 31, 2015

Given the simple schema bellow it is expected to not validate because of the foo required key in the nested attributes object but it in fact does validate when the response does not contain foo.

Doing some digging, it appears the reason may have to do with the id property being returned in the response.

Schema

{
  "$schema": "http://json-schema.org/draft-04/hyper-schema",
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "required": ["id", "type", "attributes"],
      "properties": {
        "id" : { "type" : "string" },
        "type" : { "type" : "string" },
        "attributes" : { "type" : "object" }
      },
      "attributes": {
        "type": "object",
        "required": ["user_name", "email", "auth_token", "foo"]
      }
    }
  }
}

Response

{
  "data":{
    "id": "1",
    "type": "users",
    "attributes": {
      "user_name": "admin", 
      "email":"[email protected]"
    }
  }
}
@RST-J
Copy link
Contributor

RST-J commented Nov 2, 2015

I think you confuse the top level attributes property definition with the nested attributes within the data property.
Your response is valid w.r.t. to the schema because the only thing it requires for a property of name attributes within the data property is to be an object, which it is.

Your expectation would hold if you had a response like this:

{
  "data":{
    "id": "1",
    "type": "users"
  },
  "attributes": {
    "user_name": "admin", 
    "email":"[email protected]"
  }
}

@pelted
Copy link
Author

pelted commented Nov 2, 2015

Complete fail on my part it would appear. Many examples I found seem to show the schema nested properties outside of the object but your response pretty much cleared it all up for me. I wonder then if the new reference to #178 from 3 days ago is something similar.

@pelted pelted closed this as completed Nov 2, 2015
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