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

only the first choice is shown when hovering anyOf-typed properties #784

Closed
thedmi opened this issue Jun 15, 2022 · 0 comments
Closed

only the first choice is shown when hovering anyOf-typed properties #784

thedmi opened this issue Jun 15, 2022 · 0 comments
Assignees
Milestone

Comments

@thedmi
Copy link

thedmi commented Jun 15, 2022

Describe the bug

Documentation that is shown when hovering properties is misleading in some cases related to anyOf properties. While correct documentation is shown for valid YAML, the user sees misleading information while in the process of writing YAML. This is problematic for cases where a user relies on auto-completion and hover documentation to discover available properties.

Schema

{
  "title": "TheRoot",
  "description": "Root object",
  "type": "object",
  "properties": {
    "child": {
      "title": "Child",
      "env_names": [
        "child"
      ],
      "anyOf": [
        {
          "$ref": "#/definitions/FirstChoice"
        },
        {
          "$ref": "#/definitions/SecondChoice"
        }
      ]
    }
  },
  "required": [
    "child"
  ],
  "additionalProperties": false,
  "definitions": {
    "FirstChoice": {
      "title": "FirstChoice",
      "description": "The first choice",
      "type": "object",
      "properties": {
        "choice": {
          "title": "Choice",
          "default": "first",
          "enum": [
            "first"
          ],
          "type": "string"
        },
        "property_a": {
          "title": "Property A",
          "type": "string"
        }
      },
      "required": [
        "property_a"
      ]
    },
    "SecondChoice": {
      "title": "SecondChoice",
      "description": "The second choice",
      "type": "object",
      "properties": {
        "choice": {
          "title": "Choice",
          "default": "second",
          "enum": [
            "second"
          ],
          "type": "string"
        },
        "property_b": {
          "title": "Property B",
          "type": "string"
        }
      },
      "required": [
        "property_b"
      ]
    }
  }
}

Side note: This schema was generated using Pydantic with the below Pydantic model.

from typing import Union
from pydantic import Field, BaseSettings, BaseModel
from typing_extensions import Literal


class FirstChoice(BaseModel):
    """The first choice"""

    choice: Literal["first"] = Field(default="first")

    property_a: str = Field()


class SecondChoice(BaseModel):
    """The second choice"""

    choice: Literal["second"] = Field(default="second")

    property_b: str = Field()


Choices = Union['FirstChoice', 'SecondChoice']


class TheRoot(BaseSettings):
    """Root object"""

    child: Choices = Field()

Example YAML

This is intentionally incomplete, assume the user is currently in the process of writing it.

# yaml-language-server: $schema=bugreport.schema.json

child: 

Expected Behavior

When hovering child, hover documentation indicates that there are two choices, FirstChoice and SecondChoice.

Current Behavior

When hovering child, documentation for FirstChoice is shown, without any indication that there are other possibilities.

Note that the hover documentation works as expected as soon as it is clear which anyOf choice applies. For example, the following YAML will show documentation for SecondChoice when hovering child:

# yaml-language-server: $schema=bugreport.schema.json

child: 
  choice: second

Steps to Reproduce

  1. Store the above schema and example YAML in files, make sure the schema reference matches the schema file name
  2. Hover child

Environment

  • Windows
  • VS Code 1.68.0
  • YAML Extension 1.8.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants