Skip to content

Commit

Permalink
Fix multiline doc comment parsing on members
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JordonPhillips committed Jul 15, 2020
1 parent 56cf7c1 commit 2b03004
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ private String parseDocCommentLine() {
int start = position();
consumeRemainingCharactersOnLine();
br();
sp();
return StringUtils.stripEnd(sliceFrom(start), " \t\r\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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."));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace smithy.example

structure MyStruct {
/// This is the first line.
/// This is the second line.
myMember: String
}

0 comments on commit 2b03004

Please sign in to comment.