Skip to content

Commit 6e3f406

Browse files
author
bnasslahsen
committed
code review
1 parent 10431d3 commit 6e3f406

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/core/DataRestRouterOperationBuilder.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,14 @@ private void buildRouterOperationList(List<RouterOperation> routerOperationList,
177177
for (RequestMethod requestMethod : requestMethods) {
178178
if (!UNDOCUMENTED_REQUEST_METHODS.contains(requestMethod)) {
179179
PatternsRequestCondition patternsRequestCondition = requestMappingInfo.getPatternsCondition();
180-
Set<String> patterns = patternsRequestCondition.getPatterns();
181-
Map<String, String> regexMap = new LinkedHashMap<>();
182-
String relationName = (dataRestRepository!=null) ? dataRestRepository.getRelationName(): null;
183-
String operationPath = calculateOperationPath(path, subPath, patterns, regexMap, controllerType, relationName);
184-
buildRouterOperation(routerOperationList, dataRestRepository, openAPI, methodResourceMapping,
185-
handlerMethod, requestMethod, resourceMetadata, operationPath, controllerType);
180+
if (patternsRequestCondition != null) {
181+
Set<String> patterns = patternsRequestCondition.getPatterns();
182+
Map<String, String> regexMap = new LinkedHashMap<>();
183+
String relationName = (dataRestRepository != null) ? dataRestRepository.getRelationName() : null;
184+
String operationPath = calculateOperationPath(path, subPath, patterns, regexMap, controllerType, relationName);
185+
buildRouterOperation(routerOperationList, dataRestRepository, openAPI, methodResourceMapping,
186+
handlerMethod, requestMethod, resourceMetadata, operationPath, controllerType);
187+
}
186188
}
187189
}
188190
}
@@ -270,16 +272,18 @@ private Optional<Entry<RequestMappingInfo, HandlerMethod>> getSearchEntry(Map<Re
270272
private boolean isSearchControllerPresent(RequestMappingInfo requestMappingInfo, HandlerMethod handlerMethod, RequestMethod requestMethod) {
271273
if (!UNDOCUMENTED_REQUEST_METHODS.contains(requestMethod)) {
272274
PatternsRequestCondition patternsRequestCondition = requestMappingInfo.getPatternsCondition();
273-
Set<String> patterns = patternsRequestCondition.getPatterns();
274-
Map<String, String> regexMap = new LinkedHashMap<>();
275-
String operationPath;
276-
for (String pattern : patterns) {
277-
operationPath = PathUtils.parsePath(pattern, regexMap);
278-
if (operationPath.contains(REPOSITORY_PATH) && operationPath.contains(SEARCH_PATH)) {
279-
MethodAttributes methodAttributes = new MethodAttributes(springDocConfigProperties.getDefaultConsumesMediaType(), springDocConfigProperties.getDefaultProducesMediaType());
280-
methodAttributes.calculateConsumesProduces(handlerMethod.getMethod());
281-
if (springDocConfigProperties.getDefaultProducesMediaType().equals(methodAttributes.getMethodProduces()[0]))
282-
return true;
275+
if (patternsRequestCondition != null) {
276+
Set<String> patterns = patternsRequestCondition.getPatterns();
277+
Map<String, String> regexMap = new LinkedHashMap<>();
278+
String operationPath;
279+
for (String pattern : patterns) {
280+
operationPath = PathUtils.parsePath(pattern, regexMap);
281+
if (operationPath.contains(REPOSITORY_PATH) && operationPath.contains(SEARCH_PATH)) {
282+
MethodAttributes methodAttributes = new MethodAttributes(springDocConfigProperties.getDefaultConsumesMediaType(), springDocConfigProperties.getDefaultProducesMediaType());
283+
methodAttributes.calculateConsumesProduces(handlerMethod.getMethod());
284+
if (springDocConfigProperties.getDefaultProducesMediaType().equals(methodAttributes.getMethodProduces()[0]))
285+
return true;
286+
}
283287
}
284288
}
285289
}

springdoc-openapi-webmvc-core/src/main/java/org/springdoc/webmvc/api/OpenApiResource.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -242,21 +242,23 @@ protected void calculatePath(Map<String, Object> restControllers, Map<RequestMap
242242
RequestMappingInfo requestMappingInfo = entry.getKey();
243243
HandlerMethod handlerMethod = entry.getValue();
244244
PatternsRequestCondition patternsRequestCondition = requestMappingInfo.getPatternsCondition();
245-
Set<String> patterns = patternsRequestCondition.getPatterns();
246-
Map<String, String> regexMap = new LinkedHashMap<>();
247-
for (String pattern : patterns) {
248-
String operationPath = PathUtils.parsePath(pattern, regexMap);
249-
String[] produces = requestMappingInfo.getProducesCondition().getProducibleMediaTypes().stream().map(MimeType::toString).toArray(String[]::new);
250-
String[] consumes = requestMappingInfo.getConsumesCondition().getConsumableMediaTypes().stream().map(MimeType::toString).toArray(String[]::new);
251-
String[] headers = requestMappingInfo.getHeadersCondition().getExpressions().stream().map(Object::toString).toArray(String[]::new);
252-
if (((actuatorProvider.isPresent() && actuatorProvider.get().isRestController(operationPath, handlerMethod.getBeanType()))
253-
|| isRestController(restControllers, handlerMethod, operationPath))
254-
&& isFilterCondition(handlerMethod, operationPath, produces, consumes, headers)) {
255-
Set<RequestMethod> requestMethods = requestMappingInfo.getMethodsCondition().getMethods();
256-
// default allowed requestmethods
257-
if (requestMethods.isEmpty())
258-
requestMethods = this.getDefaultAllowedHttpMethods();
259-
calculatePath(handlerMethod, operationPath, requestMethods);
245+
if (patternsRequestCondition != null) {
246+
Set<String> patterns = patternsRequestCondition.getPatterns();
247+
Map<String, String> regexMap = new LinkedHashMap<>();
248+
for (String pattern : patterns) {
249+
String operationPath = PathUtils.parsePath(pattern, regexMap);
250+
String[] produces = requestMappingInfo.getProducesCondition().getProducibleMediaTypes().stream().map(MimeType::toString).toArray(String[]::new);
251+
String[] consumes = requestMappingInfo.getConsumesCondition().getConsumableMediaTypes().stream().map(MimeType::toString).toArray(String[]::new);
252+
String[] headers = requestMappingInfo.getHeadersCondition().getExpressions().stream().map(Object::toString).toArray(String[]::new);
253+
if (((actuatorProvider.isPresent() && actuatorProvider.get().isRestController(operationPath, handlerMethod.getBeanType()))
254+
|| isRestController(restControllers, handlerMethod, operationPath))
255+
&& isFilterCondition(handlerMethod, operationPath, produces, consumes, headers)) {
256+
Set<RequestMethod> requestMethods = requestMappingInfo.getMethodsCondition().getMethods();
257+
// default allowed requestmethods
258+
if (requestMethods.isEmpty())
259+
requestMethods = this.getDefaultAllowedHttpMethods();
260+
calculatePath(handlerMethod, operationPath, requestMethods);
261+
}
260262
}
261263
}
262264
}

0 commit comments

Comments
 (0)