You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a Swagger spec declares an enum but also specifies a maxLength, running swagger-codegen with useBeanValidation enabled, will tag the enum with @Size constraint. Invoking validation on the generated model will result in this Java error: HV000030: No validator could be found for constraint 'jakarta.validation.constraints.Size' validating type
The reason for the failure is that @Size can only be used to enforce validation on String or Collections, so if it's used on an enum type, the jakarta library will panic.
Find a swagger spec that contains enum with maxLenghh or add one to any swagger spec.
Run the command above to generate JAVA code with bean validation.
Invoke the validation on the model containing the enum using Validation.buildDefaultValidatorFactory().getValidator().validate(toValidate);
Related issues/PRs
N/A
Suggest a fix/enhancement
SImple fix: remove maxLength from the enum declaration, or remove @Size manually in the generated model. However it would be good for swagger-codgen to handle this sensibly.
Perhaps we can update the mustache template to add @Size for non-enum type like this:
Description
If a Swagger spec declares an enum but also specifies a
maxLength
, running swagger-codegen withuseBeanValidation
enabled, will tag the enum with@Size
constraint. Invoking validation on the generated model will result in this Java error:HV000030: No validator could be found for constraint 'jakarta.validation.constraints.Size' validating type
The reason for the failure is that
@Size
can only be used to enforce validation on String or Collections, so if it's used on an enum type, the jakarta library will panic.Swagger-codegen version
The issue is observed in version
3.0.62
Swagger declaration file content or URL
My Swagger spec contains this enum declaration:
Command line used for generation
This command was run on mac using the latest
swagger-codegen
installed using brew:Steps to reproduce
maxLenghh
or add one to any swagger spec.Validation.buildDefaultValidatorFactory().getValidator().validate(toValidate);
Related issues/PRs
N/A
Suggest a fix/enhancement
SImple fix: remove
maxLength
from the enum declaration, or remove@Size
manually in the generated model. However it would be good for swagger-codgen to handle this sensibly.Perhaps we can update the mustache template to add
@Size
for non-enum type like this:The text was updated successfully, but these errors were encountered: