JSON schema resolving $ref by $id

I can't resolve schema documents by $id.

Using

IntelliJ Ultimate
JSON draft-07

 

Per the docs: https://tools.ietf.org/html/draft-handrews-json-schema-01#section-8.3

An object schema with a "$ref" property MUST be interpreted as a
"$ref" reference. The value of the "$ref" property MUST be a URI Reference. Resolved against the current URI base, it identifies the URI of a schema to use. All other properties in a "$ref" object MUST be ignored. The URI is not a network locator, only an identifier. A schema need
not be downloadable from the address if it is a network-addressable URL, and implementations SHOULD NOT assume they should perform a network operation when they encounter a network-addressable URI.

 

It says implementations should not assume they are network addressable. 

I'm following JSON schema conventions and all my schemas are id'd respectively:

 

"$id" : "http://com.company/schemas/base.schema.json"
--
"$id" : "http://com.company/schemas/other/other.schema.json"

However, when using a "$ref" statement it doesn't throw an error or include the schema for validating or show a warning or anything. It just simply doesn't do anything.

For example:

Assume project tree:

C:\Project\schemas\
`----base.schema.json
`----shared-defs.json
`----other\
`----other.schema.json
`----example.schema.json

I call it with the following and nothing happens:

"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://com.company/schemas/base.schema.json",
"type" : "object",
"properties" : {
"allOf" : [
{
"$ref" : "http://com.company/schemas/other/other.schema.json"
},
{
"$ref" : "http://com.company/schemas/other/example.schema.json"
}
]
}

How to reference another schema by $id property and it validate?

FYI, I know about relative path association, that is not my goal. I want to reference by $id so I can ensure I'm getting the proper file regardless of scope.

2
3 comments

Thanks a lot for the report. You're right, currently we don't resolve schemas by IDs locally if those IDs look like URLs.

I created a new ticket: https://youtrack.jetbrains.com/issue/WEB-39208, feel free to upvote to track its status.

2

Thank you Anton,

 

Please note this is not Webstorm specific, when I created this issue it automatically sent it to Webstorm. I have tried editing it to IntelliJ general specific but it changed it back to webstorm? I may be doing something wrong, but I am using IntelliJ ultimate as noted above

0

Some subsystems are historically located in the projects where their owners reside. JSON and YAML are such examples, located in WEB and RUBY despite being part of IntelliJ project.

Don't worry about the particular project where such issues are created, we sort and reassign them ourselves, anyway.

0

Please sign in to leave a comment.