File tree Expand file tree Collapse file tree
src/AspNetCore/OData/src/Asp.Versioning.OData.ApiExplorer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -97,6 +97,12 @@ public virtual void OnProvidersExecuted( ApiDescriptionProviderContext context )
9797 ArgumentNullException . ThrowIfNull ( context ) ;
9898
9999 var results = context . Results ;
100+
101+ if ( results . Count == 0 )
102+ {
103+ return ;
104+ }
105+
100106 var visited = new HashSet < ApiDescription > ( capacity : results . Count , new ApiDescriptionComparer ( ) ) ;
101107
102108 for ( var i = results . Count - 1 ; i >= 0 ; i -- )
Original file line number Diff line number Diff line change 1+ // Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
3+ #pragma warning disable CA1812
4+
5+ namespace Asp . Versioning . ApiExplorer ;
6+
7+ using Asp . Versioning . ApplicationModels ;
8+ using Microsoft . AspNetCore . Mvc . ApplicationModels ;
9+
10+ internal sealed class ODataApplicationModelProvider : IApplicationModelProvider
11+ {
12+ public int Order => 0 ;
13+
14+ public void OnProvidersExecuted ( ApplicationModelProviderContext context ) { }
15+
16+ public void OnProvidersExecuting ( ApplicationModelProviderContext context )
17+ {
18+ ArgumentNullException . ThrowIfNull ( context ) ;
19+
20+ var application = context . Result ;
21+ var controllers = application . Controllers ;
22+ var odata = new ODataControllerSpecification ( ) ;
23+ var convention = new ApiVisibilityConvention ( ) ;
24+
25+ for ( var i = 0 ; i < controllers . Count ; i ++ )
26+ {
27+ var controller = controllers [ i ] ;
28+
29+ if ( ! odata . IsSatisfiedBy ( controller ) )
30+ {
31+ continue ;
32+ }
33+
34+ var actions = controller . Actions ;
35+
36+ for ( var j = 0 ; j < actions . Count ; j ++ )
37+ {
38+ convention . Apply ( actions [ j ] ) ;
39+ }
40+ }
41+ }
42+ }
Original file line number Diff line number Diff line change @@ -8,7 +8,9 @@ namespace Microsoft.Extensions.DependencyInjection;
88using Asp . Versioning . ApiExplorer ;
99using Asp . Versioning . Conventions ;
1010using Asp . Versioning . OData ;
11+ using Microsoft . AspNetCore . Mvc ;
1112using Microsoft . AspNetCore . Mvc . ApiExplorer ;
13+ using Microsoft . AspNetCore . Mvc . ApplicationModels ;
1214using Microsoft . Extensions . DependencyInjection . Extensions ;
1315using Microsoft . Extensions . Options ;
1416using static Microsoft . Extensions . DependencyInjection . ServiceDescriptor ;
@@ -59,6 +61,7 @@ private static void AddApiExplorerServices( IApiVersioningBuilder builder )
5961 builder . Services . AddModelConfigurationsAsServices ( ) ;
6062 services . TryAddSingleton < IModelTypeBuilder , DefaultModelTypeBuilder > ( ) ;
6163 services . TryAddSingleton < IOptionsFactory < ODataApiExplorerOptions > , ODataApiExplorerOptionsFactory > ( ) ;
64+ services . TryAddEnumerable ( Transient < IApplicationModelProvider , Asp . Versioning . ApiExplorer . ODataApplicationModelProvider > ( ) ) ;
6265 services . TryAddEnumerable ( Transient < IApiDescriptionProvider , PartialODataDescriptionProvider > ( ) ) ;
6366 services . TryAddEnumerable ( Transient < IApiDescriptionProvider , ODataApiDescriptionProvider > ( ) ) ;
6467 services . TryAddEnumerable ( Transient < IModelConfiguration , ImplicitModelBoundSettingsConvention > ( ) ) ;
You can’t perform that action at this time.
0 commit comments