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

Ability to specify schema as a comment in the YAML file #401

Open
johnbillion opened this issue Nov 27, 2020 · 11 comments
Open

Ability to specify schema as a comment in the YAML file #401

johnbillion opened this issue Nov 27, 2020 · 11 comments

Comments

@johnbillion
Copy link

Is your enhancement related to a problem? Please describe.

A common problem with this extension is mis-detection of the correct schema. For example, a file named deploy.yml is assumed to be a PHPDeployer file because this is the only match on JSON Schema Store.

Related issues:

The only way to override an incorrect schema is to set glob to schema mapping in the VS Code settings, but this means the settings can't easily be shared between developers or committed to version control.

Describe the solution you would like

It should be possible to insert a leading comment in a YAML file that declares its schema.

VS Code natively supports this for JSON files via a VS Code-specific $schema property (because JSON doesn't support comments):

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  ...
}

In a YAML file, a comment could be used:

# $schema: https://json.schemastore.org/github-workflow

name: Foo

When this comment is present, this extension should skip fetching schemas from Schema Store and fetch the linked schema directly, if necessary.

Describe alternatives you have considered

I have no considered whether any other editors or IDEs support such a syntax for YAML file schema declaration. If they do, it would be worth trying to be compatible.

@evidolob
Copy link
Collaborator

evidolob commented Nov 27, 2020

@johnbillion yaml-language-server already supports this
Maybe we just need to add description in to vscode-yaml extension readme.

@johnbillion
Copy link
Author

@evidolob Great! Thanks.

I just tried this and the schema wasn't detected correctly. It looks like #397 could be the same cause?

I can open a PR with updated docs for this once it's confirmed as working as expected.

@evidolob
Copy link
Collaborator

I think yes, it could. As for #397 we have draft PR to fix schema selection redhat-developer/yaml-language-server#362

Any PR is welcome.

@ssbarnea
Copy link
Member

ssbarnea commented Feb 21, 2021

Any updates on this? At this moment I even have zero feedback regarding which schema is used, if any at all. This extensions needs to expose the current schema being used on the status bar, so we would know if any was loaded or not, or if wrong one was used.

I even tried to see if there is any command exposed by YAML extension, that can be used to expose if something happened or not regarding validation but I was not able to find any.

While using the inline schema specifier, I seen that putting wrong url does correctly reports a failure to load the schema but I seen no proof of success when it worked, which is very important for those that are writing schemas.

@IanMoroney
Copy link

IanMoroney commented Feb 26, 2021

Update:
@johnbillion, @ssbarnea , I just tested this with an inline comment and it works.
As mentioned by @evidolob , the comment format here works as expected.

I was able to make the language server recognise a specific format, overriding the auto-association based on the filename.

@evidolob, the impact that this issue is having is quite severe at the moment.
We currently don't have the ability to name our files with any name we want to because of #354 , as the language server reads the filename and incorrectly assumes a schema.
example,
create any valid yaml file and call it test.yaml. It will load just fine.
rename the file to noahsarc.yaml and it will try to load it as A JSON schema for OpenJS Architect (because it detects that the word arc is in the filename.
This is really bad behaviour, as our users are complaining that yaml files aren't valid, and investigating bugs that don't exist.

Just disable the extension? I would, except that it's a dependency for the Visual Studio Code Kubernetes extension and has to be loaded.

@trallnag
Copy link

There doesn't seem to be a way to tell the language server that the YAML file it is dealing with is a Kubernetes manifest

@davetapley
Copy link

Could we also support something like ⬇️ ?

# yaml-language-server: $schema=none

to solve for:

@Destroy666x
Copy link

Anything blocking this, considering there's an official representation of this?

@madmalkav
Copy link

madmalkav commented Oct 10, 2023

There doesn't seem to be a way to tell the language server that the YAML file it is dealing with is a Kubernetes manifest

This seems to be still the case.

@mohitsuman
Copy link
Contributor

@madmalkav Please assign yourself and work on this. Thanks for taking this up.

@madmalkav
Copy link

Sorry, I’m not a native speaker and I think my comment was misleading, I have no knowledge to fix this myself. I have edited my comment to avoid further confusion.

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

9 participants