vscode-yaml icon indicating copy to clipboard operation
vscode-yaml copied to clipboard

Property shows up multiple times in completions

Open afscrome opened this issue 2 years ago • 3 comments

Describe the bug

If a schema uses anyOf and multiple objects have a property with the same name, but different sets of required fields, then that property shows up twice in auto completion (see example schema below).

Expected Behavior

In the below example, spec should only show in completions once. image

Current Behavior

The spec field is shown in completions twice image

Steps to Reproduce

1.Create the below schema 2. Reference it in a yaml file 3. Start auto completion at the first character in the file

If you remove the required section in the second object, then completion correctly shows only one spec completion.

{
    "$schema": "http://json-schema.org/draft-07/schema",
    "oneOf": [
        {
            "type": "object",
            "properties": {
                "spec": {
                    "type": "object"
                }
            }
        },
        {
            "properties": {
                "spec": {
                    "type": "object",
                    "required": [
                        "bar"
                    ],
                    "properties": {
                        "bar": {
                            "type": "string"
                        }
                    }
                }
            }
        }
    ]
}

Environment

  • [X] Windows
  • [ ] Mac
  • [ ] Linux
  • [ ] other (please specify)

afscrome avatar Sep 22 '22 20:09 afscrome

@afscrome Here oneOf contains two properties and both name is spec.

  1. spec of object type
  2. spec of object with child property bar

So we can suggest user that all matching properties and used can pick the opt one

msivasubramaniaan avatar Sep 23 '22 07:09 msivasubramaniaan

In the VS Code JSON editor, this same schema only shows a single spec property image So to does Rider image

The wider context in which I encountered this I'm trying to use Backstage's object schema for it's catalog-info.yaml files. (This schema is heavily inspired by Kubenetes object format)

  • json schema - https://json.schemastore.org/catalog-info.json
  • docs - https://backstage.io/docs/features/software-catalog/descriptor-format, with a schema

If using this schema in the VS Code JSON editor or Rider, the the auto completions come out as expected, and are easy to use, with no duplicate property names image image

But when I use this same schema with the VS Code YAML extension , the auto completions become overwhelming with duplicates, duplicated, to the point of not being very useful. There are quite a few issues which I suspect are related, but I'm still trying to reduce them to a minimal repo

image image

afscrome avatar Sep 23 '22 08:09 afscrome

@afscrome Let me check and get back to you ASAP

msivasubramaniaan avatar Sep 23 '22 09:09 msivasubramaniaan