I've managed to add examples to my Web API with SwashBuckle.AspNetCore
and Swashbuckle.AspNetCore.Filters
for POST methods:
DTO
public class ExampleDTO
{
public string MyFoo { get; set; }
}
Example Request
public class ExampleDTOExample : IExamplesProvider<ExampleDTO>
{
public ExampleDTO GetExamples()
{
return new ExampleDTO()
{
MyFoo = "bar"
};
}
}
Controller Method
[SwaggerOperation(
Summary = "...",
Description = "...",
OperationId = "PostFoo"
)]
[SwaggerResponse(200, "Returns ...", typeof(int))]
[HttpPost]
[Route("post-foo")]
public ActionResult<int> PostFoo([FromBody]ExampleDTO request)
{
throw new NotImplementedException();
}
This work perfectly fine. When I click the "try it out" button, I have "bar" as prefilled value for the property foo.
However, when I'm trying to do the same for a GET request, e.g., with parameters from query like this, the text box is not prefilled with the value "bar":
public class ExampleDTO
{
[FromQuery(Name = "foo")]
public string MyFoo { get; set; }
}
Controller Method
[SwaggerOperation(
Summary = "...",
Description = "...",
OperationId = "GetFoo"
)]
[SwaggerResponse(200, "Returns ...", typeof(int))]
[HttpGet]
[Route("get-foo")]
public ActionResult<int> GetFoo([FromQuery]ExampleDTO request)
{
throw new NotImplementedException();
}
How can I force the text box to be prefilled with the example value? So far I've found a solution for specifying a default value which is not want I want. I only want to use attributes for a default value in Swagger UI.