usama sajid
usama sajid

Reputation: 1

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

Upvotes: 0

Views: 2500

Answers (1)

Roman Marusyk
Roman Marusyk

Reputation: 24619

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>))]

Upvotes: 1

Related Questions