我有一个端点,它产生mediatype作为application / octet-stream。然而,当我生成swagger json时,它指定"产生" as" application / json" 我没有做任何特殊的配置。我所做的只是导入swagger nuget,并保持默认配置。 请在端点下方找到:
[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);
}
来自swagger的jsonSchema:
"/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"
}
}
}
}
}
答案 0 :(得分:0)
我有一个swashbuckle的分支,我一直在添加你所要求的功能,现在你可以添加注释,如:
[SwaggerResponse(200, mediaType: "image/png")]
这是一个工作样本:
http://swashbuckletest.azurewebsites.net/swagger/ui/index#/Image/Image_Get
我的叉子在Nuget上:
https://www.nuget.org/packages/Swagger-Net/