68
68
public abstract class AbstractOpenApiResource extends SpecFilter {
69
69
70
70
private static final Logger LOGGER = LoggerFactory .getLogger (AbstractOpenApiResource .class );
71
-
72
- final OpenAPIBuilder openAPIBuilder ;
73
-
74
71
private final AbstractRequestBuilder requestBuilder ;
75
-
76
72
private final GenericResponseBuilder responseBuilder ;
77
-
78
73
private final OperationBuilder operationParser ;
79
-
80
74
private final Optional <List <OpenApiCustomiser >> openApiCustomisers ;
81
-
82
75
private final AntPathMatcher antPathMatcher = new AntPathMatcher ();
83
-
84
- protected final SpringDocConfigProperties springDocConfigProperties ;
85
-
86
76
private static final List <Class <?>> ADDITIONAL_REST_CONTROLLERS = new ArrayList <>();
87
-
88
77
private static final List <Class <?>> HIDDEN_REST_CONTROLLERS = new ArrayList <>();
89
-
90
78
private static final List <Class > DEPRECATED_TYPES = new ArrayList <>();
91
-
92
79
private boolean computeDone ;
93
-
94
80
private final String groupName ;
81
+ protected final OpenAPIBuilder openAPIBuilder ;
82
+ protected final SpringDocConfigProperties springDocConfigProperties ;
95
83
96
84
static {
97
85
DEPRECATED_TYPES .add (Deprecated .class );
98
86
}
99
87
100
- protected AbstractOpenApiResource (String groupName , OpenAPIBuilder openAPIBuilder , AbstractRequestBuilder requestBuilder ,
88
+ protected AbstractOpenApiResource (String groupName , OpenAPIBuilder openAPIBuilder ,
89
+ AbstractRequestBuilder requestBuilder ,
101
90
GenericResponseBuilder responseBuilder , OperationBuilder operationParser ,
102
- Optional <List <OpenApiCustomiser >> openApiCustomisers , SpringDocConfigProperties springDocConfigProperties ) {
91
+ Optional <List <OpenApiCustomiser >> openApiCustomisers ,
92
+ SpringDocConfigProperties springDocConfigProperties ) {
103
93
super ();
104
94
this .groupName = Objects .requireNonNull (groupName , "groupName" );
105
95
this .openAPIBuilder = openAPIBuilder ;
@@ -112,7 +102,7 @@ protected AbstractOpenApiResource(String groupName, OpenAPIBuilder openAPIBuilde
112
102
113
103
protected synchronized OpenAPI getOpenApi () {
114
104
OpenAPI openApi ;
115
- if (!computeDone || springDocConfigProperties .getCache (). isDisabled ()) {
105
+ if (!computeDone || springDocConfigProperties .isCacheDisabled ()) {
116
106
Instant start = Instant .now ();
117
107
openAPIBuilder .build ();
118
108
Map <String , Object > mappingsMap = openAPIBuilder .getMappingsMap ().entrySet ().stream ()
@@ -123,11 +113,9 @@ protected synchronized OpenAPI getOpenApi() {
123
113
124
114
Map <String , Object > findControllerAdvice = openAPIBuilder .getControllerAdviceMap ();
125
115
// calculate generic responses
126
- responseBuilder .buildGenericResponse (openAPIBuilder .getCalculatedOpenAPI ().getComponents (), findControllerAdvice );
127
-
128
- getPaths (mappingsMap );
129
116
openApi = openAPIBuilder .getCalculatedOpenAPI ();
130
-
117
+ responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice );
118
+ getPaths (mappingsMap );
131
119
// run the optional customisers
132
120
openApiCustomisers .ifPresent (apiCustomisers -> apiCustomisers .forEach (openApiCustomiser -> openApiCustomiser .customise (openApi )));
133
121
computeDone = true ;
@@ -139,9 +127,7 @@ protected synchronized OpenAPI getOpenApi() {
139
127
Duration .between (start , Instant .now ()).toMillis ());
140
128
}
141
129
else {
142
- if (!openAPIBuilder .isServersPresent ())
143
- openAPIBuilder .updateServers (openAPIBuilder .getCachedOpenAPI ());
144
- openApi = openAPIBuilder .getCachedOpenAPI ();
130
+ openApi = openAPIBuilder .calculateCachedOpenAPI ();
145
131
}
146
132
return openApi ;
147
133
}
@@ -161,13 +147,11 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
161
147
}
162
148
163
149
for (RequestMethod requestMethod : requestMethods ) {
164
-
165
150
Operation existingOperation = getExistingOperation (operationMap , requestMethod );
166
151
Method method = handlerMethod .getMethod ();
167
152
// skip hidden operations
168
- if (operationParser .isHidden (method )) {
153
+ if (operationParser .isHidden (method ))
169
154
continue ;
170
- }
171
155
172
156
RequestMapping reqMappingClass = AnnotatedElementUtils .findMergedAnnotation (handlerMethod .getBeanType (),
173
157
RequestMapping .class );
@@ -184,19 +168,17 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
184
168
185
169
Operation operation = (existingOperation != null ) ? existingOperation : new Operation ();
186
170
187
- if (isDeprecatedType (method )) {
171
+ if (isDeprecatedType (method ))
188
172
operation .setDeprecated (true );
189
- }
190
173
191
174
// Add documentation from operation annotation
192
175
io .swagger .v3 .oas .annotations .Operation apiOperation = AnnotatedElementUtils .findMergedAnnotation (method ,
193
176
io .swagger .v3 .oas .annotations .Operation .class );
194
177
195
178
calculateJsonView (apiOperation , methodAttributes , method );
196
179
197
- if (apiOperation != null ) {
180
+ if (apiOperation != null )
198
181
openAPI = operationParser .parse (apiOperation , operation , openAPI , methodAttributes );
199
- }
200
182
201
183
// compute tags
202
184
operation = openAPIBuilder .buildTags (handlerMethod , operation , openAPI );
@@ -220,10 +202,9 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
220
202
Set <io .swagger .v3 .oas .annotations .callbacks .Callback > apiCallbacks = AnnotatedElementUtils .findMergedRepeatableAnnotations (method , io .swagger .v3 .oas .annotations .callbacks .Callback .class );
221
203
222
204
// callbacks
223
- if (!CollectionUtils .isEmpty (apiCallbacks )) {
205
+ if (!CollectionUtils .isEmpty (apiCallbacks ))
224
206
operationParser .buildCallbacks (apiCallbacks , openAPI , methodAttributes )
225
207
.ifPresent (operation ::setCallbacks );
226
- }
227
208
228
209
PathItem pathItemObject = buildPathItem (requestMethod , operation , operationPath , paths );
229
210
paths .addPathItem (operationPath , pathItemObject );
@@ -293,12 +274,11 @@ private Operation getExistingOperation(Map<HttpMethod, Operation> operationMap,
293
274
private PathItem buildPathItem (RequestMethod requestMethod , Operation operation , String operationPath ,
294
275
Paths paths ) {
295
276
PathItem pathItemObject ;
296
- if (paths .containsKey (operationPath )) {
277
+ if (paths .containsKey (operationPath ))
297
278
pathItemObject = paths .get (operationPath );
298
- }
299
- else {
279
+ else
300
280
pathItemObject = new PathItem ();
301
- }
281
+
302
282
switch (requestMethod ) {
303
283
case POST :
304
284
pathItemObject .post (operation );
@@ -385,14 +365,6 @@ protected boolean isAdditionalRestController(Class<?> rawClass) {
385
365
return ADDITIONAL_REST_CONTROLLERS .stream ().anyMatch (clazz -> clazz .isAssignableFrom (rawClass ));
386
366
}
387
367
388
- public static void addRestControllers (Class <?>... classes ) {
389
- ADDITIONAL_REST_CONTROLLERS .addAll (Arrays .asList (classes ));
390
- }
391
-
392
- public static void addHiddenRestControllers (Class <?>... classes ) {
393
- HIDDEN_REST_CONTROLLERS .addAll (Arrays .asList (classes ));
394
- }
395
-
396
368
protected boolean isHiddenRestControllers (Class <?> rawClass ) {
397
369
return HIDDEN_REST_CONTROLLERS .stream ().anyMatch (clazz -> clazz .isAssignableFrom (rawClass ));
398
370
}
@@ -402,11 +374,20 @@ protected Set getDefaultAllowedHttpMethods() {
402
374
return new HashSet <>(Arrays .asList (allowedRequestMethods ));
403
375
}
404
376
377
+ private boolean isDeprecatedType (Method method ) {
378
+ return DEPRECATED_TYPES .stream ().anyMatch (clazz -> (AnnotatedElementUtils .findMergedAnnotation (method , clazz ) != null ));
379
+ }
380
+
381
+ public static void addRestControllers (Class <?>... classes ) {
382
+ ADDITIONAL_REST_CONTROLLERS .addAll (Arrays .asList (classes ));
383
+ }
384
+
385
+ public static void addHiddenRestControllers (Class <?>... classes ) {
386
+ HIDDEN_REST_CONTROLLERS .addAll (Arrays .asList (classes ));
387
+ }
388
+
405
389
public static void addDeprecatedType (Class <?> cls ) {
406
390
DEPRECATED_TYPES .add (cls );
407
391
}
408
392
409
- private boolean isDeprecatedType (Method method ) {
410
- return DEPRECATED_TYPES .stream ().anyMatch (clazz -> (AnnotatedElementUtils .findMergedAnnotation (method , clazz ) != null ));
411
- }
412
393
}
0 commit comments