json_utils: Add support jsonRead Patch/Action
Added support for readJson for Patch and Action. The only difference is
that Patch does not allow empty json input while Action does. Action with
empty input will use the default value based on the implementation and
return 200 OK response code.
readJsonPatch will replace the existing readJson and be used for path
requests. It will not allow empty json input and all requested
keys are required in the json input.
readJsonAction will be used for Action requests where it is possible for
all of the properties to be optional and allow empty request.
The optional properties are determined by the requested values type.
All current Action readJson are replaced with readJsonAction. It does
not change the existing behavior since it needs `std::optional`.
This will have to be updated later as we define the default behavior.
Tested:
Added unit tests and readJsonAction allows empty empty json object.
No Change to Redfish Tree.
Change-Id: Ia5e1f81695c528a20f1dc985aee19c920d8adaea
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 6770c48..227b4e9 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -1964,7 +1964,7 @@
DHCPParameters v4dhcpParms;
DHCPParameters v6dhcpParms;
- if (!json_util::readJson(
+ if (!json_util::readJsonPatch(
req, asyncResp->res, "HostName", hostname, "FQDN", fqdn,
"IPv4StaticAddresses", ipv4StaticAddresses,
"MACAddress", macAddress, "StaticNameServers",
@@ -2163,8 +2163,8 @@
bool vlanEnable = false;
uint32_t vlanId = 0;
- if (!json_util::readJson(req, asyncResp->res, "VLANEnable",
- vlanEnable, "VLANId", vlanId))
+ if (!json_util::readJsonPatch(req, asyncResp->res, "VLANEnable",
+ vlanEnable, "VLANId", vlanId))
{
return;
}
@@ -2350,8 +2350,8 @@
const std::string& rootInterfaceName) {
bool vlanEnable = false;
uint32_t vlanId = 0;
- if (!json_util::readJson(req, asyncResp->res, "VLANId", vlanId,
- "VLANEnable", vlanEnable))
+ if (!json_util::readJsonPatch(req, asyncResp->res, "VLANId",
+ vlanId, "VLANEnable", vlanEnable))
{
return;
}