Sort JsonSchemas output
This will show the sorted schema names for `/redfish/v1/JsonSchemas` so
that reading or checking of JsonSchemas content is easier (e.g. Redfish
Service Validator report).
Tested:
- GET /redfish/v1/JsonSchemas and check the output as sorted
Change-Id: Ica0a8fd513e117a8bd4a533c58cffa0d1090e18c
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/redfish-core/lib/redfish_v1.hpp b/redfish-core/lib/redfish_v1.hpp
index de205f0..e9dd422 100644
--- a/redfish-core/lib/redfish_v1.hpp
+++ b/redfish-core/lib/redfish_v1.hpp
@@ -11,6 +11,7 @@
#include "query.hpp"
#include "registries/privilege_registry.hpp"
#include "str_utility.hpp"
+#include "utils/json_utils.hpp"
#include <boost/beast/http/field.hpp>
#include <boost/beast/http/status.hpp>
@@ -99,7 +100,6 @@
json["@odata.type"] = "#JsonSchemaFileCollection.JsonSchemaFileCollection";
json["Name"] = "JsonSchemaFile Collection";
json["Description"] = "Collection of JsonSchemaFiles";
- nlohmann::json::array_t members;
std::error_code ec;
std::filesystem::directory_iterator dirList(
@@ -109,6 +109,8 @@
messages::internalError(asyncResp->res);
return;
}
+
+ std::vector<std::string> schemaNames;
for (const std::filesystem::path& file : dirList)
{
std::string filename = file.filename();
@@ -118,12 +120,18 @@
{
continue;
}
+ schemaNames.emplace_back(split[0]);
+ }
+ std::ranges::sort(schemaNames, AlphanumLess<std::string>());
+
+ nlohmann::json::array_t members;
+ for (const std::string& schema : schemaNames)
+ {
nlohmann::json::object_t member;
member["@odata.id"] =
- boost::urls::format("/redfish/v1/JsonSchemas/{}", split[0]);
+ boost::urls::format("/redfish/v1/JsonSchemas/{}", schema);
members.emplace_back(std::move(member));
}
-
json["Members@odata.count"] = members.size();
json["Members"] = std::move(members);
}