File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ using Swashbuckle . AspNetCore . Swagger ;
2
+ using Swashbuckle . AspNetCore . SwaggerGen ;
3
+ using System . Linq ;
4
+
5
+ namespace Supermarket . Swagger
6
+ {
7
+ public class SwaggerDefaultValues : IOperationFilter
8
+ {
9
+ /// <summary>
10
+ /// Applies the filter to the specified operation using the given context.
11
+ /// </summary>
12
+ /// <param name="operation">The operation to apply the filter to.</param>
13
+ /// <param name="context">The current operation filter context.</param>
14
+ public void Apply ( Operation operation , OperationFilterContext context )
15
+ {
16
+ if ( operation . Parameters == null )
17
+ {
18
+ return ;
19
+ }
20
+ foreach ( var parameter in operation . Parameters . OfType < NonBodyParameter > ( ) )
21
+ {
22
+ var description = context . ApiDescription . ParameterDescriptions . First ( p => p . Name == parameter . Name ) ;
23
+ var routeInfo = description . RouteInfo ;
24
+
25
+ if ( parameter . Description == null )
26
+ {
27
+ parameter . Description = description . ModelMetadata ? . Description ;
28
+ }
29
+
30
+ if ( routeInfo == null )
31
+ {
32
+ continue ;
33
+ }
34
+
35
+ if ( parameter . Default == null )
36
+ {
37
+ parameter . Default = routeInfo . DefaultValue ;
38
+ }
39
+
40
+ parameter . Required |= ! routeInfo . IsOptional ;
41
+ }
42
+ }
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments