I'm using Swagger with my ASP.NET Core application and for a HTTP POST endpoint returning Blog model:
[HttpPost]
[ProducesResponseType(typeof(Blog), StatusCodes.Status200OK)]
public IActionResult AddBlog([FromBody] string name)
{
// Code removed for brevity...
return Ok(newBlog);
}
Blog:
public Blog
{
public int Id { get; set; }
public string Name { get; set; }
}
Swagger in its UI will show example response for that endpoint:
{
"Id": 0,
"Name": "string"
}
What I'd like to do is to generate such example values in JSON for type of class I provide and where I need it, which is somewhere else in my application like:
var json = exampleValuesGenerator.Generate(typeof(Blog));
Is this possible?