Unify resource mapping json schema across cpp and python usage (#5799)

* Unify resource mapping json schema across cpp and python usage

Signed-off-by: onecent1101 <liug@amazon.com>

* Update based on feedback

Signed-off-by: onecent1101 <liug@amazon.com>

* Add empty line at end of file

Signed-off-by: onecent1101 <liug@amazon.com>
This commit is contained in:
Vincent Liu
2021-11-23 12:06:39 -08:00
committed by GitHub
parent d614857da3
commit 423e2e8da8
11 changed files with 260 additions and 91 deletions
@@ -12,6 +12,7 @@
#include <AzCore/Serialization/Json/JsonUtils.h>
#include <AzCore/Settings/SettingsRegistry.h>
#include <AzCore/Settings/SettingsRegistryImpl.h>
#include <AzCore/Utils/Utils.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AWSCoreInternalBus.h>
@@ -244,14 +245,16 @@ namespace AWSCore
bool AWSResourceMappingManager::ValidateJsonDocumentAgainstSchema(const rapidjson::Document& jsonDocument)
{
rapidjson::Document jsonSchemaDocument;
if (jsonSchemaDocument.Parse(ResourceMappingJsonSchema).HasParseError())
AZ::IO::Path executablePath = AZ::IO::PathView(AZ::Utils::GetExecutableDirectory());
AZ::IO::Path jsonSchemaPath = (executablePath / ResourceMapppingJsonSchemaFilePath).LexicallyNormal();
AZ::Outcome<rapidjson::Document, AZStd::string> readJsonOutcome = AZ::JsonSerializationUtils::ReadJsonFile(jsonSchemaPath.c_str());
if (!readJsonOutcome.IsSuccess() || readJsonOutcome.TakeValue().ObjectEmpty())
{
AZ_Error(AWSResourceMappingManagerName, false, ResourceMappingFileInvalidSchemaErrorMessage);
return false;
}
auto jsonSchema = rapidjson::SchemaDocument(jsonSchemaDocument);
auto jsonSchema = rapidjson::SchemaDocument(readJsonOutcome.TakeValue());
rapidjson::SchemaValidator validator(jsonSchema);
if (!jsonDocument.Accept(validator))