@@ -41,19 +41,41 @@ public SwaggerGenerator(
41
41
42
42
public async Task < OpenApiDocument > GetSwaggerAsync ( string documentName , string host = null , string basePath = null )
43
43
{
44
- var ( applicableApiDescriptions , swaggerDoc , schemaRepository ) = GetSwaggerDocument ( documentName , host , basePath ) ;
44
+ var ( applicableApiDescriptions , swaggerDoc , schemaRepository ) = GetSwaggerDocumentWithoutFilters ( documentName , host , basePath ) ;
45
+
45
46
swaggerDoc . Components . SecuritySchemes = await GetSecuritySchemes ( ) ;
47
+
48
+ // NOTE: Filter processing moved here so they may effect generated security schemes
49
+ var filterContext = new DocumentFilterContext ( applicableApiDescriptions , _schemaGenerator , schemaRepository ) ;
50
+ foreach ( var filter in _options . DocumentFilters )
51
+ {
52
+ filter . Apply ( swaggerDoc , filterContext ) ;
53
+ }
54
+
55
+ swaggerDoc . Components . Schemas = new SortedDictionary < string , OpenApiSchema > ( swaggerDoc . Components . Schemas , _options . SchemaComparer ) ;
56
+
46
57
return swaggerDoc ;
47
58
}
48
59
49
60
public OpenApiDocument GetSwagger ( string documentName , string host = null , string basePath = null )
50
61
{
51
- var ( applicableApiDescriptions , swaggerDoc , schemaRepository ) = GetSwaggerDocument ( documentName , host , basePath ) ;
62
+ var ( applicableApiDescriptions , swaggerDoc , schemaRepository ) = GetSwaggerDocumentWithoutFilters ( documentName , host , basePath ) ;
63
+
52
64
swaggerDoc . Components . SecuritySchemes = GetSecuritySchemes ( ) . Result ;
65
+
66
+ // NOTE: Filter processing moved here so they may effect generated security schemes
67
+ var filterContext = new DocumentFilterContext ( applicableApiDescriptions , _schemaGenerator , schemaRepository ) ;
68
+ foreach ( var filter in _options . DocumentFilters )
69
+ {
70
+ filter . Apply ( swaggerDoc , filterContext ) ;
71
+ }
72
+
73
+ swaggerDoc . Components . Schemas = new SortedDictionary < string , OpenApiSchema > ( swaggerDoc . Components . Schemas , _options . SchemaComparer ) ;
74
+
53
75
return swaggerDoc ;
54
76
}
55
77
56
- private ( IEnumerable < ApiDescription > , OpenApiDocument , SchemaRepository ) GetSwaggerDocument ( string documentName , string host = null , string basePath = null )
78
+ private ( IEnumerable < ApiDescription > , OpenApiDocument , SchemaRepository ) GetSwaggerDocumentWithoutFilters ( string documentName , string host = null , string basePath = null )
57
79
{
58
80
if ( ! _options . SwaggerDocs . TryGetValue ( documentName , out OpenApiInfo info ) )
59
81
throw new UnknownSwaggerDocument ( documentName , _options . SwaggerDocs . Select ( d => d . Key ) ) ;
@@ -77,14 +99,6 @@ public OpenApiDocument GetSwagger(string documentName, string host = null, strin
77
99
SecurityRequirements = new List < OpenApiSecurityRequirement > ( _options . SecurityRequirements )
78
100
} ;
79
101
80
- var filterContext = new DocumentFilterContext ( applicableApiDescriptions , _schemaGenerator , schemaRepository ) ;
81
- foreach ( var filter in _options . DocumentFilters )
82
- {
83
- filter . Apply ( swaggerDoc , filterContext ) ;
84
- }
85
-
86
- swaggerDoc . Components . Schemas = new SortedDictionary < string , OpenApiSchema > ( swaggerDoc . Components . Schemas , _options . SchemaComparer ) ;
87
-
88
102
return ( applicableApiDescriptions , swaggerDoc , schemaRepository ) ;
89
103
}
90
104
0 commit comments