Support for Schema with subSchema(s)

Hi,

I wonder if it is possible somehow to define (sub-)schema’s together with UI how to render the (sub-) schema and then reference this schema to be used as the data schema for property inside another schema?

To make this question more practical, let’s consider an example:

  • Say we need a form to manage the paint state of a house
  • the house has a predefined format: floor0, floor1, floor2. Floor0 has subProperties hallway, toilet, kitchen, garage, … Floor2 has subproperties hallway, room1, room2, room3, …
  • every ‘room’ has the same type of data to manage: surface (number), painted (boolean), color (enum)
  • if a room is painted, you need to select the color of the room
  • we want to reuse this logic on all defined rooms, without code duplication (or dynamic json creation)

I know we can define a room type and use it in an array to manage an arbitrary collection of rooms of this type.

But I don’t see how it would be currently possible to define a room and to assign this room type to all of the predefined rooms of each available floor.

Could you please assist me how to accomplish this use case?

Thanks a lot for your support!

Kind regards,
Pieter

Hi @Sewdn,

We optionally accept a uischemas registry. Whenever a subschema (i.e. nested object or array) shall be rendered this registry is queried for a uischema. Instead of using the registry the subuischema can also be hard coded within the UI Schema using the options.detail property. When neither of these options are used the sub-uischema will be generated.

Regarding your JSON Schema you can use $references to not repeat yourself, see here.

Thanks for your answer.

Regarding the JSON schema: using inline $defs and $refs to reference them works like a charm.

I’ll have to experiment some more regarding the UI Schema options, but thanks for the pointers where to start looking. I think it’ll work out.

1 Like