ApiEndpoints icon indicating copy to clipboard operation
ApiEndpoints copied to clipboard

Consider FromMultiSourceAttribute Necessity and Document It If It Helps

Open ardalis opened this issue 3 years ago • 2 comments

Version 3.1 sometimes had issues with request types being pulled from multiple locations (route, query, body).

Nick Chapsas shows a solution to this problem here. The MultiSourceAttribute.

I'm not sure if the problem still exists in v4, but if it does we should show how to use this attribute to address it.

References:

  • https://stackoverflow.com/questions/45495432/asp-net-core-mvc-mixed-route-frombody-model-binding-validation
  • https://www.seeleycoder.com/blog/mixed-model-binding-aspnetcore/

ardalis avatar Jan 27 '22 20:01 ardalis

As per my comment here: https://github.com/ardalis/ApiEndpoints/issues/161#issuecomment-976126232 this was something I tried but it doesn't play well with Swagger (or Redoc) nor does it work if you have multiple fields that come from the body. You will still need to create a class representing the body details like I mention, in which case my solution continues to work fine and doesn't need the attribute.

Allann avatar Jan 27 '22 22:01 Allann

Good to know, thanks, Allann.

ardalis avatar Jan 27 '22 22:01 ardalis