djabraham / vscode-yaml-validation

VSCode Language Extension vscode-yaml-validation
https://marketplace.visualstudio.com/items?itemName=djabraham.vscode-yaml-validation
MIT License
18 stars 6 forks source link

Does not find schemas referenced through relative paths #1

Closed benjamind closed 5 years ago

benjamind commented 7 years ago

If you are using local schemas (i.e. schemas defined locally in your workspace), and have a $ref from one schema to another using relative paths rather than absolute http urls, then the dependent schema fails to load.

The error message shown on the yaml file is:

Problems loading reference 'child-schema': Unable to load schema from 'child-schema': Unable to to connect to child-schema. Error: connect ECONNREFUSED 127.0.0.1:80

Here's the files to reproduce, put these in a folder and open in vscode.

.vscode/settings.json:

{
    "json.schemas": [
        {
            "fileMatch": [
                "/data/*.json",
                "/data/*.yaml"
            ],
            "url": "./schemas/parent-schema.json"
        }
    ]
}

data/test.yaml

id: 'foo'
child:
    name: 'bah'

schemas/parent-schema.json

{
    "id": "parent-schema.json",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "My Parent Schema",
    "properties": {
        "id": {
            "type": "string"
        },
        "child": {
            "$ref": "child-schema.json"
        }
    }
}

schemas/child-schema.json

{
    "id": "child-schema.json",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "My Child Schema",
    "properties": {
        "name": {
            "type": "string"
        }
    }
}
djabraham commented 7 years ago

Haven't had a chance to try this yet, but the # may be necessary. It also appears as thought they pushed a fix in the vscode repo for this.

    "child": {
        "$ref": "./child-schema.json#"
    }

https://github.com/Microsoft/vscode/commit/fb4d59aa39ed6d496f52857039ee570950dc612d

adamvoss commented 7 years ago

@benjamind vscode-yaml does not appear to be affected by this issue. Switching to that extension should resolve this issue for you.

djabraham commented 5 years ago

Closing, this extension was retired.