Closed
Description
I have a legacy API that takes an enumeration as argument, here is a yaml fragment of OpenAPI spec :
...
components
schemas:
Mode:
type: string
enum:
- a
- b
Such enumeration should be used as string in API, but is translated to Enum with processor (why not, this is not the problem) as :
@Generated(value = "openapi-processor-spring", version = "2023.4", date = "2023-10-05T14:30:44.211810700+02:00")
public enum Mode {
A("a"),
B("b");
...
Internally spring use StringToEnumConverterFactory to convert the string to enumeration:
Daemon Thread [parallel-3] (Suspended)
owns: FluxConcatMapNoPrefetch$FluxConcatMapNoPrefetchSubscriber<T,R> (id=741)
owns: FluxConcatMapNoPrefetch$FluxConcatMapNoPrefetchSubscriber<T,R> (id=742)
Enum<E>.valueOf(Class<T>, String) line: 268
StringToEnumConverterFactory$StringToEnum<T>.convert(String) line: 54
StringToEnumConverterFactory$StringToEnum<T>.convert(Object) line: 39
GenericConversionService$ConverterFactoryAdapter.convert(Object, TypeDescriptor, TypeDescriptor) line: 436
ConversionUtils.invokeConverter(GenericConverter, Object, TypeDescriptor, TypeDescriptor) line: 41
DefaultFormattingConversionService(GenericConversionService).convert(Object, TypeDescriptor, TypeDescriptor) line: 192
TypeConverterDelegate.convertIfNecessary(String, Object, Object, Class<T>, TypeDescriptor) line: 129
SimpleTypeConverter(TypeConverterSupport).convertIfNecessary(Object, Class<T>, TypeDescriptor) line: 73
SimpleTypeConverter(TypeConverterSupport).convertIfNecessary(Object, Class<T>, MethodParameter) line: 53
BindingContext$ExtendedWebExchangeDataBinder(DataBinder).convertIfNecessary(Object, Class<T>, MethodParameter) line: 729
RequestParamMethodArgumentResolver(AbstractNamedValueArgumentResolver).applyConversion(Object, AbstractNamedValueArgumentResolver$NamedValueInfo, MethodParameter, BindingContext, ServerWebExchange) line: 193
and it fail, because Enum.valueOf(Mode.class, "a") delegates to internal enumConstantDirectory which contains only uppercase values "A" and "B" !
So the only workaround is to inject custom converter, but this is not desirable.
Metadata
Metadata
Assignees
Labels
No labels