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]: Sequence contains no matching element when accessing swagger.json #3187

Closed
moni-dips opened this issue Dec 4, 2024 · 1 comment · Fixed by #3188
Closed

[Bug]: Sequence contains no matching element when accessing swagger.json #3187

moni-dips opened this issue Dec 4, 2024 · 1 comment · Fixed by #3188
Labels
Milestone

Comments

@moni-dips
Copy link
Contributor

Describe the bug

The changes in #3133 made swagger.json crash with an InvalidOperationException when I try to access swagger.json in one of our services.

This is due to the code:

bodyParameterDescription = apiDescription.ParameterDescriptions.Single(desc => desc.IsFromBody());
if (bodyParameterDescription is not null)

Since this is using .Single(), bodyParameterDescription would never be null, so it seems that this was intended to use SingleOrDefault instead.

Expected behavior

No crash on accessing swagger.json

Actual behavior

Crash on accessing swagger.json

Steps to reproduce

No response

Exception(s) (if any)

Sequence contains no matching element
System.InvalidOperationException
at System.Linq.ThrowHelper.ThrowNoMatchException()
at System.Linq.Enumerable.Single[TSource](IEnumerable1 source, Func2 predicate)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOpenApiOperationFromMetadataAsync(ApiDescription apiDescription, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperationAsync(ApiDescription apiDescription, SchemaRepository schemaRepository, Func3 parametersGenerator, Func3 bodyGenerator, Func3 applyFilters) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperationAsync(ApiDescription apiDescription, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperationsAsync(IEnumerable\u00601 apiDescriptions, SchemaRepository schemaRepository) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePathsAsync(IEnumerable1 apiDescriptions, SchemaRepository schemaRepository, Func3 operationsGenerator) at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePathsAsync(IEnumerable1 apiDescriptions, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerAsync(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Swashbuckle.AspNetCore version

7.1.0

.NET Version

8.0

Anything else?

No response

@martincostello
Copy link
Collaborator

For clarity - this isn't a crash, it's an unhandled exception in an HTTP request.

@martincostello martincostello added this to the v7.2.0 milestone Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants