Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [sprind-cloud] Bean Validation for Type Optional is wrong #8690

Open
5 of 6 tasks
MelleD opened this issue Feb 12, 2021 · 0 comments
Open
5 of 6 tasks

[BUG] [sprind-cloud] Bean Validation for Type Optional is wrong #8690

MelleD opened this issue Feb 12, 2021 · 0 comments

Comments

@MelleD
Copy link
Contributor

MelleD commented Feb 12, 2021

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 );
`
wing328 pushed a commit that referenced this issue May 18, 2021
* Fix bean validation for type Optional
#8690

* Revert path params
premiumitsolution pushed a commit to premiumitsolution/openapi-generator that referenced this issue May 26, 2021
* Fix bean validation for type Optional
OpenAPITools#8690

* Revert path params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant