Open jasongrout opened 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.
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:
"attributes"
> "properties"
"attributes": [{"name": "somename", ...}, ...]
with "properties": {"name": {...}, ...}
"bool"
> "boolean"
"int"
> "integet"
"float"
> "number"
"bytes"
> "string"
?"reference"
> "string"
?"allow_none"
> "type": ["sometype", "null"]
null
to "enum"
when "allow_none": true
"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?
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.
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).