react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Adding different display name to enum with ui-Schema

Open perelin opened this issue 1 year ago • 1 comments

Prerequisites

What theme are you using?

core

What is your question?

We are auto-generating our base json-schema files directly from a (graphql) API schema. So enums there are not meant for human consumption and need labels.

We use ui-Schema to augment the generated json-schema files with all necessary presentation layer things (titles, order, etc). The only thing that we dont manage to do is give enums new labels.

How can we approach this?

perelin avatar Jun 11 '24 08:06 perelin

I don't think you can do that today, the only ways to label an enum are using oneOf/title or the deprecated & nonstandard enumNames property in the JSON Schema (docs).

The reason we deprecated enumNames is because it's a nonstandard JSON Schema field. I think it could be useful to have a similar feature added to the uiSchema. We'd be happy to review a PR if you are interested in contributing this feature!

nickgros avatar Jun 21 '24 15:06 nickgros

Late reply, sorry.

I found that it does seem possible somehow to attach a title to a any/oneOf somehow. But there are other issues keeping me :) https://github.com/rjsf-team/react-jsonschema-form/issues/4260 thanks anyway!

perelin avatar Aug 01 '24 14:08 perelin

Glad you have a workaround for this issue @perelin . If you don't mind, I want to re-open this ticket because I think we'll want to do this eventually. We will plan to keep enumNames in the library until we provide some way to override enum display values via the uiSchema. This issue can track that new feature (and also indicate to us that we can remove enumNames once we release the following major version)

nickgros avatar Aug 02 '24 19:08 nickgros

Fixed with https://github.com/rjsf-team/react-jsonschema-form/pull/4263

heath-freenome avatar Aug 04 '24 01:08 heath-freenome