Can SwaggerGen (ASP.NET Core) generate multipart/form-data properties as objects?

Viewed 120

given some example scenario:

public class SomeRequest
{
  public SomeDto dto {get; set;}
}

public class SomeDto
{
  public string someString {get; set;}
  public int someInt {get; set;}
}

Then in some controller I would have a method:

[HttpPost]
public async Task<IActionResult> DoSomething([FromBody] SomeRequest request) { ... }

Generated swagger.json is fine, everything is an object and in swagger UI I can provide a json. But I need to change it to [FromForm] to add some IFormFile into my SomeRequest class and it breaks it. In Swagger the properties are somehow flatten to simple types and it looks like that:

dto.SomeInt
dto.SomeString

An example from Swagger UI:

enter image description here

What I would prefer is to have objects like I created them so I can put them as json, it would also help with mappings on the frontend. So I would like it to be like with the use of [FromBody]:

enter image description here

So in case of [FromForm] I would like to have a field called dto where I can put a json representation of that object.

Is this possible to configure SwaggerGen in that way? I know how to define that manually in OpenApi but I would like to have it automatically generated.

0 Answers
Related