| 1008 | |
| 1009 | |
| 1010 | Json Assets::checkPatchArray(String const& path, AssetSourcePtr const& source, Json const result, JsonArray const patchData, Maybe<Json> const external) const { |
| 1011 | auto externalRef = external.value(); |
| 1012 | auto newResult = result; |
| 1013 | for (auto const& patch : patchData) { |
| 1014 | switch(patch.type()) { |
| 1015 | case Json::Type::Array: // if the patch is an array, go down recursively until we get objects |
| 1016 | try { |
| 1017 | newResult = checkPatchArray(path, source, newResult, patch.toArray(), externalRef); |
| 1018 | } catch (JsonPatchTestFail const& e) { |
| 1019 | Logger::debug("Patch test failure from file {} in source: '{}' at '{}'. Caused by: {}", path, source->metadata().value("name", ""), m_assetSourcePaths.getLeft(source), e.what()); |
| 1020 | } catch (JsonPatchException const& e) { |
| 1021 | Logger::error("Could not apply patch from file {} in source: '{}' at '{}'. Caused by: {}", path, source->metadata().value("name", ""), m_assetSourcePaths.getLeft(source), e.what()); |
| 1022 | } |
| 1023 | break; |
| 1024 | case Json::Type::Object: // if its an object, check for operations, or for if an external file is needed for patches to reference |
| 1025 | newResult = JsonPatching::applyOperation(newResult, patch, externalRef); |
| 1026 | break; |
| 1027 | case Json::Type::String: |
| 1028 | try { |
| 1029 | externalRef = json(patch.toString()); |
| 1030 | } catch (...) { |
| 1031 | throw JsonPatchTestFail(strf("Unable to load reference asset: {}", patch.toString())); |
| 1032 | } |
| 1033 | break; |
| 1034 | default: |
| 1035 | throw JsonPatchException(strf("Patch data is wrong type: {}", Json::typeName(patch.type()))); |
| 1036 | break; |
| 1037 | } |
| 1038 | } |
| 1039 | return newResult; |
| 1040 | } |
| 1041 | |
| 1042 | Json Assets::readJson(String const& path) const { |
| 1043 | ByteArray streamData = read(path); |