wildlife-dynamics / ecoscope-workflows

An extensible task specification and compiler for local and distributed workflows.
https://ecoscope-workflows.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

Pydantic JSON Schema generator for react-jsonschema-form #82

Closed cisaacstern closed 1 month ago

cisaacstern commented 1 month ago

Pydantic allows us to customize json schema output.

Now that @juanlescano-ng has identified react-jsonschema-form as the form generator for the front end, we will need to make sure our JSON schema (as output by the 'get-params' command) conforms to this expectation.

Certain Python/pydnatic field types may not fit a data type supported by react-jsonschema-forms, which highlights the importance of testing JSON Schema generation for all newly added (and existing) tasks.

Among other things, options for handling data types that don't directly parse into compatible JSON schema include:

cisaacstern commented 1 month ago

The json provided in this comment is one reference point for what this data structure looks like:

https://github.com/wildlife-dynamics/ecoscope-workflows/pull/45#issuecomment-2231489970

The react-jsonschema-form playground is liked at the bottom of that comment, which is a very useful reference.

cisaacstern commented 1 month ago

The more I am thinking about this the more I wonder if the best way to approach this is:

It would be an interesting thought experiment to see if all of the user-configurable parameters we currently have for our tasks could be expressed within these constraints.

If/when they cannot, we have at least two paths of recourse:

  1. Investigate custom react-jsonschema-form widgets (if the gap between supported inputs and desired parameter type is large)
  2. Use pydantic BeforeValidators to coerce types, e.g. json array of floats could be coerced into a numpy array, etc, for cases where it's more a matter of type casting/coercion
cisaacstern commented 1 month ago

duplicate of #93, closing