49
49
import org .slf4j .Logger ;
50
50
import org .slf4j .LoggerFactory ;
51
51
52
+ import org .springdoc .core .customizers .OpenApiBuilderCustomiser ;
52
53
import org .springframework .beans .factory .config .BeanDefinition ;
53
54
import org .springframework .boot .autoconfigure .AutoConfigurationPackages ;
54
55
import org .springframework .context .ApplicationContext ;
@@ -81,18 +82,24 @@ public class OpenAPIBuilder {
81
82
82
83
private final SecurityParser securityParser ;
83
84
85
+ private final Map <String , Object > mappingsMap = new HashMap <>();
86
+
84
87
private final Map <HandlerMethod , io .swagger .v3 .oas .models .tags .Tag > springdocTags = new HashMap <>();
85
88
86
89
private final Optional <SecurityOAuth2Provider > springSecurityOAuth2Provider ;
87
90
91
+ private final List <OpenApiBuilderCustomiser > openApiBuilderCustomisers ;
92
+
88
93
private boolean isServersPresent ;
89
94
90
95
private String serverBaseUrl ;
91
96
92
97
private final SpringDocConfigProperties springDocConfigProperties ;
93
98
94
99
@ SuppressWarnings ("WeakerAccess" )
95
- OpenAPIBuilder (Optional <OpenAPI > openAPI , ApplicationContext context , SecurityParser securityParser , Optional <SecurityOAuth2Provider > springSecurityOAuth2Provider , SpringDocConfigProperties springDocConfigProperties ) {
100
+ OpenAPIBuilder (Optional <OpenAPI > openAPI , ApplicationContext context , SecurityParser securityParser ,
101
+ Optional <SecurityOAuth2Provider > springSecurityOAuth2Provider , SpringDocConfigProperties springDocConfigProperties ,
102
+ List <OpenApiBuilderCustomiser > openApiBuilderCustomisers ) {
96
103
if (openAPI .isPresent ()) {
97
104
this .openAPI = openAPI .get ();
98
105
if (this .openAPI .getComponents () == null )
@@ -106,6 +113,7 @@ public class OpenAPIBuilder {
106
113
this .securityParser = securityParser ;
107
114
this .springSecurityOAuth2Provider = springSecurityOAuth2Provider ;
108
115
this .springDocConfigProperties = springDocConfigProperties ;
116
+ this .openApiBuilderCustomisers = openApiBuilderCustomisers ;
109
117
}
110
118
111
119
private static String splitCamelCase (String str ) {
@@ -146,12 +154,18 @@ else if (calculatedOpenAPI.getInfo() == null) {
146
154
Info infos = new Info ().title (DEFAULT_TITLE ).version (DEFAULT_VERSION );
147
155
calculatedOpenAPI .setInfo (infos );
148
156
}
157
+ // Set default mappings
158
+ this .mappingsMap .putAll (context .getBeansWithAnnotation (RestController .class ));
159
+ this .mappingsMap .putAll (context .getBeansWithAnnotation (RequestMapping .class ));
160
+ this .mappingsMap .putAll (context .getBeansWithAnnotation (Controller .class ));
161
+
149
162
// default server value
150
163
if (CollectionUtils .isEmpty (calculatedOpenAPI .getServers ()) || !isServersPresent ) {
151
164
this .updateServers (calculatedOpenAPI );
152
165
}
153
166
// add security schemes
154
167
this .calculateSecuritySchemes (calculatedOpenAPI .getComponents ());
168
+ Optional .ofNullable (this .openApiBuilderCustomisers ).ifPresent (customisers -> customisers .forEach (customiser -> customiser .customise (this )));
155
169
}
156
170
157
171
public void updateServers (OpenAPI openAPI ) {
@@ -397,16 +411,12 @@ public void addTag(Set<HandlerMethod> handlerMethods, io.swagger.v3.oas.models.t
397
411
handlerMethods .forEach (handlerMethod -> springdocTags .put (handlerMethod , tag ));
398
412
}
399
413
400
- public Map <String , Object > getRestControllersMap () {
401
- return context .getBeansWithAnnotation (RestController .class );
402
- }
403
-
404
- public Map <String , Object > getRequestMappingMap () {
405
- return context .getBeansWithAnnotation (RequestMapping .class );
414
+ public Map <String , Object > getMappingsMap () {
415
+ return this .mappingsMap ;
406
416
}
407
417
408
- public Map <String , Object > getControllersMap ( ) {
409
- return context . getBeansWithAnnotation ( Controller . class );
418
+ public void addMappings ( Map <String , Object > mappings ) {
419
+ this . mappingsMap . putAll ( mappings );
410
420
}
411
421
412
422
public Map <String , Object > getControllerAdviceMap () {
0 commit comments