From d374e8a6ca88b23d7ab70e5c71510890209fed27 Mon Sep 17 00:00:00 2001 From: fossand Date: Fri, 6 Jan 2023 11:07:44 -0800 Subject: [PATCH] Fix Upgrade1to2Command for Set shape --- .../smithy/cli/commands/Upgrade1to2Command.java | 15 +++++++++++++++ .../cli/commands/upgrade/cases/box.v2.smithy | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/Upgrade1to2Command.java b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/Upgrade1to2Command.java index 2a03c4764f4..7d401d76d6f 100644 --- a/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/Upgrade1to2Command.java +++ b/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/Upgrade1to2Command.java @@ -45,7 +45,9 @@ import software.amazon.smithy.model.SourceLocation; import software.amazon.smithy.model.loader.ModelAssembler; import software.amazon.smithy.model.loader.Prelude; +import software.amazon.smithy.model.shapes.ListShape; import software.amazon.smithy.model.shapes.MemberShape; +import software.amazon.smithy.model.shapes.SetShape; import software.amazon.smithy.model.shapes.Shape; import software.amazon.smithy.model.shapes.ShapeType; import software.amazon.smithy.model.shapes.ShapeVisitor; @@ -321,6 +323,19 @@ public Void stringShape(StringShape shape) { return null; } + @Override + public Void listShape(ListShape shape) { + getDefault(shape); + if (shape instanceof SetShape) { + int lineNumber = shape.getSourceLocation().getLine(); + writer.eraseLine(lineNumber); + writer.insertLine(lineNumber, "list " + shape.toShapeId().getName() + " {"); + writer.insertLine(lineNumber, "@uniqueItems"); + } + + return null; + } + private String serializeEnum(StringShape shape) { // Strip all the traits from the shape except the enum trait. // We're leaving the other traits where they are in the model diff --git a/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/box.v2.smithy b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/box.v2.smithy index 8633ec27dac..6e1f45cb48d 100644 --- a/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/box.v2.smithy +++ b/smithy-cli/src/test/resources/software/amazon/smithy/cli/commands/upgrade/cases/box.v2.smithy @@ -24,7 +24,8 @@ list BadSparseList { member: NonBoxedInteger, } -set BadSparseSet { +@uniqueItems +list BadSparseSet { member: NonBoxedInteger, }