JSON Schema cannot resolve relative remote URLs

I am trying to extend the JsonSchema.ProviderFactory extension point to pull in a remote schema and associate it with a file. The problem is that this remote schema uses relative $refs. For example, if my schema is at example.com/MyBaseSchema.json, it will include a ref like: "$ref": "MyOtherSchema.json". Now I know that that means it’s referencing example.com/MyOtherSchema.json but IntelliJ will only retrieve the MyBaseSchema.json file and not retrieve any referenced files.

My implementation is pretty straightforward:

private class SchemaProvider(
    private val name: String,
    private val schemaPath: String,
) : JsonSchemaFileProvider {
    private var virtualFile: VirtualFile? = null

    override fun isAvailable(file: VirtualFile): Boolean = file.name.startsWith("MyFileName")

    override fun getName(): @Nls String = name

    override fun getSchemaFile(): VirtualFile? {
        if (virtualFile != null && virtualFile!!.isValid) {
            return virtualFile
        }
        virtualFile = JsonFileResolver.urlToFile(schemaPath)
        return virtualFile
    }

    override fun getSchemaVersion(): JsonSchemaVersion? = JsonSchemaVersion.SCHEMA_7

    override fun isUserVisible(): Boolean = true

    override fun getPresentableName(): @ListItem String = "$name Schema"

    override fun getSchemaType(): SchemaType = SchemaType.embeddedSchema

    override fun getRemoteSource(): @NonNls String? = schemaPath
}

I’m passing in the base remote URL as the schemaPath.

I’ve tried:

  • switching up the SchemaType to remoteSchema
  • using the EmbeddedJsonSchemaFileProvider from the JavaScript module

Getting the relative $ref URLs in the schema file does not appear to be an option; my team doesn’t own them and the owners host them in different environments so they don’t want to maintain distinct absolute URL $refs in each (i.e. example-dev.com/MyBaseSchema.json).

How can I get IntelliJ to resolve these $refs such that it knows they are also located at the base URL?

1 Like