简体   繁体   English

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

[英]Facing Problem while returning object in response Example in Swashbuckle.Examples

I'm using Swashbuckle.Examples in Web API for better documentation. 我在Web API中使用Swashbuckle.Examples来获得更好的文档。 It is working fine for Swashbuckle Sample response but when I'm using Sample Example When I run the project it is showing an Error. 它适用于Swashbuckle Sample响应,但当我使用示例示例时,当我运行项目时,它显示错误。

My controller 我的控制器

 [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)
 {
 }

Response Example Class 响应示例类

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

ERROR : 错误

Expected examplesProviderType to implement Swashbuckle.Examples.IExamplesProvider. 期望的examplesProviderType用于实现Swashbuckle.Examples.IExamplesProvider。 System.Collections.Generic.IEnumerable`1[IgniteAPI.Payload.ReasonReponseSuccessExample_list] does not. System.Collections.Generic.IEnumerable`1 [IgniteAPI.Payload.ReasonReponseSuccessExample_list]没有。

I'm Getting this error in global.asmx 我在global.asmx中遇到此错误

GlobalConfiguration.Configure(WebApiConfig.Register);

As you can see in the error, you need to specify type that implements IExamplesProvider 正如您在错误中看到的那样,您需要指定实现IExamplesProvider类型

Use 采用

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

instead of 代替

[SwaggerResponseExample(HttpStatusCode.OK, typeof(IEnumerable<ReasonReponseSuccessExample_list>))]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM