This is an automated email from the ASF dual-hosted git repository.
mridulpathak pushed a commit to branch release24.09
in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git
The following commit(s) were added to refs/heads/release24.09 by this push:
new 0447d58e7 Fixed: ModelApiReader resolved omitted auth/publish
attributes to false, opposite of rest-api.xsd's declared default (#408)
0447d58e7 is described below
commit 0447d58e79b6bf51ed7dfe3d7e294a8593d1e133
Author: Mridul Pathak <[email protected]>
AuthorDate: Thu Sep 17 14:50:17 2026 +0530
Fixed: ModelApiReader resolved omitted auth/publish attributes to false,
opposite of rest-api.xsd's declared default (#408)
Backported from trunk (apache/ofbiz-framework#2011).
Manually re-applied rather than cherry-picked: on release24.09, rest-api
still lives as a plugin here (javax.ws.rs) rather than framework/rest-api's
later Jakarta-based layout, so the fix is reproduced against that version of
ModelApiReader.
---
.../apache/ofbiz/ws/rs/model/ModelApiReader.java | 23 ++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git
a/rest-api/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java
b/rest-api/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java
index 0bc8c3cb9..fa6dd31bd 100644
--- a/rest-api/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java
+++ b/rest-api/src/main/java/org/apache/ofbiz/ws/rs/model/ModelApiReader.java
@@ -49,7 +49,7 @@ public final class ModelApiReader {
api.setDisplayName(UtilXml.checkEmpty(docElement.getAttribute("displayName")).intern());
api.setName(UtilXml.checkEmpty(docElement.getAttribute("name")).intern());
api.setDescription(UtilXml.checkEmpty(docElement.getAttribute("description")).intern());
-
api.setPublish(Boolean.parseBoolean(UtilXml.checkEmpty(docElement.getAttribute("publish")).intern()));
+
api.setPublish(parseBooleanDefaultTrue(docElement.getAttribute("publish")));
for (Element resourceEle : UtilXml.childElementList(docElement,
"resource")) {
createModelResource(resourceEle, api);
}
@@ -61,8 +61,8 @@ public final class ModelApiReader {
.description(UtilXml.checkEmpty(resourceEle.getAttribute("description")).intern())
.displayName(UtilXml.checkEmpty(resourceEle.getAttribute("displayName")).intern())
.path(UtilXml.checkEmpty(resourceEle.getAttribute("path")).intern())
-
.publish(Boolean.parseBoolean(UtilXml.checkEmpty(resourceEle.getAttribute("publish")).intern()))
-
.auth(Boolean.parseBoolean(UtilXml.checkEmpty(resourceEle.getAttribute("auth")).intern()));
+
.publish(parseBooleanDefaultTrue(resourceEle.getAttribute("publish")))
+
.auth(parseBooleanDefaultTrue(resourceEle.getAttribute("auth")));
createOperations(resourceEle, resource);
Debug.logInfo(resource.toString(), MODULE);
modelApi.addResource(resource);
@@ -78,9 +78,24 @@ public final class ModelApiReader {
.produces(UtilXml.checkEmpty(operationEle.getAttribute("produces")).intern())
.consumes(UtilXml.checkEmpty(operationEle.getAttribute("consumes")).intern())
.description(UtilXml.checkEmpty(operationEle.getAttribute("description")).intern())
-
.auth(Boolean.parseBoolean(UtilXml.checkEmpty(operationEle.getAttribute("auth")).intern()));
+
.auth(parseBooleanDefaultTrue(operationEle.getAttribute("auth")));
resource.addOperation(op);
}
}
+ /**
+ * Parses an {@code xs:boolean}-typed attribute that {@code rest-api.xsd}
declares with
+ * {@code default="true"} (currently {@code publish} and {@code auth}).
DOM's
+ * {@code Element.getAttribute} returns {@code ""} for an attribute that
is absent from the
+ * source XML, so the omitted case must be defaulted explicitly rather
than handed to
+ * {@link Boolean#parseBoolean(String)}, which would otherwise resolve it
to {@code false}.
+ *
+ * @param attributeValue the raw attribute value, or {@code ""} if the
attribute was omitted
+ * @return {@code true} if the attribute was omitted or explicitly {@code
"true"}; {@code false} otherwise
+ */
+ private static boolean parseBooleanDefaultTrue(String attributeValue) {
+ String value = UtilXml.checkEmpty(attributeValue).intern();
+ return value.isEmpty() || Boolean.parseBoolean(value);
+ }
+
}