@@ -7,6 +7,7 @@ namespace Asp.Versioning.ApiExplorer;
77using Asp . Versioning . OData ;
88using Asp . Versioning . Routing ;
99using Microsoft . AspNet . OData ;
10+ using Microsoft . AspNet . OData . Extensions ;
1011using Microsoft . AspNet . OData . Formatter ;
1112using Microsoft . AspNet . OData . Routing ;
1213using Microsoft . AspNet . OData . Routing . Template ;
@@ -63,15 +64,12 @@ public ODataApiExplorer( HttpConfiguration configuration, ODataApiExplorerOption
6364 protected virtual IModelTypeBuilder ModelTypeBuilder =>
6465 modelTypeBuilder ??= Configuration . DependencyResolver . GetModelTypeBuilder ( ) ;
6566
66- /// <summary>
67- /// Determines whether the action should be considered.
68- /// </summary>
69- /// <param name="actionRouteParameterValue">The action route parameter value.</param>
70- /// <param name="actionDescriptor">The associated <see cref="HttpActionDescriptor">action descriptor</see>.</param>
71- /// <param name="route">The associated <see cref="IHttpRoute">route</see>.</param>
72- /// <param name="apiVersion">The <see cref="ApiVersion">API version</see> to consider the controller for.</param>
73- /// <returns>True if the action should be explored; otherwise, false.</returns>
74- protected override bool ShouldExploreAction ( string actionRouteParameterValue , HttpActionDescriptor actionDescriptor , IHttpRoute route , ApiVersion apiVersion )
67+ /// <inheritdoc />
68+ protected override bool ShouldExploreAction (
69+ string actionRouteParameterValue ,
70+ HttpActionDescriptor actionDescriptor ,
71+ IHttpRoute route ,
72+ ApiVersion apiVersion )
7573 {
7674 if ( actionDescriptor == null )
7775 {
@@ -96,15 +94,12 @@ protected override bool ShouldExploreAction( string actionRouteParameterValue, H
9694 return actionDescriptor . GetApiVersionMetadata ( ) . IsMappedTo ( apiVersion ) ;
9795 }
9896
99- /// <summary>
100- /// Determines whether the controller should be considered.
101- /// </summary>
102- /// <param name="controllerRouteParameterValue">The controller route parameter value.</param>
103- /// <param name="controllerDescriptor">The associated <see cref="HttpControllerDescriptor">controller descriptor</see>.</param>
104- /// <param name="route">The associated <see cref="IHttpRoute">route</see>.</param>
105- /// <param name="apiVersion">The <see cref="ApiVersion">API version</see> to consider the controller for.</param>
106- /// <returns>True if the controller should be explored; otherwise, false.</returns>
107- protected override bool ShouldExploreController ( string controllerRouteParameterValue , HttpControllerDescriptor controllerDescriptor , IHttpRoute route , ApiVersion apiVersion )
97+ /// <inheritdoc />
98+ protected override bool ShouldExploreController (
99+ string controllerRouteParameterValue ,
100+ HttpControllerDescriptor controllerDescriptor ,
101+ IHttpRoute route ,
102+ ApiVersion apiVersion )
108103 {
109104 if ( controllerDescriptor == null )
110105 {
@@ -141,26 +136,26 @@ protected override bool ShouldExploreController( string controllerRouteParameter
141136 return true ;
142137 }
143138
144- /// <summary>
145- /// Explores controllers that do not use direct routes (aka "attribute" routing).
146- /// </summary>
147- /// <param name="controllerMappings">The <see cref="IDictionary{TKey, TValue}">collection</see> of controller mappings.</param>
148- /// <param name="route">The <see cref="IHttpRoute">route</see> to explore.</param>
149- /// <param name="apiVersion">The <see cref="ApiVersion">API version</see> to explore.</param>
150- /// <returns>The <see cref="Collection{T}">collection</see> of discovered <see cref="VersionedApiDescription">API descriptions</see>.</returns>
151- protected override Collection < VersionedApiDescription > ExploreRouteControllers ( IDictionary < string , HttpControllerDescriptor > controllerMappings , IHttpRoute route , ApiVersion apiVersion )
139+ /// <inheritdoc />
140+ protected override Collection < VersionedApiDescription > ExploreRouteControllers (
141+ IDictionary < string , HttpControllerDescriptor > controllerMappings ,
142+ IHttpRoute route ,
143+ ApiVersion apiVersion )
152144 {
153145 if ( controllerMappings == null )
154146 {
155147 throw new ArgumentNullException ( nameof ( controllerMappings ) ) ;
156148 }
157149
150+ Collection < VersionedApiDescription > apiDescriptions ;
151+
158152 if ( route is not ODataRoute )
159153 {
160- return base . ExploreRouteControllers ( controllerMappings , route , apiVersion ) ;
154+ apiDescriptions = base . ExploreRouteControllers ( controllerMappings , route , apiVersion ) ;
155+ return ExploreQueryOptions ( route , apiDescriptions ) ;
161156 }
162157
163- var apiDescriptions = new Collection < VersionedApiDescription > ( ) ;
158+ apiDescriptions = new ( ) ;
164159 var modelSelector = Configuration . GetODataRootContainer ( route ) . GetRequiredService < IEdmModelSelector > ( ) ;
165160 var edmModel = modelSelector . SelectModel ( apiVersion ) ;
166161
@@ -184,17 +179,28 @@ protected override Collection<VersionedApiDescription> ExploreRouteControllers(
184179 }
185180 }
186181
187- ExploreQueryOptions ( apiDescriptions , Configuration . GetODataRootContainer ( route ) . GetRequiredService < ODataUriResolver > ( ) ) ;
182+ return ExploreQueryOptions ( route , apiDescriptions ) ;
183+ }
188184
189- return apiDescriptions ;
185+ /// <inheritdoc />
186+ protected override Collection < VersionedApiDescription > ExploreDirectRouteControllers (
187+ HttpControllerDescriptor controllerDescriptor ,
188+ IReadOnlyList < HttpActionDescriptor > candidateActionDescriptors ,
189+ IHttpRoute route ,
190+ ApiVersion apiVersion )
191+ {
192+ var apiDescriptions = base . ExploreDirectRouteControllers ( controllerDescriptor , candidateActionDescriptors , route , apiVersion ) ;
193+ return ExploreQueryOptions ( route , apiDescriptions ) ;
190194 }
191195
192196 /// <summary>
193197 /// Explores the OData query options for the specified API descriptions.
194198 /// </summary>
195199 /// <param name="apiDescriptions">The <see cref="IEnumerable{T}">sequence</see> of <see cref="VersionedApiDescription">API descriptions</see> to explore.</param>
196200 /// <param name="uriResolver">The associated <see cref="ODataUriResolver">OData URI resolver</see>.</param>
197- protected virtual void ExploreQueryOptions ( IEnumerable < VersionedApiDescription > apiDescriptions , ODataUriResolver uriResolver )
201+ protected virtual void ExploreQueryOptions (
202+ IEnumerable < VersionedApiDescription > apiDescriptions ,
203+ ODataUriResolver uriResolver )
198204 {
199205 if ( uriResolver == null )
200206 {
@@ -206,12 +212,32 @@ protected virtual void ExploreQueryOptions( IEnumerable<VersionedApiDescription>
206212 {
207213 NoDollarPrefix = uriResolver . EnableNoDollarQueryOptions ,
208214 DescriptionProvider = queryOptions . DescriptionProvider ,
215+ DefaultQuerySettings = Configuration . GetDefaultQuerySettings ( ) ,
209216 } ;
210217
211218 queryOptions . ApplyTo ( apiDescriptions , settings ) ;
212219 }
213220
214- private ResponseDescription CreateResponseDescriptionWithRoute ( HttpActionDescriptor actionDescriptor , IHttpRoute route , ApiVersion apiVersion )
221+ private Collection < VersionedApiDescription > ExploreQueryOptions (
222+ IHttpRoute route ,
223+ Collection < VersionedApiDescription > apiDescriptions )
224+ {
225+ if ( apiDescriptions . Count == 0 )
226+ {
227+ return apiDescriptions ;
228+ }
229+
230+ var uriResolver = Configuration . GetODataRootContainer ( route ) . GetRequiredService < ODataUriResolver > ( ) ;
231+
232+ ExploreQueryOptions ( apiDescriptions , uriResolver ) ;
233+
234+ return apiDescriptions ;
235+ }
236+
237+ private ResponseDescription CreateResponseDescriptionWithRoute (
238+ HttpActionDescriptor actionDescriptor ,
239+ IHttpRoute route ,
240+ ApiVersion apiVersion )
215241 {
216242 var description = CreateResponseDescription ( actionDescriptor ) ;
217243 var serviceProvider = actionDescriptor . Configuration . GetODataRootContainer ( route ) ;
@@ -347,7 +373,10 @@ private static bool WillReadUri( HttpParameterBinding parameterBinding )
347373 return willReadUri ;
348374 }
349375
350- private ApiParameterDescription CreateParameterDescriptionFromBinding ( HttpParameterBinding parameterBinding , IServiceProvider serviceProvider , ApiVersion apiVersion )
376+ private ApiParameterDescription CreateParameterDescriptionFromBinding (
377+ HttpParameterBinding parameterBinding ,
378+ IServiceProvider serviceProvider ,
379+ ApiVersion apiVersion )
351380 {
352381 var descriptor = parameterBinding . Descriptor ;
353382 var description = CreateParameterDescription ( descriptor ) ;
@@ -378,7 +407,10 @@ private ApiParameterDescription CreateParameterDescriptionFromBinding( HttpParam
378407 return description ;
379408 }
380409
381- private IList < ApiParameterDescription > CreateParameterDescriptions ( HttpActionDescriptor actionDescriptor , IHttpRoute route , ApiVersion apiVersion )
410+ private IList < ApiParameterDescription > CreateParameterDescriptions (
411+ HttpActionDescriptor actionDescriptor ,
412+ IHttpRoute route ,
413+ ApiVersion apiVersion )
382414 {
383415 var list = new List < ApiParameterDescription > ( ) ;
384416 var actionBinding = GetActionBinding ( actionDescriptor ) ;
@@ -422,7 +454,8 @@ private IList<ApiParameterDescription> CreateParameterDescriptions( HttpActionDe
422454 return list ;
423455 }
424456
425- private static IEnumerable < MediaTypeFormatter > GetInnerFormatters ( IEnumerable < MediaTypeFormatter > mediaTypeFormatters ) => mediaTypeFormatters . Select ( Decorator . GetInner ) ;
457+ private static IEnumerable < MediaTypeFormatter > GetInnerFormatters ( IEnumerable < MediaTypeFormatter > mediaTypeFormatters ) =>
458+ mediaTypeFormatters . Select ( Decorator . GetInner ) ;
426459
427460 private static void PopulateMediaTypeFormatters (
428461 HttpActionDescriptor actionDescriptor ,
0 commit comments