dora icon indicating copy to clipboard operation
dora copied to clipboard

Json schemas for VSCode YAML Support

Open haixuanTao opened this issue 1 year ago • 0 comments

In an effort to address, developers difficulty in discovering dora-rs functionality, I'm adding a way to:

  • Generate JSON Schema: https://json-schema.org/ using schemars
  • JSON Schema can be interpreted by many extension to give us YAML validation, documentation and suggestions. In my case, I'm using VSCode most popular extension for YAML which is redhat.vscode-yaml

This enables:

  • Documentation that is directly generated from the docstring within the rust code
  • Suggestions from the field defined in the Rust Code
  • Validation of type

Edge cases

Failure to auto-generate schema

Some auto-generation of some of our rust struct definition did not work. They are the one that are using serde(from= such as: https://github.com/dora-rs/dora/blob/558fa149079368a7abca01e35f23aafcff86f575/libraries/core/src/descriptor/mod.rs#L270-L280

In those case I had to remove the validation so that our current dataflow passes.

Failure to manage #[serde(flatten)] with additional properties

In our Nodes definition, we are using #[serde(flatten)] of an enum with some additional properties.

In order to validate those additional properties, I had to set additionalproperties to true.

Demo

https://github.com/dora-rs/dora/assets/22787340/4839f248-e9cc-47e6-a015-4ca53226864e

haixuanTao avatar May 15 '24 13:05 haixuanTao