Enriching enum values with UISchema

Is there a way or has your team considered giving the ability to enrich enum values with data that would naturally belong in the UI schema? Currently you can do a small bit of this by attaching a label to enum values using the oneOf and const/title strategy, but this feels kind of strange when trying to follow the paradigm of schema and UI schema. For instance what if I have some enum values but with each one I not only want a label but an image, description, and color. There is already some magic going on within the system that is mapping oneOf or enum entries to the options prop of renderers, so I am suggesting a way to add more data to each object in the options array. There are a few ways this could be done in the UI schema, probably by having a map that is keyed by enum values. I know this can be done manually with the options property of the UI schema paired with a function that can look up each enum value’s uischema, but it seems like it could be a good fit to add to one of these with context hooks. Thoughts?

[original thread by Chad Johnson]

Hi @chad-johnson(chad-johnson), I can see where you’re coming from. For example it definitely makes sense to also map description from the JSON Schema into the enum options.

I’m not that sure about properties like image or color. When using these you will need to write a custom renderer anyway. You have the uischema element already accessible within the custom renderer so you can just map these options in the way you need it.

When I understand you correctly, you’re suggesting something like this:

type: 'Control',
enumOptions: [
  {
    image: 'image',
    color: '#000000'
   },
  {
    image: 'image2',
    color: '#000001'
   },
]

which then maps each of these options per index to the one in JSON Schema.

I guess the main benefit would be that we could also overwrite labels like this, so the user no longer needs to write oneOf for enums or even when using them could still overwrite them via the ui schema.

If you’d like you can open a feature request in our repository.