sylvainlaurent / yaml-json-validator-maven-plugin

A maven plugin to check that YAML and JSON files are well formed and optionally valid against JSON schemas
Apache License 2.0
22 stars 14 forks source link

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

Open bFollon opened 3 years ago

bFollon commented 3 years ago

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.

sylvainlaurent commented 3 years ago

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 ...