yaml-json-validator-maven-plugin icon indicating copy to clipboard operation
yaml-json-validator-maven-plugin copied to clipboard

Cannot use $ref to other files in combination with `resource:`

Open bFollon opened this issue 5 years ago • 1 comments

Hi,

I'm trying to validate a schema that has references to another file like so:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "id": "resource:/dev/schemas/my-schema.json#",
    "properties": {
        "thisIsAProperty": {
            "type": "string"   
        },
        "anotherProperty": { "$ref": "anotherSchema.json#/myObj" }
    }
}

The anotherSchema.json schema contains the following:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "myObj": {
        "properties": {
            "thirdProperty": {
                "type": "string"   
            }
        }
    }
}

Both files are located under src/main/resource/dev/schemas.

When running the plugin I get:

[WARNING] fatal: unable to dereference URI "resource:/dev/schemas/endpoint.schema.json#"
    level: "fatal"
    uri: "resource:/dev/schemas/anotherSchema.json#"
    exceptionMessage: "resource /dev/schemas/anotherSchema.json not found"

I've tried many options and only managed to make it work using file: with the absolute path to the file.

bFollon avatar Sep 24 '20 15:09 bFollon

I'm not sure where "resource:" scheme is coming from? If both schemas are in the same folder, I think you don't need the "id" field at all. FYI, this plugin just makes use of https://github.com/java-json-tools/json-schema-validator ...

sylvainlaurent avatar Nov 24 '20 21:11 sylvainlaurent