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] [SPRING] Missing Java Bean Validation annotations on RequestBody #13932

Closed
Mintas opened this issue Nov 7, 2022 · 0 comments · Fixed by #13936
Closed

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

Mintas opened this issue Nov 7, 2022 · 0 comments · Fixed by #13936

Comments

@Mintas
Copy link
Contributor

Mintas commented Nov 7, 2022

Description

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

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

#13936

Suggest a fix/enhancement

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

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

Successfully merging a pull request may close this issue.

1 participant