Skip to content

Commit 402a1d5

Browse files
author
bnasslahsen
committed
project review
1 parent 7452898 commit 402a1d5

File tree

42 files changed

+310
-505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+310
-505
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,28 @@
6868
public abstract class AbstractOpenApiResource extends SpecFilter {
6969

7070
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractOpenApiResource.class);
71-
72-
final OpenAPIBuilder openAPIBuilder;
73-
7471
private final AbstractRequestBuilder requestBuilder;
75-
7672
private final GenericResponseBuilder responseBuilder;
77-
7873
private final OperationBuilder operationParser;
79-
8074
private final Optional<List<OpenApiCustomiser>> openApiCustomisers;
81-
8275
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
83-
84-
protected final SpringDocConfigProperties springDocConfigProperties;
85-
8676
private static final List<Class<?>> ADDITIONAL_REST_CONTROLLERS = new ArrayList<>();
87-
8877
private static final List<Class<?>> HIDDEN_REST_CONTROLLERS = new ArrayList<>();
89-
9078
private static final List<Class> DEPRECATED_TYPES = new ArrayList<>();
91-
9279
private boolean computeDone;
93-
9480
private final String groupName;
81+
protected final OpenAPIBuilder openAPIBuilder;
82+
protected final SpringDocConfigProperties springDocConfigProperties;
9583

9684
static {
9785
DEPRECATED_TYPES.add(Deprecated.class);
9886
}
9987

