为了获得更好的文档,我在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);
发布于 2019-05-31 07:37:14
正如您在错误中看到的,您需要指定实现IExamplesProvider
的类型
使用
[SwaggerResponseExample(HttpStatusCode.OK, typeof(ReasonReponseSuccessExample_list))]
而不是
[SwaggerResponseExample(HttpStatusCode.OK, typeof(IEnumerable<ReasonReponseSuccessExample_list>))]
https://stackoverflow.com/questions/56386138
复制相似问题