mattfrear/Swashbuckle.Examples

SwaggerRequestExample attribute does not seem to work in ASP.NET MVC 5 (.NET Framework 4.5.2)

Closed this issue · 2 comments

I am trying to use the library to output some examples (request and response), but I fail to make it work in ASP.NET MVC 5:

Configuration (SwaggerConfig.cs)

public static void Register()
{
    var thisAssembly = typeof(SwaggerConfig).Assembly;

    GlobalConfiguration.Configuration
        .EnableSwagger(c => {
             c.SingleApiVersion("v1", "TestApp.Web");
             c.IncludeXmlComments(string.Format(@"{0}\bin\TestApp.Web.xml", System.AppDomain.CurrentDomain.BaseDirectory));
             c.OperationFilter<ExamplesOperationFilter>();
             c.OperationFilter<DescriptionOperationFilter>();
             c.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();
                })
            .EnableSwaggerUi(c => { });
 }  

Request example classes

public class EchoRequestExample : IExamplesProvider
{
public object GetExamples()
{
return new EchoInput { Value = 7 } ;
}
}

public class EchoInput
{
public int Value { get; set; }
}

Action

[HttpGet]
[Route("Echo")]
[CustomApiAuthorize]
[SwaggerRequestExample(typeof(EchoInput), typeof(EchoRequestExample))]
[ResponseType(typeof(EchoServiceModel))]
public HttpResponseMessage Echo([FromUri] EchoInput model)
{
var ret = new EchoServiceModel
{
Username = RequestContext.Principal.Identity.Name,
Value = value
};
return Request.CreateResponse(HttpStatusCode.OK, ret);
}

Library version: 3.10.0.

What am I missing? Thanks.

OK. Thank you.