100-
protected AbstractOpenApiResource(String groupName, OpenAPIBuilder openAPIBuilder, AbstractRequestBuilder requestBuilder,
88+
protected AbstractOpenApiResource(String groupName, OpenAPIBuilder openAPIBuilder,
89+
AbstractRequestBuilder requestBuilder,
10190
GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
102-
Optional<List<OpenApiCustomiser>> openApiCustomisers, SpringDocConfigProperties springDocConfigProperties) {
91+
Optional<List<OpenApiCustomiser>> openApiCustomisers,
92+
SpringDocConfigProperties springDocConfigProperties) {
10393
super();
10494
this.groupName = Objects.requireNonNull(groupName, "groupName");
10595
this.openAPIBuilder = openAPIBuilder;
@@ -112,7 +102,7 @@ protected AbstractOpenApiResource(String groupName, OpenAPIBuilder openAPIBuilde
112102

113103
protected synchronized OpenAPI getOpenApi() {
114104
OpenAPI openApi;
115-
if (!computeDone || springDocConfigProperties.getCache().isDisabled()) {
105+
if (!computeDone || springDocConfigProperties.isCacheDisabled()) {
116106
Instant start = Instant.now();
117107
openAPIBuilder.build();
118108
Map<String, Object> mappingsMap = openAPIBuilder.getMappingsMap().entrySet().stream()
@@ -123,11 +113,9 @@ protected synchronized OpenAPI getOpenApi() {
123113

124114
Map<String, Object> findControllerAdvice = openAPIBuilder.getControllerAdviceMap();
125115
// calculate generic responses
126-
responseBuilder.buildGenericResponse(openAPIBuilder.getCalculatedOpenAPI().getComponents(), findControllerAdvice);
127-
128-
getPaths(mappingsMap);
129116
openApi = openAPIBuilder.getCalculatedOpenAPI();
130-
117+
responseBuilder.buildGenericResponse(openApi.getComponents(), findControllerAdvice);
118+
getPaths(mappingsMap);
131119
// run the optional customisers
132120
openApiCustomisers.ifPresent(apiCustomisers -> apiCustomisers.forEach(openApiCustomiser -> openApiCustomiser.customise(openApi)));
133121
computeDone = true;
@@ -139,9 +127,7 @@ protected synchronized OpenAPI getOpenApi() {
139127
Duration.between(start, Instant.now()).toMillis());
140128
}
141129
else {
142-
if (!openAPIBuilder.isServersPresent())
143-
openAPIBuilder.updateServers(openAPIBuilder.getCachedOpenAPI());
144-
openApi = openAPIBuilder.getCachedOpenAPI();
130+
openApi = openAPIBuilder.calculateCachedOpenAPI();
145131
}
146132
return openApi;
147133
}
@@ -161,13 +147,11 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
161147
}
162148

163149
for (RequestMethod requestMethod : requestMethods) {
164-
165150
Operation existingOperation = getExistingOperation(operationMap, requestMethod);
166151
Method method = handlerMethod.getMethod();
167152
// skip hidden operations
168-
if (operationParser.isHidden(method)) {
153+
if (operationParser.isHidden(method))
169154
continue;
170-
}
171155

172156
RequestMapping reqMappingClass = AnnotatedElementUtils.findMergedAnnotation(handlerMethod.getBeanType(),
173157
RequestMapping.class);
@@ -184,19 +168,17 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
184168

185169
Operation operation = (existingOperation != null) ? existingOperation : new Operation();
186170

187-
if (isDeprecatedType(method)) {
171+
if (isDeprecatedType(method))
188172
operation.setDeprecated(true);
189-
}
190173

191174
// Add documentation from operation annotation
192175
io.swagger.v3.oas.annotations.Operation apiOperation = AnnotatedElementUtils.findMergedAnnotation(method,
193176
io.swagger.v3.oas.annotations.Operation.class);
194177

195178
calculateJsonView(apiOperation, methodAttributes, method);
196179

197-
if (apiOperation != null) {
180+
if (apiOperation != null)
198181
openAPI = operationParser.parse(apiOperation, operation, openAPI, methodAttributes);
199-
}
200182

201183
// compute tags
202184
operation = openAPIBuilder.buildTags(handlerMethod, operation, openAPI);
@@ -220,10 +202,9 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
220202
Set<io.swagger.v3.oas.annotations.callbacks.Callback> apiCallbacks = AnnotatedElementUtils.findMergedRepeatableAnnotations(method, io.swagger.v3.oas.annotations.callbacks.Callback.class);
221203

222204
// callbacks
223-
if (!CollectionUtils.isEmpty(apiCallbacks)) {
205+
if (!CollectionUtils.isEmpty(apiCallbacks))
224206
operationParser.buildCallbacks(apiCallbacks, openAPI, methodAttributes)
225207
.ifPresent(operation::setCallbacks);
226-
}
227208

228209
PathItem pathItemObject = buildPathItem(requestMethod, operation, operationPath, paths);
229210
paths.addPathItem(operationPath, pathItemObject);
@@ -293,12 +274,11 @@ private Operation getExistingOperation(Map<HttpMethod, Operation> operationMap,
293274
private PathItem buildPathItem(RequestMethod requestMethod, Operation operation, String operationPath,
294275
Paths paths) {
295276
PathItem pathItemObject;
296-
if (paths.containsKey(operationPath)) {
277+
if (paths.containsKey(operationPath))
297278
pathItemObject = paths.get(operationPath);
298-
}
299-
else {
279+
else
300280
pathItemObject = new PathItem();
301-
}
281+
302282
switch (requestMethod) {
303283
case POST:
304284
pathItemObject.post(operation);
@@ -385,14 +365,6 @@ protected boolean isAdditionalRestController(Class<?> rawClass) {
385365
return ADDITIONAL_REST_CONTROLLERS.stream().anyMatch(clazz -> clazz.isAssignableFrom(rawClass));
386366
}
387367

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-
396368
protected boolean isHiddenRestControllers(Class<?> rawClass) {
397369
return HIDDEN_REST_CONTROLLERS.stream().anyMatch(clazz -> clazz.isAssignableFrom(rawClass));
398370
}
@@ -402,11 +374,20 @@ protected Set getDefaultAllowedHttpMethods() {
402374
return new HashSet<>(Arrays.asList(allowedRequestMethods));
403375
}
404376

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+
405389
public static void addDeprecatedType(Class<?> cls) {
406390
DEPRECATED_TYPES.add(cls);
407391
}
408392

409-
private boolean isDeprecatedType(Method method) {
410-
return DEPRECATED_TYPES.stream().anyMatch(clazz -> (AnnotatedElementUtils.findMergedAnnotation(method, clazz) != null));
411-
}
412393
}

0 commit comments

Comments
 (0)