Many of the fields in my models use java.util.Optional, and it generally seems to be pretty well supported by auto-restdocs. However, I noticed that my Optional Enum fields do not get a constraint message generated the same way that raw Enum fields do. It seems like this behavior would be desirable for most users.
Note that it looks like this is possibly related to: https://github.com/ScaCap/spring-auto-restdocs/issues/288. Perhaps there should be a collection of known types (Collection, Optional etc.) where the generic parameter is used to determine whether to generate the enum constraint?
Many of the fields in my models use java.util.Optional, and it generally seems to be pretty well supported by auto-restdocs. However, I noticed that my Optional Enum fields do not get a constraint message generated the same way that raw Enum fields do. It seems like this behavior would be desirable for most users.
One possible solution would be to add a special check if the type is java.util.Optional in the constraint message generation code: https://github.com/ScaCap/spring-auto-restdocs/blob/46df17af26a3ae097d063439c5dbfb37ce5f685d/spring-auto-restdocs-core/src/main/java/capital/scalable/restdocs/constraints/ConstraintReaderImpl.java#L137, and, if so, use
MethodParameter.getGenericParameterType()
to get the underlying Enum type (as opposed to usingMethodParameter.getParameterType()
).Note that it looks like this is possibly related to: https://github.com/ScaCap/spring-auto-restdocs/issues/288. Perhaps there should be a collection of known types (Collection, Optional etc.) where the generic parameter is used to determine whether to generate the enum constraint?