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

$ref to relative path does not work with "./file.json" #249

Open
mehdijouan opened this issue Jan 8, 2018 · 2 comments
Open

$ref to relative path does not work with "./file.json" #249

mehdijouan opened this issue Jan 8, 2018 · 2 comments

Comments

@mehdijouan
Copy link

Hello,

I would like to get your point on an issue I face when validating two schemas with a reference, from one to the other.

I have two schemes

  • An address.json
  • A card.json that refers to the address.json

When trying to validate the schemes, I get the following error:

   [ {
     "level" : "error",
     "message" : "URI \"./address.json\" is not normalized",
     "domain" : "syntax",
     "schema" : {
       "loadingURI" : "#",
       "pointer" : "/properties/addresses/items"
     },
     "keyword" : "$ref",
     "value" : "./address.json"
   } ]

From my understanding of the json schema spec, a relative path should be accepted.
What do you think about it?

The address.json is as following:

{
   "$schema": "http://json-schema.org/draft-06/schema#",
   "description": "An address",
   "type": "object",
   "properties": {
      "post-office-box": {
         "type": "string"
      },
      "extended-address": {
         "type": "string"
      },
      "street-address": {
         "type": "string"
      },
      "locality": {
         "type": "string"
      },
      "region": {
         "type": "string"
      },
      "postal-code": {
         "type": "string"
      },
      "country-name": {
         "type": "string"
      }
   },
   "required": [
      "locality",
      "region",
      "country-name"
   ],
   "dependencies": {
      "post-office-box": [
         "street-address"
      ],
      "extended-address": [
         "street-address"
      ]
   }
}

The card.json file is as following:

{
   "$schema": "http://json-schema.org/draft-06/schema#",
   "description": "A representation of a person, company, organization, or place",
   "type": "object",
   "required": [
      "familyName",
      "givenName"
   ],
   "properties": {
      "familyName": {
         "type": "string"
      },
      "givenName": {
         "type": "string"
      },
      "nickname": {
         "type": "string"
      },
      "addresses": {
         "type": "array",
         "items": {
            "$ref": "./address.json"
         }
      }
   }
}
@trein
Copy link

trein commented Aug 28, 2018

I'm facing similar issue.

@russgold
Copy link

russgold commented Oct 4, 2018

I'm running into the same issue, and have a thought. How does the validator know the file location of the top-level schema?

That is, I am loading my schema with the following code:

JsonNode schema = new JsonNodeReader()
.fromInputStream(getClass().getResourceAsStream("/schema/domain.json"));

I assume that you guys are doing something similar? But if the Json node reader is just reading from an InputStream or Reader, the location of the original file is lost - so how could relative urls possibly work?

That suggests that, in order to make this work, the node reader must take a file path - or else some pre-processing is needed in order to merge the nested schemas.

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

3 participants