VSChina / magic-modules

Magic Modules: Automagically generate Google Cloud Platform support for OSS
Apache License 2.0
1 stars 4 forks source link

`ExpandFlattenDescriptor` can't differentiate `ComplexObject` and `ComplexArrayObject` #76

Open magodo opened 4 years ago

magodo commented 4 years ago

When a ExpandFlattenDescriptor is constructed for ComplexObject or ComplexArrayObject sdk fields, the @func_name is deduced from the go_type_name of those fields.

Since go_type_name has ambiguous meanings when applied to ComplexObject (which indicates the type of this complex object, i.e. struct type) and ComplexArrayObject (which indicates the type of element type). In some case, these go_type_name(s) might be same. However since their properties are different, magic module will generate expand/flatten function for both of them, with same name. This will introduce redeclaration error in generated code.

magodo commented 4 years ago

The impact field is within the expand/flatten function related stuff, which currently covers EnumArrayObject, ComplexObject and ComplexArrayObject sdk types (maybe more...).

A quick fix would be to change @func_name definition, where we should also check whether the accepted sdk field is an array or not. If it's an array, prefix/suffix go_type_name with "array"-like word to be as the @func_name.

A more general fix would be to elliminate the ambiguity of go_type_name, and then change the the @func_name duduction logic. This might introduce new field into SDKTypeDefinition.