Add versioning to RAS data schemas

Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: Ie1688f748fe70d40bee4c88160cb20b7d36d3033
diff --git a/analyzer/ras-data/meson.build b/analyzer/ras-data/meson.build
index 73198de..051892a 100644
--- a/analyzer/ras-data/meson.build
+++ b/analyzer/ras-data/meson.build
@@ -12,7 +12,7 @@
 
 # Install the RAS data schema
 
-ras_data_schema = files( 'schema/ras-data-schema.json' )
+ras_data_schema = files( 'schema/ras-data-schema-v01.json' )
 
 install_data( ras_data_schema, install_dir: join_paths(package_dir, 'schema') )
 
diff --git a/analyzer/ras-data/ras-data-parser.cpp b/analyzer/ras-data/ras-data-parser.cpp
index 48b0428..d1315dc 100644
--- a/analyzer/ras-data/ras-data-parser.cpp
+++ b/analyzer/ras-data/ras-data-parser.cpp
@@ -29,22 +29,33 @@
 
     // Get the RAS data schema files from the package `schema` subdirectory.
     fs::path schemaDir{PACKAGE_DIR "schema"};
-    auto schemaRegex = R"(ras-data-schema\.json)";
-    std::vector<fs::path> schmemaPaths;
-    util::findFiles(schemaDir, schemaRegex, schmemaPaths);
-    assert(1 == schmemaPaths.size()); // Should be one, and only one, file.
+    auto schemaRegex = R"(ras-data-schema-v[0-9]{2}\.json)";
+    std::vector<fs::path> schemaPaths;
+    util::findFiles(schemaDir, schemaRegex, schemaPaths);
 
-    // Trace the file for debug.
-    trace::inf("File found: path=%s", schmemaPaths.front().string().c_str());
+    // Parse each of the schema files.
+    std::map<unsigned int, nlohmann::json> schemaFiles;
+    for (const auto& path : schemaPaths)
+    {
+        // Trace each data file for debug.
+        trace::inf("File found: path=%s", path.string().c_str());
 
-    // Open the file.
-    std::ifstream schemaFile{schmemaPaths.front()};
-    assert(schemaFile.good()); // The file must be readable.
+        // Open the file.
+        std::ifstream file{path};
+        assert(file.good()); // The file must be readable.
 
-    // Parse the JSON.
-    auto schema = nlohmann::json::parse(schemaFile);
+        // Parse the JSON.
+        auto schema = nlohmann::json::parse(file);
 
-    // Get the RAS data files from the package `ras-data` subdirectory.
+        // Get the schema version.
+        auto version = schema.at("version").get<unsigned int>();
+
+        // Keep track of the schemas.
+        auto ret = schemaFiles.emplace(version, schema);
+        assert(ret.second); // Should not have duplicate entries
+    }
+
+    // Get the RAS data files from the package `data` subdirectory.
     fs::path dataDir{PACKAGE_DIR "ras-data"};
     std::vector<fs::path> dataPaths;
     util::findFiles(dataDir, R"(.*\.json)", dataPaths);
@@ -62,6 +73,12 @@
         // Parse the JSON.
         const auto data = nlohmann::json::parse(file);
 
+        // Get the data version.
+        auto version = data.at("version").get<unsigned int>();
+
+        // Get the schema for this file.
+        auto schema = schemaFiles.at(version);
+
         // Validate the data against the schema.
         assert(util::validateJson(schema, data));
 
diff --git a/analyzer/ras-data/schema/ras-data-schema.json b/analyzer/ras-data/schema/ras-data-schema-v01.json
similarity index 99%
rename from analyzer/ras-data/schema/ras-data-schema.json
rename to analyzer/ras-data/schema/ras-data-schema-v01.json
index 3016f06..05f18cc 100644
--- a/analyzer/ras-data/schema/ras-data-schema.json
+++ b/analyzer/ras-data/schema/ras-data-schema-v01.json
@@ -1,6 +1,7 @@
 {
     "$schema": "https://json-schema.org/draft/2020-12/schema",
     "title": "RAS Data schema for openpower-hw-diags",
+    "version": 1,
     "type": "object",
     "definitions": {
         "priority": {