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] Wrong code generation when reactive: true and useResponseEntity: false #15966

Closed
Cpt76 opened this issue Jun 30, 2023 · 0 comments · Fixed by #16230
Closed

[BUG] [SPRING] Wrong code generation when reactive: true and useResponseEntity: false #15966

Cpt76 opened this issue Jun 30, 2023 · 0 comments · Fixed by #16230

Comments

@Cpt76
Copy link

Cpt76 commented Jun 30, 2023

Description

When I generate the server using reactive: true and useResponseEntity: true all works fine, but if I set useResponseEntity: false the generated code is wrong and doesn't compile.

openapi-generator version

6.6.0

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: user-service API
  description: ''
  version: 1.94.190
servers:
  - url: http://localhost:8081/user-service
    description: Generated server url
paths:
  /api/users/{userId}:
    delete:
      tags:
        - user-controller
      operationId: deleteUser
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '204':
          description: No Content
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Not Found
        '500':
          description: Internal Server Error
components:
  schemas:
    User:
      required:
        - email
        - enabled
        - firstName
        - lastName
        - role
        - userSettings
        - username
      type: object
      properties:
        id:
          type: string
          format: uuid
        tenantName:
          type: string
        username:
          maxLength: 100
          minLength: 0
          type: string
        type:
          type: string
          enum:
            - INTERACTIVE
            - NON_INTERACTIVE
        email:
          maxLength: 150
          minLength: 0
          type: string
        firstName:
          maxLength: 100
          minLength: 0
          type: string
        lastName:
          maxLength: 100
          minLength: 0
          type: string
        companyId:
          type: string
          format: uuid
        role:
          type: string
        enabled:
          type: boolean
        externalId:
          type: string
        status:
          type: string
  securitySchemes:
    token:
      type: http
      scheme: bearer
Generation Details

openapi-generator generate -i ./openapi/openapi.yaml -o ./generated_server/ -g spring -c openapi-server-config.yaml

configuration file openapi-server-config.yaml:

artifactDescription: autogenerated api stubs
artifactId: service-openapi-api
artifactVersion: 1.94.190

library: spring-boot

groupId: com.example
parentArtifactId: service-pom
parentGroupId: com.example
parentVersion: 1.94.190

delegatePattern: true
useTags: true
reactive: true
interfaceOnly: true
useResponseEntity: false

Steps to reproduce

Run the above command with the above configuration on any openapi.yaml containing APIs returning no content, like userDelete.

The generated code is wrong and doesn't compile, e.g.

/**
   * DELETE /api/users/{userId}
   *
   * @param userId  (required)
   * @return No Content (status code 204)
   *         or Bad Request (status code 400)
   *         or Unauthorized (status code 401)
   *         or Forbidden (status code 403)
   *         or Not Found (status code 404)
   *         or Internal Server Error (status code 500)
   */
  @Operation(
      operationId = "deleteUser",
      tags = { "user-controller" },
      responses = {
          @ApiResponse(responseCode = "204", description = "No Content"),
          @ApiResponse(responseCode = "400", description = "Bad Request"),
          @ApiResponse(responseCode = "401", description = "Unauthorized"),
          @ApiResponse(responseCode = "403", description = "Forbidden"),
          @ApiResponse(responseCode = "404", description = "Not Found"),
          @ApiResponse(responseCode = "500", description = "Internal Server Error")
      }
  )
  @RequestMapping(
      method = RequestMethod.DELETE,
      value = "/api/users/{userId}"
  )
  @ResponseStatus(HttpStatus.NO_CONTENT)
  default Mono<void> _deleteUser(
      @Parameter(name = "userId", description = "", required = true, in = ParameterIn.PATH) @PathVariable("userId") UUID userId,
      @Parameter(hidden = true) final ServerWebExchange exchange
  ) {
      return deleteUser(userId, exchange);
  }

  // Override this method
  default  Mono<void> deleteUser(UUID userId,  final ServerWebExchange exchange) {
      Mono<Void> result = Mono.empty();
      exchange.getResponse().setStatusCode(HttpStatus.NOT_IMPLEMENTED);
      return result.then(Mono.empty());

  }

The error is that void is lower case (should be upper case).

When useResponseEntity: true Void is upper case and the code compiles.

@Cpt76 Cpt76 changed the title [BUG] [SPRING] Error when reactive: true and useResponseEntity: false [BUG] [SPRING] Wrong code generation when reactive: true and useResponseEntity: false Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant