Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger does not show any parameters when using mvc ModelBinder #15

Open
angelcolmenares opened this issue Feb 27, 2022 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@angelcolmenares
Copy link

angelcolmenares commented Feb 27, 2022

Hi!
every thing works fine, but swagger does not show parameters info when using mvc ModelBinder.
my code:

builder.Services.AddMvcCore();
...
app.MapGet("test", ( ModelBinder<GetOrderByIdRequest> request)=> request.Model);

public class GetOrderByIdRequest
{
    [FromQuery] public string Id { get; set; } = string.Empty;
}

imagen

@DamianEdwards
Copy link
Owner

When accepting any parameter in Minimal APIs that implements BindAsync you lose any automatic parameter metadata being emitted by the framework. You can use the IProvideEndpointParameterMetadata interface on the type you're actually binding (GetOrderByIdRequest in this case) to implement the metadata you want to return but note that there is currently no support in Minimal APIs for specifying path or querystring (i.e. non-body) parameters from endpoint metadata (that's coming in .NET 7.0, see dotnet/aspnetcore#40084).

For this to work today I'd need to add a feature to this library to support specifying non-body parameter metadata on route handlers and then projecting those into the ApiExplorer (via the custom provider in this library). Then I could update ModelBinder<TBinder> to automatically discover attribute-based metadata from the specified TBinder and flow that into the endpoint metadata. That shouldn't be too difficult but ultimately would likely look different to the same functionality when it lands in .NET 7.0.

@DamianEdwards DamianEdwards added the enhancement New feature or request label Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants