You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by il...@apache.org on 2018/10/05 13:10:28 UTC
[cxf] branch 3.2.x-fixes updated: Allow more customization of
Operation responses
This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.2.x-fixes by this push:
new 4c64888 Allow more customization of Operation responses
4c64888 is described below
commit 4c64888f93f15eef4ff6fc64c75f483a28c864ce
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Fri Oct 5 15:09:12 2018 +0200
Allow more customization of Operation responses
---
.../cxf/jaxrs/openapi/OpenApiCustomizer.java | 31 +++++++++++++++-------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiCustomizer.java b/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiCustomizer.java
index f3dad04..abdc7b7 100644
--- a/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiCustomizer.java
+++ b/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiCustomizer.java
@@ -39,6 +39,7 @@ import org.apache.cxf.jaxrs.model.doc.JavaDocProvider;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
import org.apache.cxf.jaxrs.utils.ResourceUtils;
+import io.swagger.v3.jaxrs2.Reader;
import io.swagger.v3.oas.integration.api.OpenAPIConfiguration;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
@@ -127,6 +128,7 @@ public class OpenApiCustomizer {
if (StringUtils.isBlank(subentry.getValue().getSummary())) {
subentry.getValue().setSummary(javadocProvider.getMethodDoc(ori));
}
+
if (subentry.getValue().getParameters() == null) {
List<Parameter> parameters = new ArrayList<>();
addParameters(parameters);
@@ -141,15 +143,7 @@ public class OpenApiCustomizer {
addParameters(subentry.getValue().getParameters());
}
- if (subentry.getValue().getResponses() != null
- && !subentry.getValue().getResponses().isEmpty()) {
-
- ApiResponse response =
- subentry.getValue().getResponses().entrySet().iterator().next().getValue();
- if (StringUtils.isBlank(response.getDescription())) {
- response.setDescription(javadocProvider.getMethodResponseDoc(ori));
- }
- }
+ customizeResponses(subentry.getValue(), ori);
}
}
});
@@ -190,6 +184,25 @@ public class OpenApiCustomizer {
// does nothing by default
}
+ /**
+ * Allows to customize the responses of the given {@link Operation} instance; the method is invoked
+ * for all instances available.
+ *
+ * @param operation operation instance
+ * @param ori CXF data about the given operation instance
+ */
+ protected void customizeResponses(final Operation operation, final OperationResourceInfo ori) {
+ if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
+ ApiResponse response = operation.getResponses().entrySet().iterator().next().getValue();
+ if (StringUtils.isBlank(response.getDescription())
+ || (StringUtils.isNotBlank(javadocProvider.getMethodResponseDoc(ori))
+ && Reader.DEFAULT_DESCRIPTION.equals(response.getDescription()))) {
+
+ response.setDescription(javadocProvider.getMethodResponseDoc(ori));
+ }
+ }
+ }
+
public void setDynamicBasePath(final boolean dynamicBasePath) {
this.dynamicBasePath = dynamicBasePath;
}