Skip to content

Clarification of "$ref" as a root property referring to "definitions" defined in the same object #479

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

Closed
jimmylewis opened this issue Nov 7, 2017 · 3 comments

Comments

@jimmylewis
Copy link

Is the following JSON schema valid?

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "$ref": "#/definitions/myObject",
  "definitions": {
    "myObject": {
      "type": "object"
    }
  }
}

In JSON Schema Draft 4, it refers to the JSON Reference draft, which says (emphasis mine):

The "$ref" string value contains a URI [RFC3986], which identifies
the location of the JSON value being referenced. It is an error
condition if the string value does not conform to URI syntax rules.
Any members other than "$ref" in a JSON Reference object SHALL be
ignored.

Similarly, in the latest JSON Schema draft, it says:

An object schema with a "$ref" property MUST be interpreted as a "$ref" reference. The value of the "$ref" property MUST be a URI Reference. Resolved against the current URI base, it identifies the URI of a schema to use. All other properties in a "$ref" object MUST be ignored.

However, in the JSON Schema test suite there is a test validating this very scenario.

How are these definitions reconciled? Using Visual Studio's validator, the schema is considered invalid because it ignores the "definitions" property, so the "$ref" doesn't resolve. Other validators seem to accept it as a valid schema. Which is the correct behavior?

@handrews
Copy link
Contributor

handrews commented Nov 8, 2017

@jimmylewis thanks! I agree with your (and Visual Studio's) behavior, so this looks like a bug in the test suite. Could you please file it on that repository so the maintainer there sees it? This repository is for issues and enhancements of the specification itself.

@handrews handrews closed this as completed Nov 8, 2017
@jimmylewis
Copy link
Author

Turns out this issue was already opened on the test repo. json-schema-org/JSON-Schema-Test-Suite#113

@handrews
Copy link
Contributor

handrews commented Nov 8, 2017

@jimmylewis so it is! I've been so focused on getting draft-07 out the door that I haven't been paying much attention to the other repos. I'll try to get this fixed as soon as I have a moment. It's not good to have conforming implementations failing the suite.

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