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

additionalProperties and $ref are not working together #185

Closed
tuberlinapp opened this issue Nov 25, 2014 · 6 comments
Closed

additionalProperties and $ref are not working together #185

tuberlinapp opened this issue Nov 25, 2014 · 6 comments

Comments

@tuberlinapp
Copy link

I have a schema file (Thing.schema) which is referencing to another file (ID.schema).
When I set inside of Thing.schema - "additionalProperties": false - at the top of the nest, the reference to the other schema file will not be resolved against the URI of the current schema. And so the error message is:
The property '#/' contains additional properties ["type"] outside of the schema when none are allowed in schema http://DOMAIN.com/Thing.schema#

ID.schema

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "http://DOMAIN.com/ID.schema#",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "type": {
            "type": "string",
            "additionalProperties": false
        }
    }
}

ID data

{
    "type": "JSON"
}

Validation is correct on: ID against ID.schema

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "http://DOMAIN.com/Thing.schema#",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "$ref": "http://DOMAIN.com/ID.schema#",
        "name": {
            "type": "string",
            "additionalProperties": false
        }
    }
}
{
    "type": "json",
    "name": "JSON Schema Draft 4"
}

Error message: The property '#/' contains additional properties ["type"] outside of the schema when none are allowed in schema http://DOMAIN.com/Thing.schema#

Inside the draft explaination: http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.28 the URI should be resolved first and validated after. Or am I am wrong?

@pd
Copy link
Contributor

pd commented Nov 28, 2014

Your second schema is actually invalid; see additionalProperties, properties, and patternProperties in draft4. The $ref property you've added is actually saying your "thing" object should itself have a $ref property in it, but then the value you've specified is invalid because it should be another JSON schema object:

The value of "properties" MUST be an object. Each value of this object MUST be an object, and each object MUST be a valid JSON Schema.

In this case, I think you are looking for what draft3 provided via extends, or in draft4 can be accomplished with allOf:

{
  "type": "object",
  "allOf": [
    { "$ref": "http://example.com/id.schema#" },
    {
      "type": "object",
      "properties": { "name": { "type": "string" } }
    }
  ]
}

(Typed directly into github so forgive typos and such =)

Btw, when developing schemas, it's typically helpful to always run them with validate_schema: true turned on, so that you can find bugs in your schemas themselves.

Hope that helps!

@pd pd closed this as completed Nov 28, 2014
@tuberlinapp
Copy link
Author

Thank you pd,

I was taking a closer look and I think what I need is „$merge“ from the proposal v5.

  1. I need to describe a schema where some types are optional, but no type can be added
  2. I need to extend this schema with other types where are also some of them are optional and the other don’t

If you have a branch for v5 I really would be some of the new tester.

@RST-J
Copy link
Contributor

RST-J commented Dec 3, 2014

Yes, $merge would allow to model type hierarchies with reuse, I also missed that already.
For v5, is there any schedule?

@hoxworth
Copy link
Contributor

hoxworth commented Dec 3, 2014

I don't believe there is anything set in stone. There was a push around May to get the draft out, but that apparently stalled. There also isn't much news on the roadmap for actual ratification beyond drafts...

@iainbeeston
Copy link
Contributor

I don't think there would be any harm to defining a v5 schema in json-schema, but personally I wouldn't choose to spend any time on it until the draft is published.=

@RST-J
Copy link
Contributor

RST-J commented Dec 3, 2014

Dito

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

5 participants