Asp.net web api Swashback mediatype应用程序/octetstream
我有一个端点,它将mediatype生成为应用程序/八位字节流。但是,当我生成swagger json时,它将products指定为application/json 我没有在招摇中做任何特殊的配置。我所做的只是导入swagger nuget,并保持默认配置不变。 请查找以下端点:Asp.net web api Swashback mediatype应用程序/octetstream,asp.net-web-api,swagger,swagger-2.0,swashbuckle,Asp.net Web Api,Swagger,Swagger 2.0,Swashbuckle,我有一个端点,它将mediatype生成为应用程序/八位字节流。但是,当我生成swagger json时,它将products指定为application/json 我没有在招摇中做任何特殊的配置。我所做的只是导入swagger nuget,并保持默认配置不变。 请查找以下端点: [HttpPost] [Route("document/method1")] public HttpResponseMessage method1([FromBody]SomeModel Som
[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);
}
还有斯威格的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"
}
}
}
}
}我有一个虚张声势的叉子,我一直在添加功能,如您所要求的,现在您可以添加注释,如:
[SwaggerResponse(200, mediaType: "image/png")]
以下是一个工作示例:
我的叉子在Nuget上:
可能非常感谢伊万为我指出了正确的帖子。对不起,我错过了,可能是重复了这个问题。无论如何,谢谢你。这有帮助。