redhat-developer / redhat-developer/vscode-yaml

Default value from subschema used for string autocompletion elsewhere

Open
#1,076 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
829
Forks
260
Avg merge
5h 43m
Merged PRs (30d)
1

Description

Describe the bug

The default value of a property in one subschema is unintentionally used as default value in string item property.

I have a json schema like so:

{
  "$defs": {
    "Foo": {
      "properties": {
        "foo": {
          "type": "string",
          "default": "hello"
        }
      },
      "type": "object"
    }
  },
  "additionalProperties": false,
  "properties": {
    "foos": {
      "items": {
        "$ref": "#/$defs/Foo"
      },
      "type": "array"
    },
    "bars": {
      "items": {
        "type": "string"
      },
      "type": "array"
    }
  },
  "required": [
    "bars",
    "foos"
  ],
  "type": "object"
}

The completions for this schema is shown like this:
Image
correctly showing the default value for foo but also showing ${1} for bar. When hitting enter, the default value is applied to the bar element as well:
Image

Expected Behavior

I expect the default value to only show up for the property it is defined for.

Current Behavior

Default value shows up unexpectedly in wrong place.

Steps to Reproduce

  1. Copy the schema
  2. ctrl + space in new file which uses the schema
  3. hit enter

Environment

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue in VS Code using the provided schema: trigger completion in a new file and compare the foos and bars array items. Trace the completion path for JSON Schema defaults, then verify that hello is offered only for foo and is not inserted for bar.

Written by the indexing model from the issue text.

Assessment

Tech stack
json, typescript, vscode
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.