-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
I have a swagger.yaml with a post method that produces application/json and which consumes XML. Here's an excerpt:
post:
summary: Store a model.
description: Stores the XML content of the specified model.
consumes:
- application/xml;charset=UTF-8
parameters:
- name: model
in: body
description: The model XML you want to store
schema:
type: string
required: trueI generated the Java client from the swagger.yaml using swagger-codegen-cli-2.2.1.jar and the --lang java option. I did not specify a --library option. (I doubt it's relevant but, just in case, I also specified these options in an associated json config file: apiPackage, groupId, artifactId and artifactVersion.)
However when I issue a POST request with an XML string as input I get this error in the client:
com.mycompany.myapi.ApiException: Content type "application/xml;charset=UTF-8" is not supported
at com.mycompany.myapi.ApiClient.serialize(ApiClient.java:889)
at com.mycompany.myapi.ApiClient.buildCall(ApiClient.java:1105)
at com.mycompany.myapi.client.DefaultApi.modelsPostCall(DefaultApi.java:523)
at com.mycompany.myapi.client.DefaultApi.modelsPostWithHttpInfo(DefaultApi.java:544)
The generated method in com.mycompany.myapi.ApiClient looks like this:
/**
* Serialize the given Java object into request body according to the object's
* class and the request Content-Type.
*
* @param obj The Java object
* @param contentType The request Content-Type
* @return The serialized request body
* @throws ApiException If fail to serialize the given object
*/
public RequestBody serialize(Object obj, String contentType) throws ApiException {
if (obj instanceof byte[]) {
// Binary (byte array) body parameter support.
return RequestBody.create(MediaType.parse(contentType), (byte[]) obj);
} else if (obj instanceof File) {
// File body parameter support.
return RequestBody.create(MediaType.parse(contentType), (File) obj);
} else if (isJsonMime(contentType)) {
String content;
if (obj != null) {
content = json.serialize(obj);
} else {
content = null;
}
return RequestBody.create(MediaType.parse(contentType), content);
} else {
throw new ApiException("Content type \"" + contentType + "\" is not supported");
}
}In my case obj is a String. It looks like you don't support application\xml. Is this true? If so, how soon can we expect a fix please? Alternatively can you recommend a workaround I can use? I don't mind hacking the generated code to make it work until a proper fix is released.
Related issues
Is this related? http://stackoverflow.com/questions/33937787/how-to-write-swagger-api-that-accepts-xml-in-request-body . @wing328 suggested @splintor create a new issue but I can't tell whether that ever happened.