Fix some minor issues in Go codes templates#13
Fix some minor issues in Go codes templates#13JunyiYi merged 8 commits intoVSChina:azure_backendfrom
Conversation
| <% elsif property.is_a?(Api::Type::Array) -%> | ||
| results := make([]<%= sdk_marshal.package -%>.<%= sdk_marshal.sdktype.go_type_name -%>, 0) | ||
| for _, v := range input { | ||
| v := v.(map[string]interface{}) |
There was a problem hiding this comment.
| v := v.(map[string]interface{}) | |
| v := item.(map[string]interface{}) |
There was a problem hiding this comment.
Should it be item := item.(map[string]interface{}) ?
The generated .go code is like this
There was a problem hiding this comment.
No, it should be v := item.(map[string]interface{})
| @@ -74,6 +74,7 @@ func expand<%= sdk_marshal.resource -%><%= descriptor.func_name -%>(input <%= go | |||
| <% elsif property.is_a?(Api::Type::Array) -%> | |||
| results := make([]<%= sdk_marshal.package -%>.<%= sdk_marshal.sdktype.go_type_name -%>, 0) | |||
| for _, v := range input { | |||
There was a problem hiding this comment.
| for _, v := range input { | |
| for _, item := range input { |
And rename the original item to result.
|
@JunyiYi Codes are modified, find your time to check it. |
|
Thanks @houkms for the update. Please use |
|
OK, fixed. |
|
This PR fix the issue in this magic-module-specs PR. |
|
@JunyiYi Other possible issues are fixed in the above commit, including
Please find your time to review. |
|
This PR also fixes the pipeline error in the magic-module-specs PR102 |
JunyiYi
left a comment
There was a problem hiding this comment.
Thanks @houkms , after taking a look at the PR, I think most of the string concatenation or to_s stuffs could be simplified by Ruby String Interpolation.
| properties.each do |pn, pv| | ||
| if pv.is_a?(Hash) | ||
| pv.each do |key, val| | ||
| flat_properties[pn+"."+key] = val |
There was a problem hiding this comment.
You can simplify the string with "#{pn}.#{key}".
There was a problem hiding this comment.
Replaced! Also done for other similar cases.
| flatten_example_properties_to_check(example_props, true) | ||
| end | ||
|
|
||
| def flatten_example_properties_to_check(properties, is_nested) |
There was a problem hiding this comment.
Here is_nested, do you mean has_nested_item?
There was a problem hiding this comment.
Yes, and the name was changed to be has_nested_item
| <% elsif prop[1].is_a?(Integer) || prop[1].is_a?(TrueClass) || prop[1].is_a?(FalseClass) -%> | ||
| <%= prop[0].ljust(prop_alignment) -%> = <%= lines(prop[1].to_s) -%> | ||
| <% elsif prop[1].is_a?(Array) && (prop[1].length == 0 || prop[1][0].is_a?(String)) | ||
| res_arr = prop[1].collect{|elem| "\""+elem.to_s+"\""} -%> |
There was a problem hiding this comment.
Can you try the following code whether it works or not?
| res_arr = prop[1].collect{|elem| "\""+elem.to_s+"\""} -%> | |
| res_arr = prop[1].map{|elem| "\"#{elem}\""} -%> |
There was a problem hiding this comment.
It works, replaced now.
|
@JunyiYi Codes were refined now according to your suggestions. |
JunyiYi
left a comment
There was a problem hiding this comment.
The code is pretty good to go except for one minor issue. We still need to keep the = for tags while omit it for other block properties.
| -%> | ||
|
|
||
| <%= prop[0] -%> = { | ||
| <%= prop[0] -%> { |
There was a problem hiding this comment.
Please make sure we include the equal sign (=) for tags (You can define a new helper function in terraform/helpers.rb similar to this one for ansible). Here is the example in Terraform: https://github.com/terraform-providers/terraform-provider-azurerm/blob/master/azurerm/resource_arm_eventgrid_topic_test.go#L201.
|
Added codes to deal with the special case for tags property. |
| -%> | ||
|
|
||
| <%= prop[0] -%> = { | ||
| <%= prop[0] -%> <%= "= " if is_tags?(prop)-%>{ |
There was a problem hiding this comment.
Well, I think for this case, it is not a good choice to introduce that common helper function. Let's do it inline: <%= '= ' if prop[0] == 'tags' -%>.
JunyiYi
left a comment
There was a problem hiding this comment.
Code LGTM, let's merge that in.
Fix some minor issues in Go codes templates.