Skip to content

Commit

Permalink
private/model/api: Fix API doc being generated with wrong value (#359)
Browse files Browse the repository at this point in the history
Fixes the SDK's generated API documentation for structure member being
generated with the wrong documentation value when the member was
included multiple times in the model doc-2.json file, but under
different types.

The SDK was not considering the member's type when associating documentation
with the member. Only parent struct name and member names was being
used.

V2 Port of aws/aws-sdk-go#2748
  • Loading branch information
jasdel authored Aug 20, 2019
1 parent 8d7fdba commit 321443f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
### SDK Enhancements

### SDK Bugs
* `private/model/api`: Fix API doc being generated with wrong value ([#359](https://github.com/aws/aws-sdk-go-v2/pull/359))
* Fixes the SDK's generated API documentation for structure member being generated with the wrong documentation value when the member was included multiple times in the model doc-2.json file, but under different types.
* V2 port of to v1 [aws/aws-sdk-go#2748](https://github.com/aws/aws-sdk-go/issues/2748)
* `aws/ec2rolecreds`: Fix security creds path to include trailing slash ([#356](https://github.com/aws/aws-sdk-go-v2/pull/356))
* Fixes the iamSecurityCredsPath var to include a trailing slash preventing redirects when making requests to the EC2 Instance Metadata service.
* Fixes [#351](https://github.com/aws/aws-sdk-go-v2/issues/351)
32 changes: 16 additions & 16 deletions private/model/api/docstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
)

type apiDocumentation struct {
*API
Operations map[string]string
Service string
Shapes map[string]shapeDocumentation
Expand All @@ -30,7 +29,7 @@ type shapeDocumentation struct {

// AttachDocs attaches documentation from a JSON filename.
func (a *API) AttachDocs(filename string) {
d := apiDocumentation{API: a}
var d apiDocumentation

f, err := os.Open(filename)
defer f.Close()
Expand All @@ -42,39 +41,40 @@ func (a *API) AttachDocs(filename string) {
panic(err)
}

d.setup()

d.setup(a)
}

func (d *apiDocumentation) setup() {
d.API.Documentation = docstring(d.Service)
func (d *apiDocumentation) setup(a *API) {
a.Documentation = docstring(d.Service)

for opName, doc := range d.Operations {
if _, ok := d.API.Operations[opName]; !ok {
if _, ok := a.Operations[opName]; !ok {
panic(fmt.Sprintf("%s, doc op %q not found in API op set",
d.API.ServiceID(), opName),
a.ServiceID(), opName),
)
}
d.API.Operations[opName].Documentation = docstring(doc)
a.Operations[opName].Documentation = docstring(doc)
}

for shape, info := range d.Shapes {
if sh := d.API.Shapes[shape]; sh != nil {
sh.Documentation = docstring(info.Base)
for shapeName, docShape := range d.Shapes {
if s, ok := a.Shapes[shapeName]; ok {
s.Documentation = docstring(docShape.Base)
}

for ref, doc := range info.Refs {
for ref, doc := range docShape.Refs {
if doc == "" {
continue
}

parts := strings.Split(ref, "$")
if len(parts) != 2 {
fmt.Fprintf(os.Stderr, "Shape Doc %s has unexpected reference format, %q\n", shape, ref)
fmt.Fprintf(os.Stderr,
"Shape Doc %s has unexpected reference format, %q\n",
shapeName, ref)
continue
}
if sh := d.API.Shapes[parts[0]]; sh != nil {
if m := sh.MemberRefs[parts[1]]; m != nil {
if s, ok := a.Shapes[parts[0]]; ok && len(s.MemberRefs) != 0 {
if m, ok := s.MemberRefs[parts[1]]; ok && m.ShapeName == shapeName {
m.Documentation = docstring(doc)
}
}
Expand Down
2 changes: 1 addition & 1 deletion service/kafka/api_op_CreateCluster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 321443f

Please sign in to comment.