4949import org .slf4j .Logger ;
5050import org .slf4j .LoggerFactory ;
5151
52+ import org .springdoc .core .customizers .OpenApiBuilderCustomiser ;
5253import org .springframework .beans .factory .config .BeanDefinition ;
5354import org .springframework .boot .autoconfigure .AutoConfigurationPackages ;
5455import org .springframework .context .ApplicationContext ;
@@ -81,18 +82,24 @@ public class OpenAPIBuilder {
8182
8283 private final SecurityParser securityParser ;
8384
85+ private final Map <String , Object > mappingsMap = new HashMap <>();
86+
8487 private final Map <HandlerMethod , io .swagger .v3 .oas .models .tags .Tag > springdocTags = new HashMap <>();
8588
8689 private final Optional <SecurityOAuth2Provider > springSecurityOAuth2Provider ;
8790
91+ private final List <OpenApiBuilderCustomiser > openApiBuilderCustomisers ;
92+
8893 private boolean isServersPresent ;
8994
9095 private String serverBaseUrl ;
9196
9297 private final SpringDocConfigProperties springDocConfigProperties ;
9398
9499 @ 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 ) {
96103 if (openAPI .isPresent ()) {
97104 this .openAPI = openAPI .get ();
98105 if (this .openAPI .getComponents () == null )
@@ -106,6 +113,7 @@ public class OpenAPIBuilder {
106113 this .securityParser = securityParser ;
107114 this .springSecurityOAuth2Provider = springSecurityOAuth2Provider ;
108115 this .springDocConfigProperties = springDocConfigProperties ;
116+ this .openApiBuilderCustomisers = openApiBuilderCustomisers ;
109117 }
110118
111119 private static String splitCamelCase (String str ) {
@@ -146,12 +154,18 @@ else if (calculatedOpenAPI.getInfo() == null) {
146154 Info infos = new Info ().title (DEFAULT_TITLE ).version (DEFAULT_VERSION );
147155 calculatedOpenAPI .setInfo (infos );
148156 }
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+
149162 // default server value
150163 if (CollectionUtils .isEmpty (calculatedOpenAPI .getServers ()) || !isServersPresent ) {
151164 this .updateServers (calculatedOpenAPI );
152165 }
153166 // add security schemes
154167 this .calculateSecuritySchemes (calculatedOpenAPI .getComponents ());
168+ Optional .ofNullable (this .openApiBuilderCustomisers ).ifPresent (customisers -> customisers .forEach (customiser -> customiser .customise (this )));
155169 }
156170
157171 public void updateServers (OpenAPI openAPI ) {
@@ -397,16 +411,12 @@ public void addTag(Set<HandlerMethod> handlerMethods, io.swagger.v3.oas.models.t
397411 handlerMethods .forEach (handlerMethod -> springdocTags .put (handlerMethod , tag ));
398412 }
399413
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 ;
406416 }
407417
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 );
410420 }
411421
412422 public Map <String , Object > getControllerAdviceMap () {
0 commit comments