Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema validation reports errors in valid YAML document #42

Closed
vojtechhabarta opened this issue Nov 2, 2017 · 8 comments
Closed

Schema validation reports errors in valid YAML document #42

vojtechhabarta opened this issue Nov 2, 2017 · 8 comments
Assignees
Labels

Comments

@vojtechhabarta
Copy link

I have rather complex JSON schema with which YAML plugin doesn't work correctly. It reports errors in valid YAML document. But when I use this schema with equivalent JSON document it works correctly.

I tried to simplify the schema and narrow the problem but it is still long and complex because the problem is in some combination of schema constructs.

I have vscode-yaml 0.0.4 with VSCode insider build (see bellow).

Here is the YAML document which doesn't work correctly:

aaa:
  type: TypeA
  properties:
    propertyA: { stringArray: [ "abcd"] }

Here is JSON document which works:

{
    "$schema": "./test.schema.json",
    "aaa": {
        "type": "TypeA",
        "properties": {
            "propertyA": {
                "stringArray": ["abcd"]
            }
        }
    }
}

Here is test.schema.json schema:

{
  "$schema": "http://json-schema.org/schema#",
  "type": "object",
  "properties": {
    "aaa": {
      "oneOf": [
        {
          "allOf": [
            {
              "properties": {
                "type": {
                  "enum": [
                    "TypeA"
                  ]
                },
                "properties": {
                  "type": "object",
                  "properties": {
                    "propertyA": {
                      "$ref": "#/definitions/commonStructures",
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "propertyA"
                  ],
                  "additionalProperties": true
                }
              },
              "required": [
                "type"
              ]
            },
            {
              "$ref": "#/definitions/commonProperties"
            }
          ]
        },
        {
          "allOf": [
            {
              "properties": {
                "type": {
                  "enum": [
                    "TypeB"
                  ]
                },
                "properties": {
                  "type": "object",
                  "properties": {
                    "propertyB": {
                      "$ref": "#/definitions/commonStructures",
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "propertyB"
                  ],
                  "additionalProperties": true
                }
              },
              "required": [
                "type"
              ]
            },
            {
              "$ref": "#/definitions/commonProperties"
            }
          ]
        }
      ]
    }
  },
  "required": [
    "aaa"
  ],
  "additionalProperties": true,
  "definitions": {
    "commonProperties": {
      "type": "object",
      "properties": {
        "commonProperty": {
          "type": "string"
        }
      }
    },
    "commonStructures": {
      "type": "object",
      "properties": {
        "stringArray": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        }
      },
      "additionalProperties": false
    }
  }
}
  • VSCode Version: Code - Insiders 1.18.0-insider (2ab10d50163f008ada9a4aa215de8c884857ce99, 2017-11-01T05:19:21.302Z)
  • OS Version: Windows_NT x64 10.0.16299
  • Extensions:
Extension Author (truncated) Version
vscode-yaml red 0.0.4
@JPinkney JPinkney self-assigned this Nov 2, 2017
@JPinkney
Copy link
Contributor

JPinkney commented Nov 2, 2017

I've narrowed this down to a regression in redhat-developer/yaml-language-server@2a8456a inside the jsonParser. I'm currently working on fixing this!

@JPinkney JPinkney added the bug label Nov 2, 2017
@felixfbecker
Copy link

felixfbecker commented Nov 9, 2017

I think I'm meeting the same issue. I have a schema for a .travis.yml that defines the type of e.g. before_install as oneOf boolean, string or array of strings:

https://github.com/felixfbecker/schemastore/blob/2a32ed0e3eab265b9a82f0b2dbcd1046eab85bde/src/schemas/json/travis.json#L15-L28

But the inside VS Code I get the validation error that boolean is expected (and not string array):

image

https://github.com/aaronpowell/ps-nvmw/blob/9784e5ada938a7485a6786371ac76b3ed78d37fb/.travis.yml#L13

@JPinkney
Copy link
Contributor

JPinkney commented Nov 9, 2017

I believe this is the same issue. I have a fix for it we just need to release the extension again for the update!

@felixfbecker
Copy link

felixfbecker commented Nov 9, 2017

@JPinkney to make these releases automatic, would you be interested in a semantic-release auto-release workflow? I set that up for php-language-server and vscode-php-intellisense and it works very well

@JPinkney
Copy link
Contributor

Hi, I've fixed this issue! It's now available in the latest release!

@felixfbecker
Copy link

@JPinkney awesome! Did you read my comment above?

@vojtechhabarta
Copy link
Author

@JPinkney thanks, with latest release my schema works as expected.

BTW the schema is here: https://github.com/vojtechhabarta/heat-template-schema/blob/master/schema/heat-template.schema.json - it is generated schema for OpenStack Heat Orchestration Templates.

@felixfbecker
Copy link

@vojtechhabarta I would encourage you to contribute it to jsonschemastore :)

apupier pushed a commit to apupier/vscode-yaml that referenced this issue Jul 2, 2020
…idation

Fixing the validator and making it more stable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants