swagger-api / swagger-api/swagger-codegen

Java codegen, when post a String parameter, unexpected quote in json

Open
#1,641 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

My code :

@Path("/{id}")
  @PUT
  @Consumes({"application/json"})
  @ApiOperation(value = "Update Tab info", notes = "test")
  public Result put(@PathParam("id")final String id, String tab) {
    return super.put(id, tab);
  }

swagger-spec

"put": {
                "tags": [
                    "tab"
                ],
                "summary": "Update Tab info",
                "description": "If current user is owner, he can update all attribute. If current user is signer, he could only update data",
                "operationId": "put",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "in": "body",
                        "name": "body",
                        "required": false,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "successful operation",
                        "schema": {
                            "$ref": "#/definitions/Result"
                        }
                    }

codegen generate code:

  public Result put(String id, String body) throws ApiException {
    Call call = putCall(id,body, null, null);
    Type returnType = new TypeToken<Result>(){}.getType();
    return apiClient.execute(call, returnType);
  }

When I use this method, I capture the package with wireshark
screenshot:
image

If I use the swagger-ui to call this API, I capture the package with wireshark
screenshot:
image

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 by reproducing the request from the generated Java client's put method and compare its body with the Swagger UI request; inspect the request-building path used by putCall. Done means posting a String body produces the same JSON payload without the unexpected quote.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.