Skip to content

Commit 42dde42

Browse files
committed
Rework operation customizing to consider returned value. Fixes #1025
1 parent 01992fe commit 42dde42

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
400400
buildCallbacks(openAPI, methodAttributes, operation, apiCallbacks);
401401

402402
// allow for customisation
403-
customiseOperation(operation, handlerMethod);
403+
operation = customiseOperation(operation, handlerMethod);
404+
if (operation == null)
405+
continue;
404406

405407
PathItem pathItemObject = buildPathItem(requestMethod, operation, operationPath, paths);
406408
paths.addPathItem(operationPath, pathItemObject);
@@ -703,8 +705,15 @@ protected Set<RequestMethod> getDefaultAllowedHttpMethods() {
703705
* @return the operation
704706
*/
705707
protected Operation customiseOperation(Operation operation, HandlerMethod handlerMethod) {
706-
operationCustomizers.ifPresent(customizers -> customizers.forEach(customizer -> customizer.customize(operation, handlerMethod)));
707-
return operation;
708+
if (!operationCustomizers.isPresent())
709+
return operation;
710+
Operation customizedOperation = operation;
711+
for (OperationCustomizer customizer : operationCustomizers.get()) {
712+
customizedOperation = customizer.customize(customizedOperation, handlerMethod);
713+
if (customizedOperation == null)
714+
return null;
715+
}
716+
return customizedOperation;
708717
}
709718

710719
/**

springdoc-openapi-common/src/main/java/org/springdoc/core/customizers/OperationCustomizer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public interface OperationCustomizer {
3737
*
3838
* @param operation input operation
3939
* @param handlerMethod original handler method
40-
* @return customized operation
40+
* @return customized operation or null to hide operation
4141
*/
4242
Operation customize(Operation operation, HandlerMethod handlerMethod);
4343
}
44-

0 commit comments

Comments
 (0)