This repository was archived by the owner on Dec 14, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
src/Microsoft.AspNetCore.Mvc.Core/Internal
test/Microsoft.AspNetCore.Mvc.Core.Test/Internal Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,13 @@ public void OnProvidersExecuting(ApplicationModelProviderContext context)
57
57
foreach ( var controllerModel in context . Result . Controllers )
58
58
{
59
59
var isApiController = controllerModel . Attributes . OfType < IApiBehaviorMetadata > ( ) . Any ( ) ;
60
+ if ( isApiController &&
61
+ controllerModel . ApiExplorer . IsVisible == null )
62
+ {
63
+ // Enable ApiExplorer for the controller if it wasn't already explicitly configured.
64
+ controllerModel . ApiExplorer . IsVisible = true ;
65
+ }
66
+
60
67
var controllerHasSelectorModel = controllerModel . Selectors . Any ( s => s . AttributeRouteModel != null ) ;
61
68
62
69
foreach ( var actionModel in controllerModel . Actions )
Original file line number Diff line number Diff line change @@ -102,6 +102,47 @@ public void OnProvidersExecuting_SkipsAddingFilterToActionIfFeatureIsDisabledUsi
102
102
} ) ;
103
103
}
104
104
105
+ [ Fact ]
106
+ public void OnProvidersExecuting_MakesControllerVisibleInApiExplorer_IfItIsAnnotatedWithAttribute ( )
107
+ {
108
+ // Arrange
109
+ var context = GetContext ( typeof ( TestApiController ) ) ;
110
+ var options = new TestOptionsManager < ApiBehaviorOptions > ( new ApiBehaviorOptions
111
+ {
112
+ SuppressModelStateInvalidFilter = true ,
113
+ } ) ;
114
+
115
+ var provider = GetProvider ( options ) ;
116
+
117
+ // Act
118
+ provider . OnProvidersExecuting ( context ) ;
119
+
120
+ // Assert
121
+ var controller = Assert . Single ( context . Result . Controllers ) ;
122
+ Assert . True ( controller . ApiExplorer . IsVisible ) ;
123
+ }
124
+
125
+ [ Fact ]
126
+ public void OnProvidersExecuting_DoesNotModifyVisibilityInApiExplorer_IfValueIsAlreadySet ( )
127
+ {
128
+ // Arrange
129
+ var context = GetContext ( typeof ( TestApiController ) ) ;
130
+ context . Result . Controllers [ 0 ] . ApiExplorer . IsVisible = false ;
131
+ var options = new TestOptionsManager < ApiBehaviorOptions > ( new ApiBehaviorOptions
132
+ {
133
+ SuppressModelStateInvalidFilter = true ,
134
+ } ) ;
135
+
136
+ var provider = GetProvider ( options ) ;
137
+
138
+ // Act
139
+ provider . OnProvidersExecuting ( context ) ;
140
+
141
+ // Assert
142
+ var controller = Assert . Single ( context . Result . Controllers ) ;
143
+ Assert . False ( controller . ApiExplorer . IsVisible ) ;
144
+ }
145
+
105
146
[ Fact ]
106
147
public void OnProvidersExecuting_ThrowsIfControllerWithAttribute_HasActionsWithoutAttributeRouting ( )
107
148
{
You can’t perform that action at this time.
0 commit comments