diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelAssembler.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelAssembler.java index df139bffd31..54f1d18b490 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelAssembler.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/ModelAssembler.java @@ -29,6 +29,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -93,7 +94,7 @@ public final class ModelAssembler { private TraitFactory traitFactory; private ValidatorFactory validatorFactory; private boolean disableValidation; - private final Map> inputStreamModels = new HashMap<>(); + private final Map> inputStreamModels = new LinkedHashMap<>(); private final List validators = new ArrayList<>(); private final List documentNodes = new ArrayList<>(); private final List mergeModels = new ArrayList<>(); diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelAssemblerTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelAssemblerTest.java index cc0ab3f0ae8..fa24b0baa82 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelAssemblerTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/ModelAssemblerTest.java @@ -47,6 +47,8 @@ import java.util.Map; import java.util.Optional; import java.util.function.Supplier; +import java.util.stream.Collectors; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; @@ -391,6 +393,26 @@ public void detectsMetadataConflicts() { containsString("Metadata conflict for key `foo`")); } + @Test + public void metadataIsNotAffectedByTheSourceName() { + Model model1 = new ModelAssembler() + .addUnparsedModel("a1.smithy", "metadata items = [1]") + .addUnparsedModel("a2.smithy", "metadata items = [2]") + .addUnparsedModel("a3.smithy", "metadata items = [3]") + .assemble() + .unwrap(); + Model model2 = new ModelAssembler() + .addUnparsedModel("b1.smithy", "metadata items = [1]") + .addUnparsedModel("b2.smithy", "metadata items = [2]") + .addUnparsedModel("b3.smithy", "metadata items = [3]") + .assemble() + .unwrap(); + List metadata1 = model1.getMetadata().get("items").expectArrayNode().getElements().stream().map(s -> s.expectNumberNode().getValue()).collect(Collectors.toList()); + List metadata2 = model2.getMetadata().get("items").expectArrayNode().getElements().stream().map(s -> s.expectNumberNode().getValue()).collect(Collectors.toList()); + assertThat(metadata1, is(metadata2)); + } + + @Test public void mergesMultipleModels() { Model model = new ModelAssembler()