Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a70ac75

Browse files
committedJan 20, 2021
Rework operation customizing to consider returned value. Fixes #1025
1 parent 01992fe commit a70ac75

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed
 

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

Lines changed: 10 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,13 @@ 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+
}
714+
return customizedOperation;
708715
}
709716

710717
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import io.swagger.v3.oas.models.Operation;
2424

25+
import org.springframework.lang.Nullable;
2526
import org.springframework.web.method.HandlerMethod;
2627

2728
/**
@@ -37,8 +38,7 @@ public interface OperationCustomizer {
3738
*
3839
* @param operation input operation
3940
* @param handlerMethod original handler method
40-
* @return customized operation
41+
* @return customized operation or null to hide operation
4142
*/
4243
Operation customize(Operation operation, HandlerMethod handlerMethod);
4344
}
44-

0 commit comments

Comments
 (0)
Please sign in to comment.