swashbuckle 媒体类型应用程序/八位字节流 [英] swashbuckle mediatype application/octetstream

查看:45
本文介绍了swashbuckle 媒体类型应用程序/八位字节流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将媒体类型生成为应用程序/八位字节流的端点.但是,当我生成 swagger json 时,它将生产"指定为应用程序/json"我没有在 swagger 中做任何特殊的配置.我所做的只是导入 swagger nuget 并保持默认配置不变.请在端点下方找到:

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);
    }

还有来自 swagger 的 jsonSchema:

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

}

推荐答案

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

I have a fork of swashbuckle that I have been adding functionality like what you are asking, now you can add Annotations like:

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

这是一个工作示例:
http://swashbuckletest.azurewebsites.net/swagger/ui/index#/图像/图像_获取


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

这篇关于swashbuckle 媒体类型应用程序/八位字节流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