[BUG] [sprind-cloud] Bean Validation for Type Optional is wrong
Created by: MelleD
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Invalid code for the type Optional with Bean Validation is generated.
openapi-generator version
5.0.1
OpenAPI declaration file content or url
If you post the code inline, please wrap it with
/foo:
post:
operationId: createFoo
responses:
'200':
content:
text/plain:
schema:
type: string
format: binary
parameters:
- name: filename
schema:
type: string
maxLength: 120
pattern: '^[a-zA-Z0-9_-]*$'
Generation Details
Maven plugin
<configuration>
<generatorName>spring</generatorName>
<configOptions>
<sortParamsByRequiredFlag>true</sortParamsByRequiredFlag>
<library>spring-cloud</library>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<useOptional>true</useOptional>
<skipDefaultInterface>true</skipDefaultInterface>
<useBeanValidation>true</useBeanValidation>
</configOptions>
ResponseEntity<String> getFoo(
@Pattern( regexp = "^[a-zA-Z0-9_-]*$" ) @Size( max = 120 )
@ApiParam( value = "The filename of the Aspect Model input file." ) @Valid
@RequestParam( value = "filename", required = false ) Optional<String> filename );
Steps to reproduce
Use bean validation with optionals
Suggest a fix
Generate valid code. The constraints have to be included in the Optional tag
ResponseEntity<String> getFoo(
@ApiParam( value = "The filename of the Aspect Model input file." ) @Valid
@RequestParam( value = "filename", required = false ) Optional< @Pattern( regexp = "^[a-zA-Z0-9_-]*$" ) @Size( max = 120 )String> filename );
`