swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Openapi endpoint generating values for @Context arguments

Open gssbzn opened this issue 2 years ago • 0 comments

This is an issue we've been seeing for a while now and we haven't figured out what or when it broke since it is only impacting "packaged" versions of our app and we are not able to reproduce locally so debugging has been a bit complicated

This is what we know so far, we have an endpoint annotated as

  @GET
  @Produces({MediaType.APPLICATION_JSON})
  @Operation(
      summary = "Return the status of the system")
 public Response getSystemStatus(
      @Context final HttpServletRequest pRequest) final Boolean pEnvelope) {
// not important
}

which is generating the following spec

paths:
  /api/public/v1.0:
    get:
      description: This resource returns information about the MongoDB application
        along with API key meta data.
      operationId: getSystemStatus
      requestBody:
        content:
          '*/*':
            schema:
              $ref: '#/components/schemas/HttpServletRequest'
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SystemStatus'
          description: OK

For some reason HttpServletRequest is being documented even tho is annotated with @Context and in theory should be ignored by default. We are only seeing this on our "live" envs and not locally We are also seeing this for multiple classes annotated with @Context but not all and the only thing they have in common is they are all GET operations and they get documented as part of the request body So far I have managed to see that when io.swagger.v3.jaxrs2.Reader is called the param is already there and being added but I'm uncertain if the pram should've been filtered in a previous class/method

I'm happy to try and add a filter for this case but I'm currently uncertain what the best class/filter would be to achieve this fix

Some additional info Java version: 17.0.8.1+1 swagger-core version 2.2.16 (and managed to reproduce up to 2.2.10)

gssbzn avatar Oct 17 '23 13:10 gssbzn