简体   繁体   中英

Facing Problem while returning object in response Example in Swashbuckle.Examples

I'm using Swashbuckle.Examples in Web API for better documentation. 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.

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. System.Collections.Generic.IEnumerable`1[IgniteAPI.Payload.ReasonReponseSuccessExample_list] does not.

I'm Getting this error in global.asmx

GlobalConfiguration.Configure(WebApiConfig.Register);

As you can see in the error, you need to specify type that implements IExamplesProvider

Use

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

instead of

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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