Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #8690
Closed
Open
Issue created Feb 12, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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 );
`
Assignee
Assign to
Time tracking