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

[Micronaut server] Add ability to exclude Swagger ApiOperation and ApiResponses annotation output from generated methods #12223

Open
mshannongit opened this issue Apr 24, 2022 · 1 comment

Comments

@mshannongit
Copy link

Leveraging release 5.4 ...

Given a yaml input document containing a snippet like the following ...

paths:
  /management/api/v1/users/{userId}:
    patch:
      x-codegen-request-body-name: message
      tags:
        - Backup Management Service
        - Backup Management Service Users
      summary: Update the specified user details
      description: Update the specified user details
      operationId: updateUserAsAdmin
      parameters:
        - name: userId
          in: path
          description: User identifier which may be extended format identifier e.g. machine:89928359235
          required: true
          schema:
            type: string
      requestBody:
        description: Details of user to update
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/rest.UserUpdateRequest'
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/rest.UserResource'
        '401':
          $ref: '#/components/responses/401-Unauthorized'
        '404':
          $ref: '#/components/responses/404-NotFound'

the generated java output looks something like ...

    /**
     * Update the specified user details
     * Update the specified user details
     *
     * @param userId User identifier which may be extended format identifier e.g. machine:89928359235 (required)
     * @param message Details of user to update (required)
     * @return RestUserResource
     */
    @ApiOperation(
        value = "Update the specified user details",
        nickname = "updateUserAsAdmin",
        notes = "Update the specified user details",
        response = RestUserResource.class,
        authorizations = {
            @Authorization(value = "bearerAuth")
        },
        tags={})
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "OK", response = RestUserResource.class),
        @ApiResponse(code = 401, message = "Unauthorized", response = RestError.class),
        @ApiResponse(code = 404, message = "Not Found", response = RestError.class)})
    @Patch(uri="/management/api/v1/users/{userId}")
    @Produces(value = {"application/json"})
    @Consumes(value = {"application/json"})
    public Mono<RestUserResource> updateUserAsAdminApi(
        @PathVariable(value="userId") @NotNull String userId, 
        @Body @NotNull @Valid RestUserUpdateRequest message
    ) {
        return updateUserAsAdmin(userId, message);
    }

It would be nice if there were a mechanism to exclude the generation of the ApiOperation and ApiResponses annotation output in the java. They yaml document is already the source of truth, duplicating the output in Java whilst nice also makes for massive Java files. In our case, we won't be generating from Java back to Yaml and have no need for those annotations to appear in the source.

@mshannongit
Copy link
Author

The jaxrs generator provides this capability by way of the useSwaggerAnnotations option:

"Whether to generate Swagger annotations"

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java

@mshannongit mshannongit changed the title [Micronaut server] Add ability to exclude ApiOperation and ApiResponses annotation output from generated methods [Micronaut server] Add ability to exclude Swagger ApiOperation and ApiResponses annotation output from generated methods Apr 24, 2022
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