question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relative paths between definition files are not resolved

See original GitHub issue

Dear all,

first: thanks a lot for this great library, which enables me to use JSON schema validation during QM procedures in data management for JSON-based metadata!

I am struggling with an java.net.MalformedURLException: no protocol exception for a complex schema, which I am unable to resolve.

Given the following example root schema to reproduce my findings:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://myexample.org/example/example.schema.json",
    "type": "object",
    "properties": {
        "house": { "$ref": "definitions/buildings.json#/house" }
    }
}

Let’s say that the definitions are in a separate file in a subdir of the root schema’s location definitions.

{
    "house": {
        "type": "object",
        "properties": {
            "rooms": { 
                "type": "array",
                "items": { "$ref": "#/room" }
            }
        }
    },
    "room": {
        "type": "object",
        "properties": {
            "door" : { "$ref": "stuff.json#/door" }
        }
    }
}

And for the sake of modularity and structuring, the door property is defined in another json file:

{
    "door": {
        "type": "object",
        "properties": {
            "material": { "type": "string" }
        }
    }
}

Validating an example object (which should throw a validation error because material is not a String)

{
   "house": {
       "rooms": [ {
           "door": { "material": 1 }
       }]
   }
}

throws: Caused by: java.net.MalformedURLException: no protocol: stuff.json (Stack-trace: https://pastebin.com/rQip3Gmn).

I tried to set the default resolutions scope explicitly as well with the schema builder, but the issue remains.

So my question is: why is the relative path of buildings.json#/house resolved properly, but not stuff.json? Am I violating the JSON schema specification?

I am thankfully looking forward to any remarks/help!

Best, Sven

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
erosbcommented, Jan 21, 2019

Hello both,

I fixed the bug during the weekend and it will be included in the next release.

1reaction
erosbcommented, Jan 22, 2019

Hello, version 1.11.0 is out, including the fix. Thanks for the bugreport.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does Java resolve a relative path in new File()?
When the specified relative path is not found, the file seems to be created in the user.dir . So, it appears to me...
Read more >
Absolute and Relative Paths
The difference between an absolute path and a relative path. ... The target is in the same folder so indicate that with a...
Read more >
Relative and absolute paths, in the file system and on the web ...
The difference between absolute and relative paths · If the path is built starting from the system root, it is called absolute. ·...
Read more >
Paths explained: Absolute, relative, UNC, and URL—Help
Relative paths cannot span disk drives. That is, if the root directory is on drive D, you cannot use relative paths to navigate...
Read more >
Path (Java Platform SE 7 ) - Oracle Help Center
Constructs a relative path between this path and a given path. ... This method does not access the file system; the path or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found