I have an endpoint that produces mediatype as application/octet-stream. However, when I generated the swagger json, it specifies "produces" as "application/json" I did not do any special configs in swagger. All I did was import swagger nuget and just kept the default configuration as is. Please find below the endpoint:
[HttpPost]
[Route("document/method1")]
public HttpResponseMessage method1([FromBody]SomeModel SomeModelValue)
{
// code that generates the file
if (File.Exists(outputFilePath))
{
byte[] resultFile = File.ReadAllBytes(outputFilePath);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created);
response.Content = new ByteArrayContent(ResultFile);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue(ContentDispositionHeaderValue);
response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeHeaderValue);
response.Content.Headers.ContentLength = ResultFile.Length;
File.Delete(inputFilePath);
File.Delete(outputFilePath);
return response;
}
else
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
}
And the jsonSchema from swagger:
"/document/method1": {
"post": {
"tags": ["Document"],
"operationId": "Document_Method1",
"consumes": ["application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded"],
"produces": ["application/json", "text/json", "application/xml", "text/xml"],
"parameters": [{
"name": "SomeModelValue",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SomeModel"
}
}],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
}
}
}
}
I have a fork of swashbuckle that I have been adding functionality like what you are asking, now you can add Annotations like:
Here is a working sample:
http://swashbuckletest.azurewebsites.net/swagger/ui/index#/Image/Image_Get
My fork is on Nuget:
https://www.nuget.org/packages/Swagger-Net/