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

Nested additionalProperties isn't respected #109

Closed
LinusU opened this issue Feb 16, 2016 · 4 comments
Closed

Nested additionalProperties isn't respected #109

LinusU opened this issue Feb 16, 2016 · 4 comments

Comments

@LinusU
Copy link
Collaborator

LinusU commented Feb 16, 2016

Example schema:

{
  type: 'object',
  properties: {
    data: {
      type: 'object',
      additionalProperties: true
    }
  },
  required: [
    'data'
  ],
  additionalProperties: false,
  $schema: 'http://json-schema.org/draft-04/schema#'
}

Example data:

{
  "data": {
    "test": "I should be allowed!"
  }
}

This is rejected by is-my-json-valid with the following error:

[ { field: 'data', message: 'has additional properties' } ]
@LinusU
Copy link
Collaborator Author

LinusU commented Feb 16, 2016

Okay, it turns out that I was a bit off, guess that's what I guess for jumping to conclusions to fast.

The problem was that the object I validated actually looked like this:

{
  "id": "0ebcd4bb-a721-46b6-bcb8-85276fbc75f3",
  "data": {
    "test": "I should be allowed!"
  }
}

So the real problem seems to be that the field get's reported as data instead of id...

@LinusU
Copy link
Collaborator Author

LinusU commented Feb 16, 2016

Also, the following schema:

{
  type: 'object',
  properties: {},
  additionalProperties: false,
  $schema: 'http://json-schema.org/draft-04/schema#'
}

with the same data:

{
  "id": "0ebcd4bb-a721-46b6-bcb8-85276fbc75f3",
  "data": {
    "test": "I should be allowed!"
  }
}

Gives to errors with the same field:

[ { field: 'data', message: 'has additional properties' },
  { field: 'data', message: 'has additional properties' } ]

@LinusU
Copy link
Collaborator Author

LinusU commented Feb 16, 2016

Okay, I'm just spewing out confusion today 😆

The problem has nothing to do with my field named data. Rather, is-my-json-valid names the root to data. I do feel that this is very confusing though.

I wouldn't actually have found myself in this situation if either one of #84 or #102 would have been implemented, so I'm going to close this one in favour of those.

If anyone read this, thank you for your time, hopefully it provided some amusement :)

@LinusU LinusU closed this as completed Feb 16, 2016
@mafintosh
Copy link
Owner

@LinusU haha no worries

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