Using i18n for enum translation

I have run into a similar problem to #1642 where there is a max call stack error when there are too many oneOf options.

My initial thought was that I could use the getOptionLabel and getOptionKey in the AutoComplete component to render the proper label when I pass in options in an enum with value and label specified. My options are being passed by a custom renderer as follows:

const enumOptions = props.schema.enum?.map((enumOption: {label: string, value: any}) => {
return {label: enumOption.label, value: enumOption.value} as EnumOption;
});

Unfortunately, I run into the AJV error of “must be equal to one of the allowed values” because the options are objects (EnumOption) and the value is a string (the option key). Is there a way to make this possible? I saw the reference to using i18n for translation of the values, but would that work with a list of enum options that could not be hardcoded (dynamically pulled from the services)?

Hi @pjbiogit,

The JSON Schema and the actual data must fit together. So whatever is modeled in the JSON Schema must actually be set, otherwise you will get validation errors.

If you want to store both label and enum value in the schema without using oneOf, you could for example use a custom x-enumLabels array and then match actual enum value with its label via its index.

Or if you don’t care about the validation you could just use x-enumOptions instead of enum.