Skip to content

auto-complete is not working properly #563

@nguyenminhphuong

Description

@nguyenminhphuong

Describe the bug

I create a schema as array of tuples, the validation is working properly but auto-complete is NOT.

The schema is validating as expected but auto-complete does not show suggestion for properties defined in the items. Instead, it is only showing properties in additionalItems

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "required": [
    "metadata"
  ],
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "metadata": {
      "type": "object",
      "title": "Metadata",
      "properties": {
        "Selector": {
          "properties": {
            "query": {
              "title": "Construction",
              "type": "array",
              "items": [
                {
                  "oneOf": [
                    {
                      "$ref": "#/definitions/FUNC_item"
                    },
                    {
                      "$ref": "#/definitions/NOT_item"
                    }
                  ]
                }
              ],
              "additionalItems": {
                "$ref": "#/definitions/queryItem"
              }
            }
          }
        }
      }
    }
  },
  "definitions": {
    "FUNC_item": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "attribute",
        "operation",
        "value"
      ],
      "properties": {
        "attribute": {
          "type": "string"
        },
        "operation": {
          "type": "string"
        },
        "value": {
          "type": "string"
        }
      }
    },
    "NOT_item": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "NOT": {
          "type": "array",
          "items": [
            {
              "$ref": "#/definitions/FUNC_item"
            }
          ],
          "additionalItems": {
            "$ref": "#/definitions/queryItem"
          }
        }
      }
    },
    "AND_Item": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "AND": {
          "type": "array",
          "items": [
            {
              "oneOf": [
                {
                  "$ref": "#/definitions/FUNC_item"
                },
                {
                  "$ref": "#/definitions/NOT_item"
                }
              ]
            }
          ],
          "additionalItems": {
            "$ref": "#/definitions/queryItem"
          }
        }
      }
    },
    "OR_Item": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "OR": {
          "type": "array",
          "items": [
            {
              "oneOf": [
                {
                  "$ref": "#/definitions/FUNC_item"
                },
                {
                  "$ref": "#/definitions/NOT_item"
                }
              ]
            }
          ],
          "additionalItems": {
            "$ref": "#/definitions/queryItem"
          }
        }
      }
    },
    "queryItem": {
      "oneOf": [
      
        {"$ref": "#/definitions/AND_Item"},
        {"$ref": "#/definitions/OR_Item"}
      ]
    }
  }
}

Here is validation from visual studio code, it's saying that first element should be FUNC_item or NOT_item
=> which is correct
image

But when I use Ctrl + Space to show auto-complete, it is showing AND and OR from the list
=> which is NOT correct because as per definition of schema, properties in items should be showing up in the auto-complete for first element of array.

"items": [
                {
                  "oneOf": [
                    {
                      "$ref": "#/definitions/FUNC_item"
                    },
                    {
                      "$ref": "#/definitions/NOT_item"
                    }
                  ]

image

Expected Behavior

  1. The auto-complete should show properties defined items for first element of array. Specifically, NOT and array item (having 3 properties "attribute", "operation", "value" ) should be showing up.

  2. From second element onwards, the auto-complete shows AND and OR

Current Behavior

Steps to Reproduce

  1. Install Yaml Red Hat Visual Studio Extension to vsc
  2. Create a schema I shared above, name it schema.json
  3. Create the following settings.json in your working folder, specify your yaml files to validate against schema.json
{
"yaml.format.enable": true,
"yaml.schemas": {
  ".vscode/schema.json": [
    "test.yaml"
  ]
},
"yaml.completion": true,
"yaml.schemaStore.enable": true,
"[yaml]": {
  "editor.defaultFormatter": "redhat.vscode-yaml",
  
  
},
"workbench.editor.closeOnFileDelete": true
}
  1. Create the following test.yaml in your working folder, test auto-complete after query property
metadata:
  Selector:
    query:
      - 

Environment

  • Windows
  • Mac
  • Linux
  • other (please specify)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions