Dynamic JSON Schemas handling

Hello,
I am building an app that has a Python backend, this python backend uses pydantic which is a lib that allows to export Python classes as JSON Schema.

My app is command based and I define commands from the python side like that :

@register_command
class CreatePointCmd(Command):
    x: float = 1
    y: float = 1
    z: float = 1
    name: str | None = None

This generates the given schema :

    "CreatePointCmd": {
        "properties": {
            "x": {
                "default": 1,
                "title": "X",
                "type": "number"
            },
            "y": {
                "default": 1,
                "title": "Y",
                "type": "number"
            },
            "z": {
                "default": 1,
                "title": "Z",
                "type": "number"
            },
            "name": {
                "anyOf": [
                    {
                        "type": "string"
                    },
                    {
                        "type": "null"
                    }
                ],
                "default": null,
                "title": "Name"
            }
        },
        "type": "object"
    },

This is great because it allows me to have automatic form generation just by writing the Python code.
My issue is that doing it that way I can’t adapt form behaviour to a given command. I can write custom renderers, for example for the IntegerField but then all commands needing an integer would end up using this custom renderer while I would not want all commands needing an integer to use this custom one.

Furthermore my JSON Schema are most of time using nested $defs as property fields as the data my commands needs aren’t raw basic types but more complex ones. I feel JSONForms is adapted to my need but I also feel I’m going a bit off road and I have a hard time making it work as I would like to.

Ideally I would want to specify everything in the JSON Schema and have the less work possible to do on the React side of things so that if I change something in the backend it’s automatically updated in the frontend.

I would appreciate any advice or any documentation/example that I could get inspiration from so that I can solve my issue in the most robust and elegant way :slight_smile:

Thank you very much

Hi @Jojain,

Each renderer is associated with a tester. Each tester can be arbitrarily complex, so if you register a custom number renderer you can use a very specialized tester which only triggers this renderer for specific commands.

If you have the same set of customizations throughout multiple commands you can also tag the JSON Schema accordingly with some custom properties. The tester can then check these properties to determine whether they apply. This way, after you have all the customizations in place, you can fully control the behavior from your python commands.