diff --git a/src/Manifest/ManifestManager/Options/OutTable/Serializer/LegacyManifestNormalizer.php b/src/Manifest/ManifestManager/Options/OutTable/Serializer/LegacyManifestNormalizer.php index d04cd53..f52b85e 100644 --- a/src/Manifest/ManifestManager/Options/OutTable/Serializer/LegacyManifestNormalizer.php +++ b/src/Manifest/ManifestManager/Options/OutTable/Serializer/LegacyManifestNormalizer.php @@ -72,6 +72,7 @@ private function normalizeSchema(ManifestOptions $object, array &$data): void $this->normalizeDataTypes($schema, $columnMetadata); $this->normalizeColumnMetadata($schema, $columnMetadata); + $this->deduplicateMetadata($columnMetadata); if (!empty($columnMetadata)) { $data['column_metadata'][$schema->getName()] = $columnMetadata; @@ -248,4 +249,23 @@ public function supportsDenormalization($data, $type, $format = null): bool { return $type === ManifestOptions::class; } + + private function deduplicateMetadata(array &$columnMetadata): void + { + $columnMetadata = array_values(array_reduce( + $columnMetadata, + /** + * @param array> $carry + * @param array $item + * @return array> + */ + function (array $carry, array $item): array { + if (isset($item['key']) && !isset($carry[$item['key']])) { + $carry[$item['key']] = $item; + } + return $carry; + }, + [], + )); + } } diff --git a/tests/Manifest/ManifestManagerTest.php b/tests/Manifest/ManifestManagerTest.php index 8e88bb9..37cdd56 100644 --- a/tests/Manifest/ManifestManagerTest.php +++ b/tests/Manifest/ManifestManagerTest.php @@ -361,6 +361,10 @@ public function provideWriteManifestOptions(): array 'key' => 'yet.another.key', 'value' => 'Some other value', ], + [ + 'key' => 'yet.another.key', //duplicated key should be removed + 'value' => 'Some other value', + ], ], ]) ->setDestination('my.table')