-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Error "InvalidOperationException: Sequence contains more than one matching element" in Swagger when using multiple [FromForm] parameters in Minimal API #53831
Comments
@marcominerva Thanks for reporting this issue! I believe the issue is coming from the Microsoft.AspNetCore.OpenAPI <-> Swashbuckle integration layer. In particular here: I don't have immediate thoughts on the best way to workaround this, at the moment. |
Thank you @captainsafia for the reply! So, now I have another question. The last update in the https://github.com/domaindrivendev/Swashbuckle.AspNetCore repository happened on January 2023. Reading this issue: domaindrivendev/Swashbuckle.AspNetCore#2759, what should we expect for the future? I mean, if the situation remain the same, will Swagger integration be removed from the .NET Web API template? And there will be a recommended alternative? |
Have you tested if DotSwashbuckle produces the same error? https://github.com/Havunen/DotSwashbuckle |
The exact same behaviour happens, in minimal api endpoints, if using header (like, e.g. for versioning) and so having endpoints like this one
Yes. The error is present also with DotSwashbuckle @Havunen :) |
@Havunen You should be able to resolve this in DotSwashbuckle by updating the line of code referenced here to accept either a single parameter from body or multiple parameters from the form. One thing to note is that I think you'd have to gather the schemas for all the
This is surprising to me because I don't know of any code in minimal APIs/ApiExplorer/Swashbuckle that would be causing this off the top of my head but I can look deeper. |
Actually the exception seems to be the same
|
that code line does not exist in DotSwashbuckle
Is this latest version of DotSwashbuckle 3.0.9 ? I cannot reproduce the exception, however there seems to be something wrong with the generated schema so I will check that |
You're right. It looks like it was removed in this commit. @marcominerva Given the divergence in the codebases, can you confirm if you repro this issue with DotSwashbuckle? I don't believe what @vdevc reported with |
My check was done on 3.0.8 yesterday. I don't see the 3.0.9 version on nuget yet 🙃
@captainsafia same doubts here. I am suspecting about the presence of multiple |
ah yes, I meant 3.0.8. Can you edit the Basic examaple project here to make it fail: https://github.com/Havunen/DotSwashbuckle I have tried different approaches here but I am not able to reproduce the exception https://github.com/Havunen/DotSwashbuckle/blob/master/test/WebSites/Basic/Startup.cs#L88-L98 |
I edited the The error occur on line 279 of SwaggerGenerator.cs Member The packages
comes from the excellent project from @commonsensesoftware available here. |
Hi all, We just posted an announcement regarding our plans for OpenAPI support in ASP.NET Core moving forward in this post. We're bringing OpenAPI document generation as a first class feature in ASP.NET Core. @marcominerva I've included the scenario with multiple @vdevc It looks like your issues is specifically related to the integration with Asp.Versioning. I'm eager to get this working with the built-in integration. Do you mind filing a separate issue so that we can track this work appropriately? |
I've opened #55321 to resolve this issue in our built-in OpenAPI support. The TL;DR is that we are now using |
I see that #54623 is not addressed in the pull request. Are you planning with a different solution? |
Yep, that issue is distinct from this one although the exception is the same. We'll need to look at it separately especially when Asp.Versioning is thrown in the mix since it modifies the way ApiExplorer metadata is generated. |
Fixed in preview5 of Microsoft.AspNetCore.OpenApi. |
Is there an existing issue for this?
Describe the bug
I have the following Minimal API endpoint:
When I launch the application, I get the following Exception related to Swagger:
If instead I use a Controller like this:
Everything works as expected.
Expected Behavior
Swagger should not throw the exception.
Steps To Reproduce
Minimal repro here: https://github.com/marcominerva/FromFormBindingIssue
Exceptions (if any)
InvalidOperationException: Sequence contains more than one matching element
System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
System.Linq.Enumerable.TryGetSingle(IEnumerable source, Func<TSource, bool> predicate, out bool found)
System.Linq.Enumerable.SingleOrDefault(IEnumerable source, Func<TSource, bool> predicate)
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOpenApiOperationFromMetadata(ApiDescription apiDescription, SchemaRepository schemaRepository)
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository)
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable apiDescriptions, SchemaRepository schemaRepository)
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable apiDescriptions, SchemaRepository schemaRepository)
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerDocumentWithoutFilters(string documentName, string host, string basePath)
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerAsync(string documentName, string host, string basePath)
Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
.NET Version
8.0.101
Anything else?
No response
The text was updated successfully, but these errors were encountered: