gpt4 book ai didi

c# - 生成的 WEB API 帮助区域文档不显示响应正文格式/示例

转载 作者:太空狗 更新时间:2023-10-29 20:27:09 27 4
gpt4 key购买 nike

我已经为我的 web api 2 项目(基于 owin/katana)创建了一个帮助区域文档。我打开了配置中的所有设置并安装了 Microsoft.AspNet.WebApi.OData。目前我有以下设置:

config.SetSampleObjects(new Dictionary<Type, object>
{
{typeof(string), "sample string"},
{typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
});

config.SetSampleForMediaType(
new TextSample("Binary JSON content. See http://bsonspec.org for details."),
new MediaTypeHeaderValue("application/bson"));

config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));

config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");

config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");

config.SetActualRequestType(typeof(string), "Values", "Get");

config.SetActualResponseType(typeof(string), "Values", "Post");

但是,我没有生成任何响应样本。我的页面应该像我在网上看到的那样

what it should look like

但它是这样的。如何显示第一张图片中所示的 JSON 等示例响应格式?

enter image description here

最佳答案

尝试使用 ResponseType 属性装饰您的 Controller 操作,如下所示:

    [HttpGet]
[Route("enterprise/")]
[ResponseType(typeof(EnterpriseViewModel))]
public IHttpActionResult Get()
{
...
}

如果您有带参数的构造函数,您还必须在 ViewModel 类中提供一个空白构造函数。

关于c# - 生成的 WEB API 帮助区域文档不显示响应正文格式/示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33858279/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com