首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Swashbuckle.Examples中返回响应示例中的对象时遇到的问题

在Swashbuckle.Examples中返回响应示例中的对象时遇到的问题
EN

Stack Overflow用户
提问于 2019-05-31 05:56:44
回答 1查看 1.1K关注 0票数 0

为了获得更好的文档,我在Web API中使用了Swashbuckle.Examples。对于Swashbuckle示例响应,它工作得很好,但当我使用示例示例时,当我运行项目时,它显示了一个错误。

我的控制器

 [SwaggerResponse(HttpStatusCode.OK, Type = typeof(IEnumerable<ReasonReponsesuccessMessage_list>))]
 [SwaggerResponseExample(HttpStatusCode.OK, typeof(IEnumerable<ReasonReponseSuccessExample_list>))]
 [SwaggerResponse(HttpStatusCode.BadRequest, Type = typeof(IEnumerable<ReponseEmptyMessage>))]
 [SwaggerOperation("List reasons")]
 [ActionName("Reasons")]
 [Route("api/{Id}")]
 [HttpGet]
 public HttpResponseMessage GetReasons(string Id)
 {
 }

响应示例类

  public class ReasonReponseSuccessExample_list : IExamplesProvider
    {
        object IExamplesProvider.GetExamples()
        {
            ReasonReponsesuccessMessage_list ReasonReponsesuccessMessage_list = new ReasonReponsesuccessMessage_list();

            ReasonReponsesuccessMessage_list.Message = "Success";
            ReasonReponsesuccessMessage_list.Data = new List<tbl_reason>
            {
                new tbl_reason{ id="SAA133",primary_name="Wrong Invoice",alt_name="Wrong Invoice"},
                new tbl_reason{ id="B97123",primary_name="Payment Problem",alt_name=""}
            };
            ReasonReponsesuccessMessage_list.Extras = "";
            ReasonReponsesuccessMessage_list.Success = true;
            return ReasonReponsesuccessMessage_list;
        }
    }

错误

期望examplesProviderType实现Swashbuckle.Examples.IExamplesProvider。System.Collections.Generic.IEnumerable`1IgniteAPI.Payload.ReasonReponseSuccessExample_list不需要。

我在global.asmx中遇到了这个错误

GlobalConfiguration.Configure(WebApiConfig.Register);

EN

回答 1

Stack Overflow用户

发布于 2019-05-31 07:37:14

正如您在错误中看到的,您需要指定实现IExamplesProvider的类型

使用

[SwaggerResponseExample(HttpStatusCode.OK, typeof(ReasonReponseSuccessExample_list))]

而不是

[SwaggerResponseExample(HttpStatusCode.OK, typeof(IEnumerable<ReasonReponseSuccessExample_list>))]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56386138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档