1
1
using System ;
2
- using System . Collections . Generic ;
3
2
using System . IO ;
4
3
using System . Linq ;
5
4
using System . Net . Http ;
@@ -33,21 +32,12 @@ public static void RegisterRoutes(IUnityContainer container)
33
32
var xmlCommentsFilePaths = xmlCommentsDirectoryPaths . SelectMany ( GetXmlFilesPaths ) . ToArray ( ) ;
34
33
35
34
// Add separate swagger generator for platform
36
- EnableSwagger ( "VirtoCommerce.Platform" , httpConfiguration , container , routePrefix , xmlCommentsFilePaths , false , Assembly . GetExecutingAssembly ( ) , null ) ;
35
+ EnableSwagger ( "VirtoCommerce.Platform" , httpConfiguration , container , routePrefix , xmlCommentsFilePaths , false , Assembly . GetExecutingAssembly ( ) ) ;
37
36
38
37
// Add separate swagger generator for each installed module
39
- var allmodules = container . Resolve < IModuleCatalog > ( ) . Modules . OfType < ManifestModuleInfo > ( ) . Where ( m => m . ModuleInstance != null ) ;
40
-
41
- ICollection < Type > allPolymorphicTypes = new List < Type > ( ) ;
42
-
43
- // Add separate swagger generator for each installed module
44
- foreach ( var module in allmodules )
38
+ foreach ( var module in container . Resolve < IModuleCatalog > ( ) . Modules . OfType < ManifestModuleInfo > ( ) . Where ( m => m . ModuleInstance != null ) )
45
39
{
46
- var polimorphicTypes = GetPolymorphicTypes ( module ) ;
47
-
48
- allPolymorphicTypes . AddRange ( polimorphicTypes ) ;
49
-
50
- EnableSwagger ( module . ModuleName , httpConfiguration , container , routePrefix , xmlCommentsFilePaths , module . UseFullTypeNameInSwagger , module . ModuleInstance . GetType ( ) . Assembly , polimorphicTypes ) ;
40
+ EnableSwagger ( module . ModuleName , httpConfiguration , container , routePrefix , xmlCommentsFilePaths , module . UseFullTypeNameInSwagger , module . ModuleInstance . GetType ( ) . Assembly ) ;
51
41
}
52
42
53
43
// Add full swagger generator
@@ -72,7 +62,7 @@ public static void RegisterRoutes(IUnityContainer container)
72
62
. Replace ( ',' , '-' )
73
63
) ;
74
64
75
- AddProlymorphicFilters ( c , allPolymorphicTypes . ToArray ( ) ) ;
65
+ AddProlymorphicFilters ( container , c , null , true ) ;
76
66
77
67
ApplyCommonSwaggerConfiguration ( c , container , string . Empty , xmlCommentsFilePaths ) ;
78
68
} )
@@ -91,32 +81,14 @@ public static void RegisterRoutes(IUnityContainer container)
91
81
} ) ;
92
82
}
93
83
94
- private static Type [ ] GetPolymorphicTypes ( ManifestModuleInfo module )
95
- {
96
- //TODO: Could move type loading to module loading mechanism with its error handling
97
- Type [ ] polimorphicTypes = null ;
98
- try
99
- {
100
- polimorphicTypes = module . OpenAPIPolymorphicTypes
101
- . Select ( x => Type . GetType ( x , false ) )
102
- . Where ( x => x != null )
103
- . ToArray ( ) ;
104
- }
105
- // Need to add catch as even with GetType throwOnError = false it could throw
106
- catch { }
107
-
108
- return polimorphicTypes ;
109
- }
110
-
111
84
private static void EnableSwagger (
112
85
string moduleName ,
113
86
HttpConfiguration httpConfiguration ,
114
87
IUnityContainer container ,
115
88
string routePrefix ,
116
89
string [ ] xmlCommentsFilePaths ,
117
90
bool useFullTypeNameInSchemaIds ,
118
- Assembly apiAssembly ,
119
- Type [ ] polymorphicTypes )
91
+ Assembly apiAssembly )
120
92
{
121
93
var routeName = string . Concat ( "swagger_" , moduleName ) ;
122
94
var routeTemplate = string . Concat ( routePrefix , "docs/" , moduleName , "/{apiVersion}" ) ;
@@ -136,17 +108,16 @@ private static void EnableSwagger(
136
108
ApplyCommonSwaggerConfiguration ( c , container , moduleName , xmlCommentsFilePaths ) ;
137
109
c . OperationFilter ( ( ) => new ModuleTagsFilter ( moduleName ) ) ;
138
110
139
- AddProlymorphicFilters ( c , polymorphicTypes ) ;
111
+ AddProlymorphicFilters ( container , c , moduleName , false ) ;
140
112
} ) ;
141
113
}
142
114
143
- private static void AddProlymorphicFilters ( SwaggerDocsConfig swaggerDocsConfig , Type [ ] polymorphicTypes )
115
+ private static void AddProlymorphicFilters ( IUnityContainer container , SwaggerDocsConfig swaggerDocsConfig , string moduleName , bool useFullTypeName )
144
116
{
145
- if ( polymorphicTypes ? . Any ( ) == true )
146
- {
147
- swaggerDocsConfig . DocumentFilter ( ( ) => new PolymorphismDocumentFilter ( polymorphicTypes ) ) ;
148
- swaggerDocsConfig . SchemaFilter ( ( ) => new PolymorphismSchemaFilter ( polymorphicTypes ) ) ;
149
- }
117
+ var polymorphismRegistrar = container . Resolve < IPolymorphismRegistrar > ( ) ;
118
+
119
+ swaggerDocsConfig . DocumentFilter ( ( ) => new PolymorphismDocumentFilter ( polymorphismRegistrar , moduleName , useFullTypeName ) ) ;
120
+ swaggerDocsConfig . SchemaFilter ( ( ) => new PolymorphismSchemaFilter ( polymorphismRegistrar , moduleName , useFullTypeName ) ) ;
150
121
}
151
122
152
123
private static Uri ComputeHostAsSeenByOriginalClient ( HttpRequestMessage message )
0 commit comments