swagger-api / swagger-api/swagger-codegen
Generated RestTemplate ApiClient returns application/json if it exists in the consumes list, however the client expects PUT methods to use forms, and there is no apparent way to configure the expected behavior
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
RestTemplate APIClient does not allow any mechanism for setting the content type header. Unfortunately the swagger.json I am parsing specifies content type at the root
"consumes": ["application/json", "application/x-www-form-urlencoded"]
PUT and POST methods expect the form-urlencoded, and the generated endpoints seem to understand this...
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
if (symbol != null)
formParams.add("symbol", symbol);
if (side != null)
formParams.add("side", side);
if (simpleOrderQty != null)
formParams.add("simpleOrderQty", simpleOrderQty);
....
However the APIClient.public MediaType selectHeaderContentType(String[] contentTypes) {
if (contentTypes.length == 0) {
return MediaType.APPLICATION_JSON;
}
for (String contentType : contentTypes) {
MediaType mediaType = MediaType.parseMediaType(contentType);
if (isJsonMime(mediaType)) {
return mediaType;
}
}
return MediaType.parseMediaType(contentTypes[0]);
}
returns application/json instead and so the request ends up being built without the form values
Swagger-codegen version
2.3.1
Swagger declaration file content or url
https://testnet.bitmex.com/api/explorer/swagger.json
Command line used for generation
language: java
library: resttemplate
date-library: java8
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 with the generated RestTemplate APIClient method selectHeaderContentType and the endpoint code that builds formParams from the referenced BitMEX swagger.json. Reproduce a PUT or POST using both listed media types, then verify that the selected content type and submitted form values match the endpoint expectation. Done means the generated client handles this declaration consistently with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100