mattfrear / Swashbuckle.AspNetCore.Filters

A bunch of useful filters for Swashbuckle.AspNetCore
MIT License
430 stars 80 forks source link

fix SecurityRequirementsOperationFilter in case of minimal API #228

Closed hartmair closed 1 year ago

hartmair commented 1 year ago

What's in this PR:

andrew-yustyk commented 1 year ago

As you have a big refactoring for the OperationFilterContextExtensions, maybe you can fix issue #225 (PR: #226 ) ? There's a need just to change DeclaringType to ReflectedType

hartmair commented 1 year ago

@mattfrear PR is ready

mattfrear commented 1 year ago

I just tried to run your feature branch with my test/WebApi3.1 test project, and it throws an exception:

System.ArgumentException
  HResult=0x80070057
  Message=An item with the same key has already been added. Key: CustomHeader
  Source=System.Private.CoreLib
  StackTrace:
   at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException[T](T key)
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Swashbuckle.AspNetCore.Filters.AddResponseHeadersFilter.Apply(OpenApiOperation operation, OperationFilterContext context) in C:\code\github\Swashbuckle.AspNetCore.Filters\src\Swashbuckle.AspNetCore.Filters\ResponseHeaders\AddResponseHeadersFilter.cs:line 29
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.<Invoke>d__4.MoveNext()

image

I haven't had time to investigate, but it seems strange, because you haven't changed the AddResponseHeadersFilter which is throwing the exception.

hartmair commented 1 year ago

@mattfrear

I just tried to run your feature branch with my test/WebApi3.1 test project, and it throws an exception:

I have added integration tests and updated the implementation which led to much better solution :)

mattfrear commented 1 year ago

Just a note to say I haven't forgotten about this.

I am on holiday with my family, and I was hoping I would have a chance to look at it during my holiday, but that is unrealistic. So I won't be able to look at this until early September.

Sorry about the delay.

mattfrear commented 1 year ago

Thanks again for this - as discussed here https://github.com/mattfrear/Swashbuckle.AspNetCore.Filters/issues/227#issuecomment-1707502143