@@ -229,6 +229,49 @@ func (a *API) renameExportable() {
229229 }
230230}
231231
232+ // renameCollidingFields will rename any fields that uses an SDK or Golang
233+ // specific name.
234+ func (a * API ) renameCollidingFields () {
235+ for _ , v := range a .Shapes {
236+ namesWithSet := map [string ]struct {}{}
237+ for k , field := range v .MemberRefs {
238+ if strings .HasPrefix (k , "Set" ) {
239+ namesWithSet [k ] = struct {}{}
240+ }
241+
242+ if collides (k ) {
243+ renameCollidingField (k , v , field )
244+ }
245+ }
246+
247+ // checks if any field names collide with setters.
248+ for name := range namesWithSet {
249+ if field , ok := v .MemberRefs ["Set" + name ]; ok {
250+ renameCollidingField (name , v , field )
251+ }
252+ }
253+ }
254+ }
255+
256+ // collides will return true if it is a name used by the SDK or Golang.
257+ func collides (name string ) bool {
258+ switch name {
259+ case "String" ,
260+ "GoString" ,
261+ "Validate" :
262+ return true
263+ default :
264+ return false
265+ }
266+ }
267+
268+ func renameCollidingField (name string , v * Shape , field * ShapeRef ) {
269+ newName := name + "_"
270+ fmt .Printf ("Shape %s's field %q renamed to %q\n " , v .ShapeName , name , newName )
271+ delete (v .MemberRefs , name )
272+ v .MemberRefs [newName ] = field
273+ }
274+
232275// createInputOutputShapes creates toplevel input/output shapes if they
233276// have not been defined in the API. This normalizes all APIs to always
234277// have an input and output structure in the signature.
0 commit comments