Skip to content

Commit

Permalink
Add a test case to reproduce an issue with default value sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
adamthom-amzn committed Oct 21, 2022
1 parent c45d5db commit 3259269
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opentest4j.AssertionFailedError;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.SourceLocation;
import software.amazon.smithy.model.node.Node;
Expand Down Expand Up @@ -1136,4 +1137,23 @@ public void versionTransformsAreAlwaysApplied() {
assertThat(fooBam.getAllTraits(), hasKey(BoxTrait.ID));
assertThat(fooBam.expectTrait(DefaultTrait.class).toNode(), equalTo(Node.nullNode()));
}

@Test
public void defaultValueSugaringDoesNotEatSubsequentDocumentation() {
ValidatedResult<Model> result = new ModelAssembler()
.addImport(getClass().getResource("missing-documentation.smithy"))
.assemble();

assertThat(result.getValidationEvents(), empty());

StructureShape testShape =
result.unwrap().expectShape(ShapeId.from("software.amazon.smithy.test#TestShape"),
StructureShape.class);

MemberShape documentedString = testShape.getMember("bar")
.orElseThrow(AssertionFailedError::new);

assertEquals("bar", documentedString.expectTrait(DocumentationTrait.class).getValue());
assertEquals(2, documentedString.getAllTraits().size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$version: "2.0"

namespace software.amazon.smithy.test

structure TestShape {
/// foo
@required
foo: Boolean = false
/// bar
@required
bar: TestString
}

string TestString

0 comments on commit 3259269

Please sign in to comment.