Skip to content

Content-aware schema detection #605

Open
@valorl

Description

@valorl

Is your enhancement related to a problem? Please describe.

The current way of mappings schemas to files is way too static for some use-cases. When working e.g. with Kubernetes manifests, it's not very common nor practical to follow a file-naming convention that would include the apiVersion/kind (= the schema determinant), which makes it hard to use YAML LS in practice.

Describe the solution you would like

Instead of just a file glob, I'd like to be able to involve the contents of files in the process of determining a schema. A mapping could be defined using a basic expression, e.g.:

"yaml.schemas": {
    ".apiVersion == argoproj.io/v1alpha1": "https://raw.githubusercontent.com/argoproj/argo-workflows/master/api/jsonschema/schema.json",
    ".apiVersion == apps/v1 && .kind == Deployment": "https://kubernetesjsonschema.dev/v1.14.0/deployment-apps-v1.json"
}

(The syntax doesn't really matter as long as it's possible to determine a schema based on YAML content)

I wonder what maintainers think. Does this sound as a feature that would be accepted or is it too much complexity? Are there any other ways of achieving this ?

Describe alternatives you have considered

Adding comments with schema links to each file. This is quite impractical to maintain in repos with a lot of similar files. Adding the comments could potentially be automated based on a mapping like above for a "quick fix" solution.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions