From 2b03004e45915f2deec7924dc983bcc304225189 Mon Sep 17 00:00:00 2001 From: JordonPhillips Date: Tue, 14 Jul 2020 17:17:50 -0700 Subject: [PATCH] Fix multiline doc comment parsing on members This fixes an issue where multiline doc comments would not work on members due to the parser only consuming to the end of the current line and then checking for the forward slashes. Since there will usually be indentation here for members, the parsing ended too early. --- CHANGELOG.md | 4 +++- .../smithy/model/loader/IdlModelParser.java | 1 + .../smithy/model/loader/IdlModelLoaderTest.java | 15 +++++++++++++++ .../smithy/model/loader/multiline-comments.smithy | 7 +++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 smithy-model/src/test/resources/software/amazon/smithy/model/loader/multiline-comments.smithy diff --git a/CHANGELOG.md b/CHANGELOG.md index bc3ae3f6b8b..a8efaaa52b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ ### Bug Fixes * Fixed a bug where `passthroughBehavior` was misspelled as `passThroughBehavior` - in APIGateway OpenAPI output for integrations and mock integrations. + in APIGateway OpenAPI output for integrations and mock integrations. ([#495](https://github.com/awslabs/smithy/pull/495)) +* Fixed a bug where only the last line in a multiline doc comment on a + member would be successfully parsed. ([#498](https://github.com/awslabs/smithy/pull/498)) ## 1.0.6 (2020-06-24) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelParser.java b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelParser.java index 97ff5f8cdd5..495111f3972 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelParser.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/loader/IdlModelParser.java @@ -658,6 +658,7 @@ private String parseDocCommentLine() { int start = position(); consumeRemainingCharactersOnLine(); br(); + sp(); return StringUtils.stripEnd(sliceFrom(start), " \t\r\n"); } diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlModelLoaderTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlModelLoaderTest.java index 9d187bbfd61..89580e6dbc9 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlModelLoaderTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/loader/IdlModelLoaderTest.java @@ -29,6 +29,8 @@ import software.amazon.smithy.model.shapes.ResourceShape; import software.amazon.smithy.model.shapes.Shape; import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.traits.DocumentationTrait; +import software.amazon.smithy.model.traits.StringTrait; import software.amazon.smithy.model.validation.ValidatedResultException; public class IdlModelLoaderTest { @@ -116,4 +118,17 @@ public void limitsRecursion() { assertThat(e.getMessage(), containsString("Parser exceeded the maximum allowed depth of")); } + + @Test + public void handlesMultilineDocComments() { + Model model = Model.assembler() + .addImport(getClass().getResource("multiline-comments.smithy")) + .assemble() + .unwrap(); + + Shape shape = model.expectShape(ShapeId.from("smithy.example#MyStruct$myMember")); + String docs = shape.getTrait(DocumentationTrait.class).map(StringTrait::getValue).orElse(""); + + assertThat(docs, equalTo("This is the first line.\nThis is the second line.")); + } } diff --git a/smithy-model/src/test/resources/software/amazon/smithy/model/loader/multiline-comments.smithy b/smithy-model/src/test/resources/software/amazon/smithy/model/loader/multiline-comments.smithy new file mode 100644 index 00000000000..a68d8574e62 --- /dev/null +++ b/smithy-model/src/test/resources/software/amazon/smithy/model/loader/multiline-comments.smithy @@ -0,0 +1,7 @@ +namespace smithy.example + +structure MyStruct { + /// This is the first line. + /// This is the second line. + myMember: String +}