@@ -44,6 +44,7 @@ public abstract class AbstractOpenApiResource {
44
44
protected RequestBodyBuilder requestBodyBuilder ;
45
45
protected GeneralInfoBuilder generalInfoBuilder ;
46
46
protected Optional <List <OpenApiCustomiser >> openApiCustomisers ;
47
+ private boolean computeDone ;
47
48
48
49
protected AbstractOpenApiResource (OpenAPIBuilder openAPIBuilder , AbstractRequestBuilder requestBuilder ,
49
50
AbstractResponseBuilder responseBuilder , OperationBuilder operationParser ,
@@ -59,29 +60,35 @@ protected AbstractOpenApiResource(OpenAPIBuilder openAPIBuilder, AbstractRequest
59
60
}
60
61
61
62
protected OpenAPI getOpenApi () {
62
- Instant start = Instant .now ();
63
- generalInfoBuilder .build (openAPIBuilder .getOpenAPI ());
64
- Map <String , Object > restControllersMap = generalInfoBuilder .getRestControllersMap ();
65
- Map <String , Object > requestMappingMap = generalInfoBuilder .getRequestMappingMap ();
66
- Map <String , Object > restControllers = Stream .of (restControllersMap , requestMappingMap )
67
- .flatMap (mapEl -> mapEl .entrySet ().stream ())
68
- .filter (controller -> (AnnotationUtils .findAnnotation (controller .getValue ().getClass (),
69
- Hidden .class ) == null ))
70
- .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (a1 , a2 ) -> a1 ));
71
-
72
- Map <String , Object > findControllerAdvice = generalInfoBuilder .getControllerAdviceMap ();
73
- // calculate generic responses
74
- responseBuilder .buildGenericResponse (openAPIBuilder .getComponents (), findControllerAdvice );
75
-
76
- getPaths (restControllers );
77
- OpenAPI openApi = openAPIBuilder .getOpenAPI ();
78
-
79
- // run the optional customisers
80
- if (openApiCustomisers .isPresent ()) {
81
- openApiCustomisers .get ().stream ().forEach (openApiCustomiser -> openApiCustomiser .customise (openApi ));
82
- }
83
-
84
- LOGGER .info ("Init duration for springdoc-openapi is: {} ms" , Duration .between (start , Instant .now ()).toMillis ());
63
+ OpenAPI openApi ;
64
+ if (!computeDone ) {
65
+ Instant start = Instant .now ();
66
+ generalInfoBuilder .build (openAPIBuilder .getOpenAPI ());
67
+ Map <String , Object > restControllersMap = generalInfoBuilder .getRestControllersMap ();
68
+ Map <String , Object > requestMappingMap = generalInfoBuilder .getRequestMappingMap ();
69
+ Map <String , Object > restControllers = Stream .of (restControllersMap , requestMappingMap )
70
+ .flatMap (mapEl -> mapEl .entrySet ().stream ())
71
+ .filter (controller -> (AnnotationUtils .findAnnotation (controller .getValue ().getClass (),
72
+ Hidden .class ) == null ))
73
+ .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (a1 , a2 ) -> a1 ));
74
+
75
+ Map <String , Object > findControllerAdvice = generalInfoBuilder .getControllerAdviceMap ();
76
+ // calculate generic responses
77
+ responseBuilder .buildGenericResponse (openAPIBuilder .getComponents (), findControllerAdvice );
78
+
79
+ getPaths (restControllers );
80
+ openApi = openAPIBuilder .getOpenAPI ();
81
+
82
+ // run the optional customisers
83
+ if (openApiCustomisers .isPresent ()) {
84
+ openApiCustomisers .get ().stream ().forEach (openApiCustomiser -> openApiCustomiser .customise (openApi ));
85
+ }
86
+ LOGGER .info ("Init duration for springdoc-openapi is: {} ms" ,
87
+ Duration .between (start , Instant .now ()).toMillis ());
88
+ computeDone = true ;
89
+ } else {
90
+ openApi = openAPIBuilder .getOpenAPI ();
91
+ }
85
92
return openApi ;
86
93
}
87
94
0 commit comments