Swagger example request with frombody attr
See original GitHub issueI have the following setup and I’m having trouble with the swagger doc.
public record MyRecord(string Name, string Value);
public class MyRequest
{
[FromBody]
public IEnumerable<MyRecord> Records {get;set;}
[FromClaim(ClaimTypes.NameIdentifier, IsRequired = true)]
public string UserName {get;set;}
}
//Endpoint code
public override void Configure() {
Summary(s =>
{
s.ExampleRequest = new MyRequest() { Records = new List<MyRecord>() { new ("Name 1","Value 1")} };
});
}
The body should appear as
[
{
"name": "Name 1",
"value": "Value 1"
}
]
But its appearing as:
{
"records":
[
{
"name": "Name 1",
"value": "Value 1"
}
]
}
If I provide a list of objects in the ExampleRequest I get an error so I can only provide a Request.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Swagger UI will not list my Post methods with a [FromBody] ...
I am new to Swagger UI. I need to write a public-facing API that will nicely display some documentation and that I should...
Read more >SwaggerParameter not generating data for FromBody ...
[FromQuery] is generated as a "parameter" in the generated Swagger/OpenAPI document, hence why the SwaggerParameterAttribute works in that case.
Read more >[HttpGet] method with [FromBody] parameter described in ...
Hi Is it deliberate behavior of Swashbuckle to represent [FromBody] parametr in [HttpGet] method as "in":"query"?
Read more >Describing Request Body
The POST, PUT and PATCH requests can have the request body (payload), such as JSON or XML data. In Swagger terms, the request...
Read more >Configuring and Using Swagger UI in ASP.NET Core Web ...
We are going to learn how to integrate the Swagger UI/OpenAPI in an ASP.NET Core Web API, extend the documentation, and customize UI....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just used AddOpenApiDocument instead of AddSwaggerDoc. 😃
@vpetrusevici make sure you’re using
FastEndpoints.FromBody
and not the one from mvc.