虚张声势的媒体类型 application/octetstream

swashbuckle mediatype application/octetstream

我有一个生成媒体类型为 application/octet-stream 的端点。但是,当我生成 swagger json 时,它将 "produces" 指定为 "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 的 json 架构:

"/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"
            }
        }
    }
}

}

我有一个 swashbuckle 的分支,我一直在添加你所要求的功能,现在你可以添加注释,如:

[SwaggerResponse(200, mediaType: "image/png")]

这是一个工作示例:
http://swashbuckletest.azurewebsites.net/swagger/ui/index#/Image/Image_Get


我的叉子在 Nuget 上:
https://www.nuget.org/packages/Swagger-Net/