jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook
https://ipywidgets.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.15k stars 950 forks source link

Convert model and message schema to standardized format #3441

Open jasongrout opened 2 years ago

jasongrout commented 2 years ago

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 commented 2 years ago

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 :laughing:.

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 https://github.com/ipython/traitlets/pull/705.

AntoinePrv commented 1 year ago

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:

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

bollwyvl commented 1 year ago

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.