-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Description
For multipart uploads that contain a file and some other part, like a JSON object, it would be very useful to be able to specify a content type on the File parts other than the actual binary file. This is critical for Java applications that need the content type of the part in order to know how to deserialize the json or xml into a Java object.
For what its worth, I was able to get this working by modifying swagger-ui,js to use a Blob as the FormData. I had to add a "contentType" field to the Parameter object. I know this violates the spec, but this worked for my project.
swagger-ui.js line 1797:
if (param.paramType === 'form') {
if (param.type.toLowerCase() !== 'file' && map[param.name] !== void 0) {
if(typeof param.contentType !== 'undefined') {
bodyParam.append(param.name, new Blob([map[param.name]], { type: param.contentType}));
}
else {
bodyParam.append(param.name, map[param.name]);
}
}
}
In the swagger doc, I can define the file and the json object parameters like so:
{
"name": "story",
"description": "The story object in json format",
"required": true,
"paramType": "form",
"type": "Story",
"contentType": "application/json"
},
{
"name": "file",
"description": "The base64 encoded multipart file attachment. ",
"required": true,
"paramType": "form",
"type": "File"
}
Refer to this discussion / issue in swagger-core for more detail - swagger-api/swagger-core#636