Coder Social home page Coder Social logo

Comments (12)

oetiker avatar oetiker commented on July 18, 2024 2

how about following the convention vsc uses for json files: https://code.visualstudio.com/docs/languages/json#_json-schemas-settings

basically, the idea is that the yaml file can use the $schema key in the same way it is used in json schema definitions.

$schema: http://json.schemastore.org/coffeelint
line_endings: unix

This syntax is VS Code-specific and not part of the JSON Schema specification but I think it makes a lot of sense and thus would be worth supporting here too.

from yaml-language-server.

felixfbecker avatar felixfbecker commented on July 18, 2024 2

I don't think $schema meaning something else is something to worry about. It is specced in the JSON schema standard, which the YAML language server is built upon. https://json-schema.org/latest/json-schema-core.html#rfc.section.7

from yaml-language-server.

sqs avatar sqs commented on July 18, 2024

Also can possibly use the filename, full path name, or other sibling files.

from yaml-language-server.

JPinkney avatar JPinkney commented on July 18, 2024

We autodetect schemas from http://schemastore.org/json/ based off of filename but other then that there isn't a way to decide the schema based off of context yet. I believe @andxu was working on something like that for https://github.com/Azure/vscode-kubernetes-tools but I could be wrong.

from yaml-language-server.

apupier avatar apupier commented on July 18, 2024

for information seems another YAML LS is providing schemas: https://github.com/adamvoss/vscode-yaml-languageservice

from yaml-language-server.

JPinkney avatar JPinkney commented on July 18, 2024

This LS has all the same features as that one. When the creator of that one was closing his vscode extension he wanted to make sure that we supported all his features so his users could transition. Both do provide schemes but neither of them have an automatic way to detect schemas

from yaml-language-server.

rvansa avatar rvansa commented on July 18, 2024

What's the status of the last request? I would also appreciate being able to use $schema. An alternative approach that does not require changes on the consumer side is to add a shebang comment:

#!schema: http://json.schemastore.org/foobar
foo:
- bar

from yaml-language-server.

JPinkney avatar JPinkney commented on July 18, 2024

Currently hasn't been worked on. It is not a hard thing to add I just haven't had the time.

from yaml-language-server.

fbricon avatar fbricon commented on July 18, 2024

I think the shebang approach is safer than using a $schema field. If someone uses $schema with a different semantic value, you have a conflict.

You also need to determine what takes precedence, #!schema or the schema association in the preferences. I think the former, since the scope is smaller.

Maybe @NikolasKomonen can work on that

from yaml-language-server.

SamB avatar SamB commented on July 18, 2024

Actually, after reading carefully, I've noticed that JSON Schema spec doesn't actually seem to say anything about using $schema outside JSON schemas. (They don't say you may do it, but they also don't say you may not.)

So, that tells us nothing about whether it's okay to use $schema in this way for YAML, sadly :-(.

However, what could go wrong?

  1. $schema could be an absolute URI identifying a JSON Schema: In my opinion, anyone setting such a value who doesn't want us to validate against that schema is some kind of an idiot.
  2. $schema could be an absolute URI identifying something that merely resembles a JSON Schema: This is tricky.
  3. $schema is something else: I guess the user gets some squiggly underlines they don't need? Doesn't seem all that terrible.

However, there are some other issues with $schema:

  1. As the vscode docs point out, consumers might not be prepared for this; for instance, the schema itself might not permit the $schema property.
  2. If we're just generalizing the notation from the JSON Schema spec for use in other files, we're still stuck with the absolute URI requirement, so we can't directly reference a schema in our working tree.

These aren't necessarily showstoppers: Users can arrange that the schema permit $schema, certainly. The other issue is a bit more annoying, but apparently JSON Schema implementations aren't supposed to blindly dereference such URIs anyway, so it would be perfectly reasonable to use a mechanism similar in nature to OASIS XML Catalogs to allow this.

from yaml-language-server.

felixfbecker avatar felixfbecker commented on July 18, 2024

The user is still not forced to add $schema to the document if the consumer of the document will reject it.

we're still stuck with the absolute URI requirement

Where in the spec does it say the URI must be absolute?

In the end, it doesn't look like any of this was a problem for JSON, so I don't see why it would be a problem for YAML.

from yaml-language-server.

oetiker avatar oetiker commented on July 18, 2024

Since VC support the use of $schema in JSON, why not simply support it in YAML too? This will not compel anyone to use follow this convention, they can continue using the current config system, but for those who work with schemas that a) require the $schema keyword (these exist) or b) don't care this would make life so much simpler.

an example schema requiring the use of $schema in a normal json data structure.

https://github.com/qooxdoo/qooxdoo-compiler/blob/master/source/resource/qx/tool/schema/v1/compile.json

from yaml-language-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.