entity-manager: Make schema validation on addObject optional
Puts schema validation behind the compile switch for
schema validation within the AddObject dbus API. Schema
validation is currently completely broken, and entity-manager
fails to start with it enabled. We shouldn't require a dbus
api to rely on a broken feature.
Tested: loading this onto nvl32-obmc model and running busctl
```
root@nvl32-bmc:~# busctl call xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/Nvidia_GPU_13 xyz.openbmc_project.AddObject AddObject a{sv} 3 Name s GPU_0 Type s NvidiaMctpVdm PollRate u 1000
root@nvl32-bmc:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/Nvidia_GPU_13/GPU_0
NAME                                            TYPE      SIGNATURE RESULT/VALUE    FLAGS
org.freedesktop.DBus.Introspectable             interface -         -               -
.Introspect                                     method    -         s               -
org.freedesktop.DBus.Peer                       interface -         -               -
.GetMachineId                                   method    -         s               -
.Ping                                           method    -         -               -
org.freedesktop.DBus.Properties                 interface -         -               -
.Get                                            method    ss        v               -
.GetAll                                         method    s         a{sv}           -
.Set                                            method    ssv       -               -
.PropertiesChanged                              signal    sa{sv}as  -               -
xyz.openbmc_project.Configuration.NvidiaMctpVdm interface -         -               -
.Delete                                         method    -         -               -
.Name                                           property  s         "GPU_0"         emits-change
.PollRate                                       property  d         1000            emits-change
.Type                                           property  s         "NvidiaMctpVdm" emits-change
```
Change-Id: Iacbb683b2d9cb7fb762082a9c2f48355236f846c
Signed-off-by: Marc Olberding <molberding@nvidia.com>
diff --git a/src/entity_manager/dbus_interface.cpp b/src/entity_manager/dbus_interface.cpp
index b6fbc01..9c93ec6 100644
--- a/src/entity_manager/dbus_interface.cpp
+++ b/src/entity_manager/dbus_interface.cpp
@@ -311,27 +311,33 @@
                 lastIndex++;
             }
 
-            std::ifstream schemaFile(std::string(schemaDirectory) + "/" +
-                                     boost::to_lower_copy(*type) + ".json");
-            // todo(james) we might want to also make a list of 'can add'
-            // interfaces but for now I think the assumption if there is a
-            // schema avaliable that it is allowed to update is fine
-            if (!schemaFile.good())
+            if constexpr (ENABLE_RUNTIME_VALIDATE_JSON)
             {
-                throw std::invalid_argument(
-                    "No schema avaliable, cannot validate.");
+                const std::filesystem::path schemaPath =
+                    std::filesystem::path(schemaDirectory) /
+                    "exposes_record.json";
+
+                std::ifstream schemaFile{schemaPath};
+
+                if (!schemaFile.good())
+                {
+                    throw std::invalid_argument(
+                        "No schema avaliable, cannot validate.");
+                }
+                nlohmann::json schema =
+                    nlohmann::json::parse(schemaFile, nullptr, false, true);
+                if (schema.is_discarded())
+                {
+                    std::cerr << "Schema not legal" << *type << ".json\n";
+                    throw DBusInternalError();
+                }
+
+                if (!validateJson(schema, newData))
+                {
+                    throw std::invalid_argument("Data does not match schema");
+                }
             }
-            nlohmann::json schema =
-                nlohmann::json::parse(schemaFile, nullptr, false, true);
-            if (schema.is_discarded())
-            {
-                std::cerr << "Schema not legal" << *type << ".json\n";
-                throw DBusInternalError();
-            }
-            if (!validateJson(schema, newData))
-            {
-                throw std::invalid_argument("Data does not match schema");
-            }
+
             if (foundNull)
             {
                 findExposes->at(lastIndex) = newData;