From 3391341d8322975abc89a13248f4fb55e89de883 Mon Sep 17 00:00:00 2001 From: mvilla Date: Tue, 4 Apr 2023 15:58:41 +0100 Subject: [PATCH 1/3] Add failing test --- .../model/loader/ModelAssemblerTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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..ea323451c5b 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 @@ -391,6 +391,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()).toList(); + List metadata2 = model2.getMetadata().get("items").expectArrayNode().getElements().stream().map(s -> s.expectNumberNode().getValue()).toList(); + assertThat(metadata1, is(metadata2)); + } + + @Test public void mergesMultipleModels() { Model model = new ModelAssembler() From 69e3b6e5200f2a5b168e690f105eb3dc85d79638 Mon Sep 17 00:00:00 2001 From: Miguel Vila Date: Tue, 4 Apr 2023 16:50:04 +0100 Subject: [PATCH 2/3] Use LinkedHasMap in ModelAssembler in order to iterate over files consistently --- .../software/amazon/smithy/model/loader/ModelAssembler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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<>(); From 2017669ade36dce7795eedcbbbdc5eff2c05959e Mon Sep 17 00:00:00 2001 From: Miguel Vila Date: Tue, 4 Apr 2023 19:57:06 +0100 Subject: [PATCH 3/3] use collect method instead to support java 8 --- .../amazon/smithy/model/loader/ModelAssemblerTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 ea323451c5b..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; @@ -405,8 +407,8 @@ public void metadataIsNotAffectedByTheSourceName() { .addUnparsedModel("b3.smithy", "metadata items = [3]") .assemble() .unwrap(); - List metadata1 = model1.getMetadata().get("items").expectArrayNode().getElements().stream().map(s -> s.expectNumberNode().getValue()).toList(); - List metadata2 = model2.getMetadata().get("items").expectArrayNode().getElements().stream().map(s -> s.expectNumberNode().getValue()).toList(); + 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)); }