swagger-api / swagger-api/swagger-core

Openapi endpoint generating values for @Context arguments

Open
#4,498 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java, where the report says the @Context parameter is already present. Reproduce the packaged-environment behavior if possible and compare it with local generation across the reported swagger-core versions. Done means @Context HttpServletRequest parameters are no longer emitted as GET request bodies in the generated OpenAPI document.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.