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
  • #13932
Closed
Open
Issue created Nov 07, 2022 by Administrator@rootContributor

[BUG] [SPRING] Missing Java Bean Validation annotations on RequestBody

Created by: Mintas

Description

We are unable to generate beanValidation annotations for RequestBody params. Looks like the feature was missing in revision 8952815b

Proposed changes should cover this bug and allow beanValidation annotations to be generated on RequestBody params too.

openapi-generator version

6.2.1 , current master

OpenAPI declaration file content or url

Provided configuration:

paths:
  /add:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: integer
              title: quantity
              minimum: 2
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: boolean

Generates:

@Operation(
        operationId = "addPost",
        responses = {
            @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation =  Boolean.class)))
        }
    )
    @RequestMapping(
        method = RequestMethod.POST,
        value = "/add",
        produces = { "application/json" },
        consumes = { "application/json" }
    )
    default ResponseEntity<Boolean> cartKekPost(
        @Parameter(name = "body", description = "", required = true) @Valid @RequestBody Integer body
    ) {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

    }

Must have:



    default ResponseEntity<Boolean> addPost(
        @Min(2)  @Parameter(name = "body", description = "", required = true) @Valid @RequestBody Integer body
    ) {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

    }
Command line used for generation

Plugin configuration: (beanValidation is enabled by default)

generatorName = 'spring' configOptions = [ dateLibrary: 'java8', interfaceOnly: 'true', openApiNullable: 'false', java8: 'false' ] importMappings = ['java.time.OffsetDateTime': 'java.time.Instant'] typeMappings = ['OffsetDateTime': 'Instant']

Steps to reproduce

./gradlew openApiGenerate

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/13936

Suggest a fix/enhancement

will propose a solution as PR from fork repository https://github.com/Mintas/openapi-generator

Assignee
Assign to
Time tracking