@@ -39,32 +39,30 @@ ReflectionRepository reflectionRepository
3939 . ToLookup ( d => ( d . HttpMethod , d . RelativePath ) ) ;
4040 }
4141
42- public Task TransformAsync (
42+ public async Task TransformAsync (
4343 OpenApiOperation operation ,
4444 OpenApiOperationTransformerContext context ,
4545 CancellationToken cancellationToken )
4646 {
4747 if ( context . Description . ActionDescriptor is not ControllerActionDescriptor cad ||
4848 ! cad . ControllerTypeInfo . IsAssignableTo ( typeof ( BaseApiController ) ) )
4949 {
50- return Task . CompletedTask ;
50+ return ;
5151 }
5252
5353 var methodInfo = cad . MethodInfo ;
5454 var cvm = reflectionRepository . GetClassViewModel ( methodInfo . DeclaringType ! ) ! ;
5555 var method = new ReflectionMethodViewModel ( methodInfo , cvm , cvm ) ;
5656
57- AddOtherBodyTypes ( operation , context ) ;
57+ await AddOtherBodyTypes ( operation , context , cancellationToken ) ;
5858 ProcessDataSources ( operation , context , method ) ;
5959 ProcessStandardParameters ( operation , method ) ;
60-
61- return Task . CompletedTask ;
6260 }
6361
6462 /// <summary>
6563 /// Workaround https://github.com/dotnet/aspnetcore/issues/58329
6664 /// </summary>
67- private async void AddOtherBodyTypes ( OpenApiOperation operation , OpenApiOperationTransformerContext context )
65+ private async Task AddOtherBodyTypes ( OpenApiOperation operation , OpenApiOperationTransformerContext context , CancellationToken ct )
6866 {
6967 Type ? docServiceType = Type . GetType ( "Microsoft.AspNetCore.OpenApi.OpenApiDocumentService,Microsoft.AspNetCore.OpenApi" ) ;
7068 if ( docServiceType is null ) return ;
@@ -77,6 +75,24 @@ private async void AddOtherBodyTypes(OpenApiOperation operation, OpenApiOperatio
7775 foreach ( var otherDescription in otherDescriptions )
7876 {
7977 object docService = context . ApplicationServices . GetRequiredKeyedService ( docServiceType , context . DocumentName ) ;
78+ #if NET10_0_OR_GREATER
79+ // In .NET 10, GetRequestBodyAsync requires OpenApiDocument as the first parameter
80+ var resultTask = docServiceType
81+ . GetMethod ( "GetRequestBodyAsync" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic ) ?
82+ . Invoke ( docService , [
83+ // OpenApiDocument document,
84+ context . Document ,
85+ // ApiDescription description,
86+ otherDescription ,
87+ // IServiceProvider scopedServiceProvider,
88+ context . ApplicationServices ,
89+ // IOpenApiSchemaTransformer[] schemaTransformers,
90+ // TODO: Too hard to acquire schema transformers here.
91+ Array . Empty < IOpenApiSchemaTransformer > ( ) ,
92+ // CancellationToken cancellationToken
93+ ct
94+ ] ) as Task < OpenApiRequestBody > ;
95+ #else
8096 var resultTask = docServiceType
8197 . GetMethod ( "GetRequestBodyAsync" , System . Reflection . BindingFlags . Instance | System . Reflection . BindingFlags . NonPublic ) ?
8298 . Invoke ( docService , [
@@ -88,8 +104,9 @@ private async void AddOtherBodyTypes(OpenApiOperation operation, OpenApiOperatio
88104 // TODO: Too hard to acquire schema transformers here.
89105 Array . Empty < IOpenApiSchemaTransformer > ( ) ,
90106 // CancellationToken cancellationToken
91- CancellationToken . None
107+ ct
92108 ] ) as Task < OpenApiRequestBody > ;
109+ #endif
93110
94111 if ( resultTask is null ) continue ;
95112
0 commit comments