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

Convert model and message schema to standardized format #3441

Open
jasongrout opened this issue Apr 19, 2022 · 3 comments
Open

Convert model and message schema to standardized format #3441

jasongrout opened this issue Apr 19, 2022 · 3 comments

Comments

@jasongrout
Copy link
Member

As @bollwyvl points out here and here, it would be nice if our schemas for models and/or messages were documented in a standardized json schema format (like json-schema, for example).

@bollwyvl
Copy link
Contributor

Yay, this would be awesome, if only for documentation purposes, but definitely for broader implementation of the core widgets in different kernels, which would be a huge step forward... better still if this could be automated. This would be a bit beyond my usual go-to recommendation of quicktype, as evented models aren't built into most languages 😆.

To that end: here's a really crazy notebook that generates schema and then generates concrete typescript kernel classes that use the async iterators everywhere. I am not suggesting that the resulting classes are useful, but some of the intermediate mapping tables might be.

Long term: I feel like every darned Widget (or maybe HasTraits) subclass could have a to_schema method: no idea what to do about add_traits, though... and would complement, but not replace, language-native typing... but that's a story for another day, after ipython/traitlets#705.

@AntoinePrv
Copy link

AntoinePrv commented Jan 23, 2023

Hello, I'm just starting to contribute in the widget ecosystem.

Is this issue referencing the ipywidgets/packages/schema/jupyterwidgetmodels.latest.json file?
We started using this file in the tests in XWidgets as we reused the JS part from IPyWidgets.

We also noticed that this is not a proper JSON schema, and since we use a default JSON schema validator, we have to modify the JSON before passing it to the validator.
We'd like to improve the the file generated here to make it standard compliant.
So far we've found:

  • Rename "attributes" > "properties"
  • Change "attributes": [{"name": "somename", ...}, ...] with "properties": {"name": {...}, ...}
  • Rename types:
    • "bool" > "boolean"
    • "int" > "integet"
    • "float" > "number"
    • "bytes" > "string" ?
    • "reference" > "string" ? Replaced with their object value.
  • Replace "allow_none" > "type": ["sometype", "null"]
  • Add null to "enum" when "allow_none": true
  • Add "required" field with required properties (all of them)?

Other specs of JSON schema could be interesting but this is a good start. What do you think?

@bollwyvl
Copy link
Contributor

Yerp, nothing's worse than almost JSON schema.

Further, having this available as-packaged (on the Python and JS side, initially) would be super useful, though potentially as another package, or only in sdist, etc.

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

3 participants