-
Notifications
You must be signed in to change notification settings - Fork 2.1k
ApiExplorer expanding IFormFile into multiple ParameterDescriptions #5673
Comments
This makes sense. We should look at the swagger/API Explorer results for t all of the types we provide special model binding support for "out of the box" and make sure it's doing something appropriate. |
@jbagga let's make sure we understand the scope of the problem, e.g. which types are problematic, how to handle them, etc. |
From Swashbuckle's perspective - it's just the two "special" types above that are causing problems. For me, ApiExplorer and its abstractions are closer to the C# / MVC layer than the HTTP layer. So one could argue that it shouldn't expand out the properties at all, instead putting that responsibility on the tools that do operate purely at the HTTP layer of abstraction e.g. Swashbuckle. Not saying that's right just throwing it out there for philosophical discussion :) |
For cancellation token we already have a way to say this parameter is "not user input". We should double check the other types that aren't really going to bind user input but can appear in a parameter list like For |
@rynowak - I was hoping BindingSource.IsFromRequest would be "false" for CancellationToken but that's not currently the case. Is there something else I can look at so I don't have to do the hacky prop name matching above. As you guys think about a solution here, I just want to call out my wishlist:
|
@domaindrivendev Let us know if the changes in #5750 do not resolve the issue |
@jbagga, @rynowak - thanks for this, I just have two comments to make ...
|
I guess at a minimum, I can't think of any good reason to expand out "path" parameters at all. |
This will be part of 2.0.0 - the best date estimate I can give is Q3 2017. If you want this change right away, there's nothing fundamental about it, just implement
I'm going to open another issue where we can track that feedback. The reason why we expand non-body parameters is that it represents something fundamental about how model binding works. I think there's a disconnect in the system where implementing a custom model binder doesn't prevent us from expanding the parameter. |
This behavior was added by #2502. As far as I can tell it expands complex types into multiple ParameterDescriptions unless the parameter has a BindingSource of "body". While the expansion is really convenient for documenting complex types with a BindingSource of "query" or "form", it makes it very tricky for ApiExplorer consumers (e.g. Swashbuckle.AspNetCore) to document parameters of type IFormFile. In this case it would be ideal to have a single parameter of type IFormFile.
In fact, this is a problem for other "special" parameter types as well. For example, CancellationToken. A tool like Swashbuckle needs to omit this parameter from API docs (e.g. Swagger). But, rather than omitting ParameterDescriptions with a type CancellationToken it needs to omit all params that are likely "part of" an expanded CancellationToken. Today, it uses the following code for this:
Not sure if I've explained this well. Let me know if it makes sense
The text was updated successfully, but these errors were encountered: