Skip to content

Commit 439e554

Browse files
authored
private/model/api: Improve SDK API reference doc generation (#309)
Improves the SDK's generated documentation for API client, operation, and types. This fixes several bugs in the doc generation causing poor formatting, an difficult to read reference documentation. Fix #308 Related aws/aws-sdk-go#2617
1 parent e6b1343 commit 439e554

File tree

630 files changed

+7024
-7953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

630 files changed

+7024
-7953
lines changed

private/model/api/docstring.go

Lines changed: 366 additions & 233 deletions
Large diffs are not rendered by default.
Lines changed: 70 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,81 @@
1-
// +build 1.6,codegen
1+
// +build go1.8,codegen
22

33
package api
44

55
import (
66
"testing"
77
)
88

9-
func TestNonHTMLDocGen(t *testing.T) {
10-
doc := "Testing 1 2 3"
11-
expected := "// Testing 1 2 3\n"
12-
doc = docstring(doc)
13-
14-
if expected != doc {
15-
t.Errorf("Expected %s, but received %s", expected, doc)
16-
}
17-
}
18-
19-
func TestListsHTMLDocGen(t *testing.T) {
20-
doc := "<ul><li>Testing 1 2 3</li> <li>FooBar</li></ul>"
21-
expected := "// * Testing 1 2 3\n// * FooBar\n"
22-
doc = docstring(doc)
23-
24-
if expected != doc {
25-
t.Errorf("Expected %s, but received %s", expected, doc)
26-
}
27-
28-
doc = "<ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>"
29-
expected = "// * Testing 1 2 3\n// * FooBar\n"
30-
doc = docstring(doc)
31-
32-
if expected != doc {
33-
t.Errorf("Expected %s, but received %s", expected, doc)
34-
}
35-
36-
// Test leading spaces
37-
doc = " <ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>"
38-
doc = docstring(doc)
39-
if expected != doc {
40-
t.Errorf("Expected %s, but received %s", expected, doc)
41-
}
42-
43-
// Paragraph check
44-
doc = "<ul> <li> <p>Testing 1 2 3</p> </li><li> <p>FooBar</p></li></ul>"
45-
expected = "// * Testing 1 2 3\n// \n// * FooBar\n"
46-
doc = docstring(doc)
47-
if expected != doc {
48-
t.Errorf("Expected %s, but received %s", expected, doc)
49-
}
50-
}
51-
52-
func TestInlineCodeHTMLDocGen(t *testing.T) {
53-
doc := "<ul> <li><code>Testing</code>: 1 2 3</li> <li>FooBar</li> </ul>"
54-
expected := "// * Testing: 1 2 3\n// * FooBar\n"
55-
doc = docstring(doc)
56-
57-
if expected != doc {
58-
t.Errorf("Expected %s, but received %s", expected, doc)
59-
}
60-
}
61-
62-
func TestInlineCodeInParagraphHTMLDocGen(t *testing.T) {
63-
doc := "<p><code>Testing</code>: 1 2 3</p>"
64-
expected := "// Testing: 1 2 3\n"
65-
doc = docstring(doc)
66-
67-
if expected != doc {
68-
t.Errorf("Expected %s, but received %s", expected, doc)
9+
func TestDocstring(t *testing.T) {
10+
cases := map[string]struct {
11+
In string
12+
Expect string
13+
}{
14+
"non HTML": {
15+
In: "Testing 1 2 3",
16+
Expect: "// Testing 1 2 3",
17+
},
18+
"link": {
19+
In: `<a href="https://example.com">a link</a>`,
20+
Expect: "// a link (https://example.com)",
21+
},
22+
"link with space": {
23+
In: `<a href=" https://example.com">a link</a>`,
24+
Expect: "// a link (https://example.com)",
25+
},
26+
"list HTML 01": {
27+
In: "<ul><li>Testing 1 2 3</li> <li>FooBar</li></ul>",
28+
Expect: "// * Testing 1 2 3\n// \n// * FooBar",
29+
},
30+
"list HTML 02": {
31+
In: "<ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>",
32+
Expect: "// * Testing 1 2 3\n// \n// * FooBar",
33+
},
34+
"list HTML leading spaces": {
35+
In: " <ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>",
36+
Expect: "// * Testing 1 2 3\n// \n// * FooBar",
37+
},
38+
"list HTML paragraph": {
39+
In: "<ul> <li> <p>Testing 1 2 3</p> </li><li> <p>FooBar</p></li></ul>",
40+
Expect: "// * Testing 1 2 3\n// \n// * FooBar",
41+
},
42+
"inline code HTML": {
43+
In: "<ul> <li><code>Testing</code>: 1 2 3</li> <li>FooBar</li> </ul>",
44+
Expect: "// * Testing: 1 2 3\n// \n// * FooBar",
45+
},
46+
"complex list paragraph": {
47+
In: "<ul> <li><p><code>FOO</code> Bar</p></li><li><p><code>Xyz</code> ABC</p></li></ul>",
48+
Expect: "// * FOO Bar\n// \n// * Xyz ABC",
49+
},
50+
"inline code in paragraph": {
51+
In: "<p><code>Testing</code>: 1 2 3</p>",
52+
Expect: "// Testing: 1 2 3",
53+
},
54+
"root pre": {
55+
In: "<pre><code>Testing</code></pre>",
56+
Expect: "// Testing",
57+
},
58+
"paragraph": {
59+
In: "<p>Testing 1 2 3</p>",
60+
Expect: "// Testing 1 2 3",
61+
},
62+
"wrap lines": {
63+
In: "<span data-target-type=\"operation\" data-service=\"secretsmanager\" data-target=\"CreateSecret\">CreateSecret</span> <span data-target-type=\"structure\" data-service=\"secretsmanager\" data-target=\"SecretListEntry\">SecretListEntry</span> <span data-target-type=\"structure\" data-service=\"secretsmanager\" data-target=\"CreateSecret$SecretName\">SecretName</span> <span data-target-type=\"structure\" data-service=\"secretsmanager\" data-target=\"SecretListEntry$KmsKeyId\">KmsKeyId</span>",
64+
Expect: "// CreateSecret SecretListEntry SecretName KmsKeyId",
65+
},
66+
"links with spaces": {
67+
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>",
68+
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.",
69+
},
6970
}
70-
}
71-
72-
func TestEmptyPREInlineCodeHTMLDocGen(t *testing.T) {
73-
doc := "<pre><code>Testing</code></pre>"
74-
expected := "// Testing\n"
75-
doc = docstring(doc)
76-
77-
if expected != doc {
78-
t.Errorf("Expected %s, but received %s", expected, doc)
79-
}
80-
}
81-
82-
func TestParagraph(t *testing.T) {
83-
doc := "<p>Testing 1 2 3</p>"
84-
expected := "// Testing 1 2 3\n"
85-
doc = docstring(doc)
86-
87-
if expected != doc {
88-
t.Errorf("Expected %s, but received %s", expected, doc)
89-
}
90-
}
91-
92-
func TestComplexListParagraphCode(t *testing.T) {
93-
doc := "<ul> <li><p><code>FOO</code> Bar</p></li><li><p><code>Xyz</code> ABC</p></li></ul>"
94-
expected := "// * FOO Bar\n// \n// * Xyz ABC\n"
95-
doc = docstring(doc)
9671

97-
if expected != doc {
98-
t.Errorf("Expected %s, but received %s", expected, doc)
72+
for name, c := range cases {
73+
t.Run(name, func(t *testing.T) {
74+
t.Log("Input", c.In)
75+
actual := docstring(c.In)
76+
if e, a := c.Expect, actual; e != a {
77+
t.Errorf("expect %q, got %q", e, a)
78+
}
79+
})
9980
}
10081
}

private/model/api/example.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ var exampleCustomizations = map[string]template.FuncMap{}
5454

5555
var exampleTmpls = template.Must(template.New("example").Funcs(exampleFuncMap).Parse(`
5656
{{ generateTypes . }}
57-
{{ commentify (wrap .Title 80 false) }}
57+
{{ commentify (wrap .Title 80) }}
5858
//
59-
{{ commentify (wrap .Description 80 false) }}
59+
{{ commentify (wrap .Description 80) }}
6060
func Example{{ .API.StructName }}_{{ .MethodName }}() {
6161
cfg, err := external.LoadDefaultAWSConfig()
6262
if err != nil {

service/acm/api_op_UpdateCertificateOptions.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/acmpca/api_op_CreateCertificateAuthority.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/acmpca/api_op_CreateCertificateAuthorityAuditReport.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/acmpca/api_op_CreatePermission.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/acmpca/api_op_DeleteCertificateAuthority.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/acmpca/api_op_DeletePermission.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/acmpca/api_op_DescribeCertificateAuthority.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)