Skip to content

Support JSON Schema for YAML files #1176

Closed

Description

@mohsen1

It's getting more common to use YAML for configuration. For example docker-compose.yml or Swagger files are usually written in YAML. The JSON Schema based autocomplete for JSON files is a neat feature, please enable that for YAML files also.

Activity

  1. changed the title [-]Support JSON Schema for YAML files also[/-] [+]Support JSON Schema for YAML files[/+] on Dec 10, 2015
  2. added
    feature-request
    on Dec 11, 2015
  3. added this to the Backlog milestone on Dec 11, 2015
  4. egamma commented on Dec 11, 2015

    @egamma
    Member
  5. mohsen1 commented on Feb 9, 2016

    @mohsen1
    Author

    I'm eager to implement this. Can you point me to where can I start?

  6. aeschli commented on Feb 9, 2016

    @aeschli
    Contributor

    You basically have to implement an extension that adds a validation support for YAML.
    In there you can implement the validation logic yourself, as JSON does it, or delegate to another executable. If you implement the validation logic yourself in TypeScript/JavaScipt, you'd do that as a language server. A language server performs the validation in it's own process.

    To see that in action, have a look at the JSON extension at (https://github.com/Microsoft/vscode/tree/master/extensions/json).
    To try it out:

    • open a VSCode window on the extensions/json folder, also run npm install in that folder, press the 'run' button in the debug viewlet
    • a new VSCode window opens, where you can open a JSON file and associate a schema to it
    • to debug the validation code, additionally open a VSCode window on the 'server' folder, and use the 'attach' option in the debug viewlet.
    • Check out the jsonParser.ts code that creates an AST out of the JSON document and contains the 'validate' functions that verify a node against the JSON schema.
  7. djabraham commented on Apr 15, 2016

    @djabraham

    Mohsen Azimi (@mohsen1) Have you done any work in this regard yet?

  8. mohsen1 commented on Apr 15, 2016

    @mohsen1
    Author

    Daniel Abraham (@djabraham) no. Never found the time to do this

  9. djabraham commented on Apr 22, 2016

    @djabraham

    I Friken Love YAML

    ..so I gave it a try.

    https://github.com/djabraham/vscode-yaml-validation

    https://marketplace.visualstudio.com/items?itemName=djabraham.vscode-yaml-validation

    Uses the well known js-yaml parser with some TS types added, converts the returned structures to their JSON AST Equivalent, and then uses the standard JSON validation already built into VS Code. The excellent example cited above, is actually the source for that validation.

    This still needs some work, because the completions aren't being returned. But basic validation seems to be working. I will put some more time into it, when I can.

    screen shot 04-21-16 at 08 31 pm

    screen shot 04-21-16 at 08 30 pm

  10. aeschli commented on Apr 22, 2016

    @aeschli
    Contributor

    Daniel Abraham (@djabraham) Awesome! Let me know if I can help!

  11. adamvoss commented on Jun 20, 2017

    @adamvoss

    Daniel Abraham (@djabraham) Thanks for showing this is possible!!

    I wanted to add more functionality, but thought more good could come long-term with less forking. The result was that I wrote vscode-yaml (marketplace) (GitHub).

    From the user perspective, I believe it provides all the functionality of vscode-yaml-validation plus:

    I kept the same design decision to use the json.schemas setting key, so it should function as a drop-in replacement for vscode-yaml-validator.

    Sadly, no completion in this extension either. It was more-or-less working, but all the suggestions generated JSON. While the JSON was valid YAML, it was not what anyone would want, so I disabled it. My determination was that it would be best to write the suggestion code from scratch rather than trying to "patch" the code from vscode-json-languageservice. I spent more time on this than I anticipated and I'm not sure I am not sure I will ever get around to completion. (PRs welcome of course).

    Out of convenience it forks vscode-json, which is just the piece that wires the service to the VS Code client. It takes a source-level dependency on vscode-json-languageservice to be access some internal types. Otherwise, it doesn't fork its dependencies. This caused submitting one upstream bug fix microsoft/vscode-json-languageservice#7 and I have submitted the scalar classification code written for this to the upstream parser library possible future inclusion (mulesoft-labs/yaml-ast-parser#14).

  12. djabraham commented on Jun 20, 2017

    @djabraham

    Adam Voss (@adamvoss)

    I like the fact that validation is integrated with completion and formatting. That makes perfect sense. It's good to see major progress, cause I love the YAML format. Especially for schema files and Kubernetes configs.

    One Q, do you plan to eventually add support for multiple yaml (concatenated) files? That seems to be a major pain point for advanced users. I started restructuring the repo in another branch, per the latest JSON validation project and the MS example for newer Language Server; but a new position currently demands focus and I kept putting it off.

    djabraham/vscode-yaml-validation#2

    Thanks regardless, and nice work!

  13. adamvoss commented on Jun 20, 2017

    @adamvoss

    Daniel Abraham (@djabraham) Thanks! To avoid spamming this thread, I'll respond on your linked issue.

  14. purefan commented on Oct 6, 2017

    @purefan

    Good stuff! My use-case is however slightly different, Im looking for a serverless intellisense formatter, its basically yaml + keywords that start with !Ref, for example:
    Timeout: !Ref DefaultLambdaTimeout

    Is there a quick way to add this to the current yaml formatter?

  15. adamvoss commented on Oct 19, 2017

    @adamvoss
  16. Dominik-K commented on Mar 26, 2018

    @Dominik-K

    FYI: Another option would be the YAML Support by Red Hat extension. The underlying yaml-language-server integrates all schemas from the JSON Schema Store. Kubernetes schema is currently included from a Gist.

    Adam Voss (@adamvoss) Daniel Abraham (@djabraham) You want to share forces with them, maybe?

  17. djabraham commented on Mar 27, 2018

    @djabraham

    My extension was retired a while back. It looks like the vscode-yaml extension of Adam's was also recently retired. The RedHat extension was a possible factor: adamvoss/vscode-yaml#23

    Adam Voss (@adamvoss) You guys did great work in a much needed area. I hope experience gained from growing a team and any new skills you've acquired, serve you well into the future.

    Many thanks to those who create new inroads for technology, and to those who broaden them. You've helped great many travelers, from getting mired down.

  18. aeschli commented on Oct 28, 2019

    @aeschli
    Contributor

    No plans on our side to add this functionality given that there are extensions implementing it already. I'll continue to open up the vscode-json-languageservice so it can also be used for other parsers that the JSON parser. If there's anything missing please file issues!

  19. locked and limited conversation to collaborators on Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestjson

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions