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: Ensure API structs don't collide with API client type name #3651

Merged
merged 1 commit into from
Nov 24, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions private/model/api/passes.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ func (a *API) renameExportable() {
}

newName := a.ExportableName(k)
if s.Type == "structure" && newName == a.StructName() {
// If struct collides client's struct type name the shape needs to
// be renamed with a trailing `_` to prevent collision.
newName += "_"
}

if newName != s.ShapeName {
s.Rename(newName)
}
Expand Down
36 changes: 36 additions & 0 deletions private/model/api/passes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,42 @@ func TestCreateInputOutputShapes(t *testing.T) {
"FirstOpInput", "FirstOpOutput",
},
},
"collidingShape": {
API: &API{
name: "APIClientName",
Metadata: meta,
Operations: map[string]*Operation{
"FirstOp": {Name: "FirstOp",
InputRef: ShapeRef{ShapeName: "FirstOpRequest"},
},
},
Shapes: map[string]*Shape{
"FirstOpRequest": {ShapeName: "FirstOpRequest", Type: "structure",
MemberRefs: map[string]*ShapeRef{
"Foo": {ShapeName: "APIClientName"},
"ooF": {ShapeName: "APIClientNameList"},
},
},
"APIClientName": {
ShapeName: "APIClientName", Type: "structure",
},
"APIClientNameList": {
ShapeName: "APIClientNameList", Type: "list",
MemberRef: ShapeRef{ShapeName: "APIClientName"},
},
},
},
ExpectOps: map[string]OpExpect{
"FirstOp": {
Input: "FirstOpInput",
Output: "FirstOpOutput",
},
},
ExpectShapes: []string{
"APIClientNameList", "APIClientName_",
"FirstOpInput", "FirstOpOutput",
},
},
}

for name, c := range cases {
Expand Down