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

[Bug]: "InvalidOperationException: Sequence contains more than one matching element" in Swagger when using multiple [FromForm] parameters in Minimal API #2912

Closed
marcominerva opened this issue May 21, 2024 · 2 comments
Labels
Milestone

Comments

@marcominerva
Copy link

marcominerva commented May 21, 2024

Describe the bug

I have originally posted the issue in the ASP.NET Core repo: dotnet/aspnetcore#53831. See in particular this comment: dotnet/aspnetcore#53831 (comment)

Expected behavior

Swagger should not throw an exception.

Actual behavior

An InvalidOperationException is thrown.

Steps to reproduce

Minimal repro here: https://github.com/marcominerva/FromFormBindingIssue

Exception(s) (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)

Swashbuckle.AspNetCore version

6.6.1

.NET Version

8.0.5

Anything else?

No response

@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label May 21, 2024
@jgarciadelanoceda
Copy link
Contributor

jgarciadelanoceda commented Jun 26, 2024

Reviewing this item it seems to be due to this PR. #2441. For MinimalApis the Schema is being generated:

"multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/Person"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/Person"
              }
            }

This code block (The ref is not build for controllers because the controllers do not have the OpenApiOperation attribute)

I do not fully understand why the PR introduced the limit of one FromForm parameter in the request

@jgarciadelanoceda
Copy link
Contributor

jgarciadelanoceda commented Jun 27, 2024

@martincostello you can close this issue, the last PR included this issue

@martincostello martincostello removed the help-wanted A change up for grabs for contributions from the community label Jun 28, 2024
@martincostello martincostello added this to the v6.7.0 milestone Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants