Skip to content

Using $ref with Relative Path #920

@akuzin1

Description

@akuzin1

I am attempting to use $ref as part of a schema, in order to reference a repetitive schema definition in a separate file within the same directory.
However, after trying multiple path variations I still continue to receive a com.networknt.schema.JsonSchemaException: java.io.IOException stating that the "Resource common-definitions.json not found in classpath"

Main Schema

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "required" : ["DriverProperties"],
    "properties": {
        "DriverProperties": {
            "type": "object",
            "properties": {
                "CommonProperties": {
                    "$ref": "common-definitions.json#/definitions/DriverProperties"
                }
            },
            "required": ["CommonProperties"]
            "additionalProperties": false
        }
    },
    "additionalProperties": false
}

common-defintions.json:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "additionalProperties": false,
    "definitions": {
        "DriverProperties": {
            "type": "object",
            "properties": {
                "field1": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 512
                },
                "field2": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 512
                }
            },
            "required": ["field1"],
            "additionalProperties": false
        }
    }
}

Whenever I input the absolute path, referencing the external definition works. However, I want this to work on any machine, so I want to define the classpath relatively.
Any recommendations would be greatly appreciated.
Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions