Vscode-yaml: Problems with OpenAPI yaml files

Created on 23 Aug 2019  路  14Comments  路  Source: redhat-developer/vscode-yaml

Problems on version 0.5.1 and 0.5.0, when working with openapi yaml files.

I have used one of the openapi examples. File can be seen here

I'm getting errors such as:

String is not a URI: [UriError]: Scheme is missing: {scheme: "", authority: "", path: "", query: "", fragment: "/components/schemas/Pets"}

This is happening on each line with a reference for schema starting with a #.

$ref: "#/components/schemas/Pets"

It appears to me that this version does not honor #, while in 0.4.1 I didn't have these problems.

bug

Most helpful comment

The fix for this will be available in the next release

All 14 comments

Can you give some steps on how to reproduce?

When I open a folder and then paste in that YAML file it doesn't show any errors.

Are you open in a single root workspace? or a multi root workspace? or no workspace at all?

Can you also try setting "yaml.trace.server": "verbose" in your preferences and then paste the output logs that are found when you select YAML Support in the output panel:
image

With or without workspace, pasting the example OpenAPI file from here into vscode produces ese errors.

Here is the output with "yaml.trace.server": "verbose"

[Trace - 1:17:51 PM] Sending notification '$/setTraceNotification'.
Params: {
    "value": "verbose"
}


[Trace - 1:17:51 PM] Sending notification 'workspace/didChangeConfiguration'.
Params: {
    "settings": {
        "yaml": {
            "trace": {
                "server": "verbose"
            },
            "schemas": {},
            "format": {
                "enable": true,
                "singleQuote": false,
                "bracketSpacing": true,
                "proseWrap": "preserve",
                "printWidth": 80
            },
            "validate": true,
            "hover": true,
            "completion": true,
            "customTags": [],
            "schemaStore": {
                "enable": true
            }
        },
        "http": {
            "proxyStrictSSL": true
        }
    }
}


[Trace - 1:17:51 PM] Sending notification 'workspace/didChangeWatchedFiles'.
Params: {
    "changes": [
        {
            "uri": "file:///home/neta/.config/Code%20-%20OSS/User/settings.json",
            "type": 2
        },
        {
            "uri": "vscode-userdata:/home/neta/.config/Code%20-%20OSS/User/settings.json",
            "type": 2
        },
        {
            "uri": "file:///home/neta/.config/Code%20-%20OSS/User/settings.json",
            "type": 2
        },
        {
            "uri": "vscode-userdata:/home/neta/.config/Code%20-%20OSS/User/settings.json",
            "type": 2
        }
    ]
}


[Trace - 1:17:51 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///home/neta/openapi.yaml",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 40,
                    "character": 22
                },
                "end": {
                    "line": 40,
                    "character": 50
                }
            },
            "message": "String is not a URI: [UriError]: Scheme is missing: {scheme: \"\", authority: \"\", path: \"\", query: \"\", fragment: \"/components/schemas/Error\"}",
            "severity": 1
        },
        {
            "range": {
                "start": {
                    "line": 34,
                    "character": 22
                },
                "end": {
                    "line": 34,
                    "character": 49
                }
            },
            "message": "String is not a URI: [UriError]: Scheme is missing: {scheme: \"\", authority: \"\", path: \"\", query: \"\", fragment: \"/components/schemas/Pets\"}",
            "severity": 1
        },
        {
            "range": {
                "start": {
                    "line": 54,
                    "character": 22
                },
                "end": {
                    "line": 54,
                    "character": 50
                }
            },
            "message": "String is not a URI: [UriError]: Scheme is missing: {scheme: \"\", authority: \"\", path: \"\", query: \"\", fragment: \"/components/schemas/Error\"}",
            "severity": 1
        },
        {
            "range": {
                "start": {
                    "line": 80,
                    "character": 22
                },
                "end": {
                    "line": 80,
                    "character": 50
                }
            },
            "message": "String is not a URI: [UriError]: Scheme is missing: {scheme: \"\", authority: \"\", path: \"\", query: \"\", fragment: \"/components/schemas/Error\"}",
            "severity": 1
        },
        {
            "range": {
                "start": {
                    "line": 74,
                    "character": 22
                },
                "end": {
                    "line": 74,
                    "character": 48
                }
            },
            "message": "String is not a URI: [UriError]: Scheme is missing: {scheme: \"\", authority: \"\", path: \"\", query: \"\", fragment: \"/components/schemas/Pet\"}",
            "severity": 1
        },
        {
            "range": {
                "start": {
                    "line": 99,
                    "character": 14
                },
                "end": {
                    "line": 99,
                    "character": 40
                }
            },
            "message": "String is not a URI: [UriError]: Scheme is missing: {scheme: \"\", authority: \"\", path: \"\", query: \"\", fragment: \"/components/schemas/Pet\"}",
            "severity": 1
        }
    ]
}

I tried setting with the OpenAPI schema from here as follows:

  "yaml.schemas": {
    "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.json": "openapi.yaml"
  }

The error messages still appear for me.

I just noticed that these errors occur only when the name of the file is openapi.yaml. Opening it as petstore.yaml is ok.

But then when setting the schema:

"yaml.schemas": {
  "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.json": "petstore.yaml"
}

The errors come back.

I'm getting the same UriError when editing openapi.yaml files.
Repro:
1) new yaml file
2) paste the yaml below in
3) save
4) get error: String is not a URI: [UriError]: Scheme is missing: {scheme: "", authority: "", path: "", query: "", fragment: "/components/schemas/HelloWorld"}

openapi: 3.0.2

info:
  title: Test API
  version: '0'

paths:
  /hello-world:
    post:
      description: Hello World
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HelloWorld'
      responses:
        201:
          description: 'Hello World'

components:
  schemas:
    HelloWorld:
      type: object
      properties:
        foo:
          type: string
        bar:
          type: number

Output

[Trace - 3:17:15 PM] Sending notification 'textDocument/didOpen'.
Params: {
    "textDocument": {
        "uri": "file:///Users/tarmstrong/src/scratch/openapi.yaml",
        "languageId": "yaml",
        "version": 1,
        "text": "openapi: 3.0.2\n\ninfo:\n  title: Test API\n  version: '0'\n\npaths:\n  /hello-world:\n    post:\n      description: Hello World\n      requestBody:\n        content:\n          application/json:\n            schema:\n              $ref: '#/components/schemas/HelloWorld'\n      responses:\n        201:\n          description: 'Hello World'\n\ncomponents:\n  schemas:\n    HelloWorld:\n      type: object\n      properties:\n        foo:\n          type: string\n        bar:\n          type: number"
    }
}


[Trace - 3:17:15 PM] Sending notification 'json/schemaAssociations'.
Params: {
    "/.condarc": [
        "file:///Users/tarmstrong/.vscode/extensions/ms-python.python-2019.8.30787/schemas/condarc.json"
    ],
    "/environment.yml": [
        "file:///Users/tarmstrong/.vscode/extensions/ms-python.python-2019.8.30787/schemas/conda-environment.json"
    ],
    "/meta.yaml": [
        "file:///Users/tarmstrong/.vscode/extensions/ms-python.python-2019.8.30787/schemas/conda-meta.json"
    ]
}


[Trace - 3:17:15 PM] Sending notification 'yaml/registerCustomSchemaRequest'.
No parameters provided.


[Trace - 3:17:15 PM] Received request 'client/registerCapability - (0)'.
Params: {
    "registrations": [
        {
            "id": "1505f586-171e-4c67-91ce-560462aa4d9c",
            "method": "textDocument/rangeFormatting",
            "registerOptions": {
                "documentSelector": [
                    {
                        "language": "yaml",
                        "scheme": "file"
                    },
                    {
                        "language": "yaml",
                        "scheme": "untitled"
                    }
                ]
            }
        }
    ]
}


[Trace - 3:17:15 PM] Sending response 'client/registerCapability - (0)'. Processing request took 1ms
No result returned.


[Trace - 3:17:18 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///Users/tarmstrong/src/scratch/openapi.yaml",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 14,
                    "character": 20
                },
                "end": {
                    "line": 14,
                    "character": 53
                }
            },
            "message": "String is not a URI: [UriError]: Scheme is missing: {scheme: \"\", authority: \"\", path: \"\", query: \"\", fragment: \"/components/schemas/HelloWorld\"}",
            "severity": 1
        }
    ]
}


[Trace - 3:17:27 PM] Sending request 'textDocument/documentSymbol - (1)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/tarmstrong/src/scratch/openapi.yaml"
    }
}


[Trace - 3:17:27 PM] Received response 'textDocument/documentSymbol - (1)' in 23ms.
Result: [
    {
        "name": "openapi",
        "kind": 15,
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 0,
                "character": 14
            }
        },
        "selectionRange": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 0,
                "character": 7
            }
        },
        "children": []
    },
    {
        "name": "info",
        "kind": 2,
        "range": {
            "start": {
                "line": 2,
                "character": 0
            },
            "end": {
                "line": 4,
                "character": 14
            }
        },
        "selectionRange": {
            "start": {
                "line": 2,
                "character": 0
            },
            "end": {
                "line": 2,
                "character": 4
            }
        },
        "children": [
            {
                "name": "title",
                "kind": 15,
                "range": {
                    "start": {
                        "line": 3,
                        "character": 2
                    },
                    "end": {
                        "line": 3,
                        "character": 17
                    }
                },
                "selectionRange": {
                    "start": {
                        "line": 3,
                        "character": 2
                    },
                    "end": {
                        "line": 3,
                        "character": 7
                    }
                },
                "children": []
            },
            {
                "name": "version",
                "kind": 15,
                "range": {
                    "start": {
                        "line": 4,
                        "character": 2
                    },
                    "end": {
                        "line": 4,
                        "character": 14
                    }
                },
                "selectionRange": {
                    "start": {
                        "line": 4,
                        "character": 2
                    },
                    "end": {
                        "line": 4,
                        "character": 9
                    }
                },
                "children": []
            }
        ]
    },
    {
        "name": "paths",
        "kind": 2,
        "range": {
            "start": {
                "line": 6,
                "character": 0
            },
            "end": {
                "line": 17,
                "character": 36
            }
        },
        "selectionRange": {
            "start": {
                "line": 6,
                "character": 0
            },
            "end": {
                "line": 6,
                "character": 5
            }
        },
        "children": [
            {
                "name": "/hello-world",
                "kind": 2,
                "range": {
                    "start": {
                        "line": 7,
                        "character": 2
                    },
                    "end": {
                        "line": 17,
                        "character": 36
                    }
                },
                "selectionRange": {
                    "start": {
                        "line": 7,
                        "character": 2
                    },
                    "end": {
                        "line": 7,
                        "character": 14
                    }
                },
                "children": [
                    {
                        "name": "post",
                        "kind": 2,
                        "range": {
                            "start": {
                                "line": 8,
                                "character": 4
                            },
                            "end": {
                                "line": 17,
                                "character": 36
                            }
                        },
                        "selectionRange": {
                            "start": {
                                "line": 8,
                                "character": 4
                            },
                            "end": {
                                "line": 8,
                                "character": 8
                            }
                        },
                        "children": [
                            {
                                "name": "description",
                                "kind": 15,
                                "range": {
                                    "start": {
                                        "line": 9,
                                        "character": 6
                                    },
                                    "end": {
                                        "line": 9,
                                        "character": 30
                                    }
                                },
                                "selectionRange": {
                                    "start": {
                                        "line": 9,
                                        "character": 6
                                    },
                                    "end": {
                                        "line": 9,
                                        "character": 17
                                    }
                                },
                                "children": []
                            },
                            {
                                "name": "requestBody",
                                "kind": 2,
                                "range": {
                                    "start": {
                                        "line": 10,
                                        "character": 6
                                    },
                                    "end": {
                                        "line": 14,
                                        "character": 53
                                    }
                                },
                                "selectionRange": {
                                    "start": {
                                        "line": 10,
                                        "character": 6
                                    },
                                    "end": {
                                        "line": 10,
                                        "character": 17
                                    }
                                },
                                "children": [
                                    {
                                        "name": "content",
                                        "kind": 2,
                                        "range": {
                                            "start": {
                                                "line": 11,
                                                "character": 8
                                            },
                                            "end": {
                                                "line": 14,
                                                "character": 53
                                            }
                                        },
                                        "selectionRange": {
                                            "start": {
                                                "line": 11,
                                                "character": 8
                                            },
                                            "end": {
                                                "line": 11,
                                                "character": 15
                                            }
                                        },
                                        "children": [
                                            {
                                                "name": "application/json",
                                                "kind": 2,
                                                "range": {
                                                    "start": {
                                                        "line": 12,
                                                        "character": 10
                                                    },
                                                    "end": {
                                                        "line": 14,
                                                        "character": 53
                                                    }
                                                },
                                                "selectionRange": {
                                                    "start": {
                                                        "line": 12,
                                                        "character": 10
                                                    },
                                                    "end": {
                                                        "line": 12,
                                                        "character": 26
                                                    }
                                                },
                                                "children": [
                                                    {
                                                        "name": "schema",
                                                        "kind": 2,
                                                        "range": {
                                                            "start": {
                                                                "line": 13,
                                                                "character": 12
                                                            },
                                                            "end": {
                                                                "line": 14,
                                                                "character": 53
                                                            }
                                                        },
                                                        "selectionRange": {
                                                            "start": {
                                                                "line": 13,
                                                                "character": 12
                                                            },
                                                            "end": {
                                                                "line": 13,
                                                                "character": 18
                                                            }
                                                        },
                                                        "children": [
                                                            {
                                                                "name": "$ref",
                                                                "kind": 15,
                                                                "range": {
                                                                    "start": {
                                                                        "line": 14,
                                                                        "character": 14
                                                                    },
                                                                    "end": {
                                                                        "line": 14,
                                                                        "character": 53
                                                                    }
                                                                },
                                                                "selectionRange": {
                                                                    "start": {
                                                                        "line": 14,
                                                                        "character": 14
                                                                    },
                                                                    "end": {
                                                                        "line": 14,
                                                                        "character": 18
                                                                    }
                                                                },
                                                                "children": []
                                                            }
                                                        ]
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "name": "responses",
                                "kind": 2,
                                "range": {
                                    "start": {
                                        "line": 15,
                                        "character": 6
                                    },
                                    "end": {
                                        "line": 17,
                                        "character": 36
                                    }
                                },
                                "selectionRange": {
                                    "start": {
                                        "line": 15,
                                        "character": 6
                                    },
                                    "end": {
                                        "line": 15,
                                        "character": 15
                                    }
                                },
                                "children": [
                                    {
                                        "name": "201",
                                        "kind": 2,
                                        "range": {
                                            "start": {
                                                "line": 16,
                                                "character": 8
                                            },
                                            "end": {
                                                "line": 17,
                                                "character": 36
                                            }
                                        },
                                        "selectionRange": {
                                            "start": {
                                                "line": 16,
                                                "character": 8
                                            },
                                            "end": {
                                                "line": 16,
                                                "character": 11
                                            }
                                        },
                                        "children": [
                                            {
                                                "name": "description",
                                                "kind": 15,
                                                "range": {
                                                    "start": {
                                                        "line": 17,
                                                        "character": 10
                                                    },
                                                    "end": {
                                                        "line": 17,
                                                        "character": 36
                                                    }
                                                },
                                                "selectionRange": {
                                                    "start": {
                                                        "line": 17,
                                                        "character": 10
                                                    },
                                                    "end": {
                                                        "line": 17,
                                                        "character": 21
                                                    }
                                                },
                                                "children": []
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    },
    {
        "name": "components",
        "kind": 2,
        "range": {
            "start": {
                "line": 19,
                "character": 0
            },
            "end": {
                "line": 27,
                "character": 22
            }
        },
        "selectionRange": {
            "start": {
                "line": 19,
                "character": 0
            },
            "end": {
                "line": 19,
                "character": 10
            }
        },
        "children": [
            {
                "name": "schemas",
                "kind": 2,
                "range": {
                    "start": {
                        "line": 20,
                        "character": 2
                    },
                    "end": {
                        "line": 27,
                        "character": 22
                    }
                },
                "selectionRange": {
                    "start": {
                        "line": 20,
                        "character": 2
                    },
                    "end": {
                        "line": 20,
                        "character": 9
                    }
                },
                "children": [
                    {
                        "name": "HelloWorld",
                        "kind": 2,
                        "range": {
                            "start": {
                                "line": 21,
                                "character": 4
                            },
                            "end": {
                                "line": 27,
                                "character": 22
                            }
                        },
                        "selectionRange": {
                            "start": {
                                "line": 21,
                                "character": 4
                            },
                            "end": {
                                "line": 21,
                                "character": 14
                            }
                        },
                        "children": [
                            {
                                "name": "type",
                                "kind": 15,
                                "range": {
                                    "start": {
                                        "line": 22,
                                        "character": 6
                                    },
                                    "end": {
                                        "line": 22,
                                        "character": 18
                                    }
                                },
                                "selectionRange": {
                                    "start": {
                                        "line": 22,
                                        "character": 6
                                    },
                                    "end": {
                                        "line": 22,
                                        "character": 10
                                    }
                                },
                                "children": []
                            },
                            {
                                "name": "properties",
                                "kind": 2,
                                "range": {
                                    "start": {
                                        "line": 23,
                                        "character": 6
                                    },
                                    "end": {
                                        "line": 27,
                                        "character": 22
                                    }
                                },
                                "selectionRange": {
                                    "start": {
                                        "line": 23,
                                        "character": 6
                                    },
                                    "end": {
                                        "line": 23,
                                        "character": 16
                                    }
                                },
                                "children": [
                                    {
                                        "name": "foo",
                                        "kind": 2,
                                        "range": {
                                            "start": {
                                                "line": 24,
                                                "character": 8
                                            },
                                            "end": {
                                                "line": 25,
                                                "character": 22
                                            }
                                        },
                                        "selectionRange": {
                                            "start": {
                                                "line": 24,
                                                "character": 8
                                            },
                                            "end": {
                                                "line": 24,
                                                "character": 11
                                            }
                                        },
                                        "children": [
                                            {
                                                "name": "type",
                                                "kind": 15,
                                                "range": {
                                                    "start": {
                                                        "line": 25,
                                                        "character": 10
                                                    },
                                                    "end": {
                                                        "line": 25,
                                                        "character": 22
                                                    }
                                                },
                                                "selectionRange": {
                                                    "start": {
                                                        "line": 25,
                                                        "character": 10
                                                    },
                                                    "end": {
                                                        "line": 25,
                                                        "character": 14
                                                    }
                                                },
                                                "children": []
                                            }
                                        ]
                                    },
                                    {
                                        "name": "bar",
                                        "kind": 2,
                                        "range": {
                                            "start": {
                                                "line": 26,
                                                "character": 8
                                            },
                                            "end": {
                                                "line": 27,
                                                "character": 22
                                            }
                                        },
                                        "selectionRange": {
                                            "start": {
                                                "line": 26,
                                                "character": 8
                                            },
                                            "end": {
                                                "line": 26,
                                                "character": 11
                                            }
                                        },
                                        "children": [
                                            {
                                                "name": "type",
                                                "kind": 15,
                                                "range": {
                                                    "start": {
                                                        "line": 27,
                                                        "character": 10
                                                    },
                                                    "end": {
                                                        "line": 27,
                                                        "character": 22
                                                    }
                                                },
                                                "selectionRange": {
                                                    "start": {
                                                        "line": 27,
                                                        "character": 10
                                                    },
                                                    "end": {
                                                        "line": 27,
                                                        "character": 14
                                                    }
                                                },
                                                "children": []
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
]

As mentionned in https://github.com/microsoft/vscode/issues/80029 I'm having a similar issue with relative links. This worked before a recent update so this looks like a regression!

I'm also having this problem. Let me know what diagnostic information you'd require.

Note: I'm not able to make the error disappear regardless of filename or workspace configuration.

This looks the problem is partly to do with the way the validator is interpreting the uri-reference format, which is how $ref is described in the JSON Schema meta schema.

"$ref": {
  "type": "string",
  "format": "uri-reference"
}

According to the spec uri-reference can either be a full URI, relative reference or same document reference, but this extension is reporting the latter two as invalid.

To be clearer, if I setup my extension settings like so

{
  "yaml.schemas": {
    "http://json-schema.org/draft-07/schema": "*.schema.yaml"
  },
}

Then

$ref: some/relative/path/foo.schema.yaml // Invalid
$ref: #/some/internal/Thing // Invalid
$ref: file:///some/absolute/path/foo.schema.yaml // Valid

But all cases should be valid imo.

I encountered this issue with relative paths with special chars as "@"; it works with absolute paths anstead.

{
  "yaml.schemas": {
    "some/relative/@path/foo.schema.json": "*.schema.yaml", // Not works
    "file:///some/absolute/@path/foo.schema.json": "*.schema.yaml" // Works
  }
}

I'm not familiar with how extensions validate JSON/yaml content against a JSON Schema. Is that heavy lifting done by code in this repo, or is it a service provided by the VS Code host app?

I'm not familiar with how extensions validate JSON/yaml content against a JSON Schema. Is that heavy lifting done by code in this repo, or is it a service provided by the VS Code host app?

It looks like yaml is validated by the 'sister' project https://github.com/redhat-developer/yaml-language-server

Maybe this issue should be reported there,too

Thanks for the detective work. Done 馃憠 https://github.com/redhat-developer/yaml-language-server/issues/181

The fix for this will be available in the next release

Any ETA on when that release is going to happen?

Was this page helpful?
0 / 5 - 0 ratings