swagger-api / swagger-api/swagger-codegen
Java codegen, when post a String parameter, unexpected quote in json
Open
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:

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

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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