Skip to content

Failed to load external schema from reference #855

@YaroslavBurlakaLS

Description

@YaroslavBurlakaLS

Using 1.0.86 version of validator

So, I have a json schema, and I want to describe the "seoData" object from this schema in a separate schema file (SeoDataSchema.json), that is placed in a "commonSchemaTemplates" folder on the same level as main schema

Main schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"header": {
"type": "object",
"properties": {
"requestId": {
"type": "string"
},
"version": {
"type": "string"
},
"serverTime": {
"type": "string"
},
"versionApi": {
"type": "string"
},
"viewType": {
"type": "string"
},
"sourceUid": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"requestId",
"version",
"serverTime",
"versionApi",
"viewType"
]
},
"seoData": {
"$ref": "file://./commonSchemaTemplates/SeoDataSchema.json#/definitions/seo"
}
},
"additionalProperties": false,
"required": [
"header"
]
}

And SeoDataSchema.json:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"definitions": {
"seo": {
"type": "object",
"properties": {
"metaTitle": {
"type": "string"
},
"info": {
"type": "string"
},
"metaDescriptionq": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"metaDescriptionq"
]
}
}
}

When I'm trying to validate a json file against the main schema, I'm receiving the following error from networknt json schema validator:
Failed to load json schema!
java.net.UnknownHostException: .
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:229)
at java.base/java.net.Socket.connect(Socket.java:608)
at java.base/sun.net.ftp.impl.FtpClient.doConnect(FtpClient.java:1063)
at java.base/sun.net.ftp.impl.FtpClient.tryConnect(FtpClient.java:1025)
at java.base/sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1120)
at java.base/sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1106)
at java.base/sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:312)
at java.base/sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:418)
at com.networknt.schema.uri.URLFetcher.openConnectionCheckRedirects(URLFetcher.java:57)
at com.networknt.schema.uri.URLFetcher.fetch(URLFetcher.java:43)
at com.networknt.schema.uri.URISchemeFetcher.fetch(URISchemeFetcher.java:50)
at com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:424)
at com.networknt.schema.RefValidator.getRefSchema(RefValidator.java:84)
at com.networknt.schema.RefValidator.(RefValidator.java:43)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.networknt.schema.ValidatorTypeCode.newValidator(ValidatorTypeCode.java:162)
at com.networknt.schema.JsonMetaSchema.newValidator(JsonMetaSchema.java:278)
at com.networknt.schema.ValidationContext.newValidator(ValidationContext.java:63)
at com.networknt.schema.JsonSchema.read(JsonSchema.java:295)
at com.networknt.schema.JsonSchema.getValidators(JsonSchema.java:615)
at com.networknt.schema.JsonSchema.validate(JsonSchema.java:388)
at com.networknt.schema.PropertiesValidator.validate(PropertiesValidator.java:71)
at com.networknt.schema.JsonSchema.validate(JsonSchema.java:393)
at com.networknt.schema.BaseJsonValidator.validate(BaseJsonValidator.java:115)

Also, I've tried to specify reference like this:
"seoData": {
"$ref": "./commonSchemaTemplates/SeoDataSchema.json#/definitions/seo"
}

In this case, I have a following error:
Caused by: com.networknt.schema.JsonSchemaException: #/properties/seoData/$ref: Reference ./commonSchemaTemplates/SeoDataSchema.json#/definitions/seo cannot be resolved
at com.networknt.schema.RefValidator.

I figured out the only way to make it work is to specify absolute (full) path to external schema, which is not really good approach
What could be wrong ?
May'be I'm incorrectly specifying the relative path to external schema ?

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