Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegen: Fix SDK codegen handling of poorly formatted API docs #4512

Merged
merged 1 commit into from Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion private/model/api/docstring.go
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"html"
"io"
"log"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -320,10 +321,14 @@ func (e *htmlTokenEncoder) Encode(token xhtml.Token) error {
h.handler.OnEndTagToken(token, handlerBlockClosing)

// Remove all but the root handler as the handler is no longer needed.
if handlerBlockClosing {
if handlerBlockClosing && len(e.handlers) != 0 {
e.handlers = e.handlers[:len(e.handlers)-1]
}
e.depth--
if e.depth < 0 {
log.Printf("ignoring unexpected closing tag, %v", token)
e.depth = 0
}

case xhtml.SelfClosingTagToken:
h.handler.OnSelfClosingTagToken(token)
Expand Down
5 changes: 4 additions & 1 deletion private/model/api/docstring_test.go
Expand Up @@ -68,11 +68,14 @@ func TestDocstring(t *testing.T) {
In: "<p> Deletes the replication configuration from the bucket. For information about replication configuration, see <a href=\" https://docs.aws.amazon.com/AmazonS3/latest/dev/crr.html\">Cross-Region Replication (CRR)</a> in the <i>Amazon S3 Developer Guide</i>. </p>",
Expect: "// Deletes the replication configuration from the bucket. For information about\n// replication configuration, see Cross-Region Replication (CRR) (https://docs.aws.amazon.com/AmazonS3/latest/dev/crr.html)\n// in the Amazon S3 Developer Guide.",
},
"unexpected closing tag": {
In: "<p>Some cool text</p></p>",
Expect: "// Some cool text",
},
}

for name, c := range cases {
t.Run(name, func(t *testing.T) {
t.Log("Input", c.In)
actual := docstring(c.In)
if e, a := c.Expect, actual; e != a {
t.Errorf("expect %q, got %q", e, a)
Expand Down