Make 'returns' attribute optional in parsing 13/325413/1
authorChanggyu Choi <changyu.choi@samsung.com>
Tue, 10 Jun 2025 07:30:38 +0000 (16:30 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Tue, 10 Jun 2025 07:30:38 +0000 (16:30 +0900)
The 'returns' attribute is now treated as optional during parsing.
When the attribute is not present, the parser will pass without
raising an exception.

Change-Id: I2dbe358df33752b7116cf64ae22427a28cf9227a
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/common/action_schema.cc
test/unit_tests/action_schema_test.cc

index 63a37777c1f9ccc5bddc32d27857244aab89c981..89b8d435765a4c4787bb90e64929261efebad883 100644 (file)
@@ -30,8 +30,7 @@ std::map<std::string, common::ParameterType> kTypeMap = {
     {"number", common::ParameterType::NumberType},
     {"boolean", common::ParameterType::BoolType},
     {"object", common::ParameterType::ObjectType},
-    {"array", common::ParameterType::ArrayType}
-};
+    {"array", common::ParameterType::ArrayType}};
 
 common::ParameterType ConvertStringToParameterType(const std::string& type) {
   auto it = kTypeMap.find(type);
@@ -82,13 +81,18 @@ ActionSchema::ActionSchema(std::string json_str)
       parameters_.emplace_back(name, type, description, is_required);
     }
 
-    // returns
-    for (const auto& [name, value] : root.members("returns")) {
-      common::ParameterType type = ConvertStringToParameterType(
-          SafeJson::get<std::string>(*value, "type"));
-      std::string description = SafeJson::get<std::string>(*value, "desc");
-      // ActionParameterType -> another class???
-      returns_.emplace_back(name, type, description, false);
+    try {
+      // returns
+      for (const auto& [name, value] : root.members("returns")) {
+        common::ParameterType type = ConvertStringToParameterType(
+            SafeJson::get<std::string>(*value, "type"));
+        std::string description = SafeJson::get<std::string>(*value, "desc");
+        // ActionParameterType -> another class???
+        returns_.emplace_back(name, type, description, false);
+      }
+    } catch (...) {
+      // optional
+      returns_.clear();
     }
 
     try {
index f08be2f435636c2e870dd06836cf46db4c15fc12..9188ff5dbe0f3a0c89dc4afb0adc76c6747febfd 100644 (file)
@@ -49,12 +49,6 @@ class ActionSchemaTest : public ::testing::Test {
                 "desc": "Param 2"
               }
             },
-            "returns": {
-              "return1": {
-                "type": "number",
-                "desc": "Return 1"
-              }
-            },
             "requiredPrivileges": ["priv1", "priv2"],
             "details": {
               "pluginPath": "/path/to/plugin"
@@ -107,8 +101,7 @@ TEST_F(ActionSchemaTest, ValidPluginActionJsonParsing) {
   EXPECT_EQ(params[1].GetType(), ParameterType::NumberType);
 
   const auto& returns = schema.GetReturns();
-  EXPECT_EQ(returns.size(), 1);
-  EXPECT_EQ(returns[0].GetType(), ParameterType::NumberType);
+  EXPECT_EQ(returns.size(), 0);
 
   const auto& privileges = schema.GetPrivileges();
   EXPECT_EQ(privileges.size(), 2);