question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger example request with frombody attr

See original GitHub issue

I 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:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vpetrusevicicommented, Sep 7, 2022

I just used AddOpenApiDocument instead of AddSwaggerDoc. 😃

0reactions
dj-nitehawkcommented, Sep 7, 2022

@vpetrusevici make sure you’re using FastEndpoints.FromBody and not the one from mvc.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found