buffet: Allow omitting "parameters" and "results"

Many commands have neither parameters nor results.
Empty schema will be used if if section is omitted in command definition.

BUG=brillo:915
TEST=FEATURES=test emerge-gizmo buffet

Change-Id: I4df542d889f325223a436bfe032950aa05c35b6e
Reviewed-on: https://chromium-review.googlesource.com/268317
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/commands/command_dictionary.cc b/buffet/commands/command_dictionary.cc
index 3ab57a5..cbfd46b 100644
--- a/buffet/commands/command_dictionary.cc
+++ b/buffet/commands/command_dictionary.cc
@@ -173,13 +173,7 @@
   const base::DictionaryValue* schema_def = nullptr;
   if (!command_def_json->GetDictionaryWithoutPathExpansion(property_name,
                                                            &schema_def)) {
-    chromeos::Error::AddToPrintf(
-        error, FROM_HERE, errors::commands::kDomain,
-        errors::commands::kPropertyMissing,
-        "Command definition '%s' is missing property '%s'",
-        command_name.c_str(),
-        property_name);
-    return {};
+    return object_schema;
   }
 
   if (!object_schema->FromJson(schema_def, base_def, error)) {
diff --git a/buffet/commands/command_dictionary_unittest.cc b/buffet/commands/command_dictionary_unittest.cc
index c50a2ae..63492cc 100644
--- a/buffet/commands/command_dictionary_unittest.cc
+++ b/buffet/commands/command_dictionary_unittest.cc
@@ -36,12 +36,9 @@
   json = CreateDictionaryValue(R"({
     'base': {
       'reboot': {
-        'parameters': {'delay': 'integer'},
-        'results': {}
+        'parameters': {'delay': 'integer'}
       },
       'shutdown': {
-        'parameters': {},
-        'results': {}
       }
     }
   })");
@@ -59,24 +56,8 @@
   buffet::CommandDictionary dict;
   chromeos::ErrorPtr error;
 
-  // Command definition missing 'parameters' property.
-  auto json = CreateDictionaryValue("{'robot':{'jump':{'results':{}}}}");
-  EXPECT_FALSE(dict.LoadCommands(*json, "robotd", nullptr, &error));
-  EXPECT_EQ("parameter_missing", error->GetCode());
-  EXPECT_EQ("Command definition 'robot.jump' is missing property 'parameters'",
-            error->GetMessage());
-  error.reset();
-
-  // Command definition missing 'results' property.
-  json = CreateDictionaryValue("{'robot':{'jump':{'parameters':{}}}}");
-  EXPECT_FALSE(dict.LoadCommands(*json, "robotd", nullptr, &error));
-  EXPECT_EQ("parameter_missing", error->GetCode());
-  EXPECT_EQ("Command definition 'robot.jump' is missing property 'results'",
-            error->GetMessage());
-  error.reset();
-
   // Command definition is not an object.
-  json = CreateDictionaryValue("{'robot':{'jump':0}}");
+  auto json = CreateDictionaryValue("{'robot':{'jump':0}}");
   EXPECT_FALSE(dict.LoadCommands(*json, "robotd", nullptr, &error));
   EXPECT_EQ("type_mismatch", error->GetCode());
   EXPECT_EQ("Expecting an object for command 'jump'", error->GetMessage());
@@ -111,8 +92,7 @@
   // Redefine commands in different category.
   buffet::CommandDictionary dict;
   chromeos::ErrorPtr error;
-  auto json = CreateDictionaryValue(
-      "{'robot':{'jump':{'parameters':{},'results':{}}}}");
+  auto json = CreateDictionaryValue("{'robot':{'jump':{}}}");
   dict.LoadCommands(*json, "category1", nullptr, &error);
   ASSERT_DEATH(dict.LoadCommands(*json, "category2", nullptr, &error),
                ".*Definition for command 'robot.jump' overrides an "
diff --git a/buffet/etc/buffet/commands/test.json b/buffet/etc/buffet/commands/test.json
index 4d11f82..182192f 100644
--- a/buffet/etc/buffet/commands/test.json
+++ b/buffet/etc/buffet/commands/test.json
@@ -3,8 +3,6 @@
     "_jump": {
       "parameters": {
         "_height":"integer"
-      },
-      "results": {
       }
     }
   }