Repository: dikhan/terraform-provider-openapi
Pull request #170 (2019-10-22 02:56:02)

fix IneffAssign issues
## Proposed changes

Please add as many details as possible about the change here. Does this Pull Request resolve any open issue? If so, please make sure to link to that issue:
                                                              
Fixes IneffAssign issues

## Type of change

What type of change does your code introduce to the provider? Please put an `x` (w/o heading/trailing white spaces) 
in the boxes that apply:

- [ ] Bug-fix (change that fixes current functionality)
- [ ] New feature (change that adds new functionality)
- [x] Enhancement (change that adds new functionality)

## Checklist

Please put an `x` (w/o heading/trailing white spaces) in the boxes that apply:

- [x] I have read and followed the [CONTRIBUTING](https://github.com/dikhan/terraform-provider-api/blob/master/.github/CONTRIBUTING.md) guidelines
- [x] I have made sure code compiles correctly
- [x] I have run 'make test' locally from the terraform_provider_api folder and no errors were found
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] I have added/updated necessary documentation (if appropriate)


Patch:
diff --git a/openapi/data_source_factory.go b/openapi/data_source_factory.go
index deaef159..e9820017 100644
--- a/openapi/data_source_factory.go
+++ b/openapi/data_source_factory.go
@@ -46,6 +46,9 @@ func (d dataSourceFactory) createTerraformDataSourceSchema() (map[string]*schema
 		return nil, err
 	}
 	dataSourceSchema, err := specSchema.createDataSourceSchema()
+	if err != nil {
+		return nil, err
+	}
 	dataSourceSchema[dataSourceFilterPropertyName] = d.dataSourceFiltersSchema()
 	return dataSourceSchema, nil
 }
diff --git a/openapi/openapi_spec_resource_schema_definition.go b/openapi/openapi_spec_resource_schema_definition.go
index 974c6d5e..3858052f 100644
--- a/openapi/openapi_spec_resource_schema_definition.go
+++ b/openapi/openapi_spec_resource_schema_definition.go
@@ -53,8 +53,8 @@ func setPropertyForDataSourceSchema(inputProperty *schema.Schema) (outputPropert
 		hasChildResources := inputProperty.Elem != nil && len(inputProperty.Elem.(*schema.Resource).Schema) > 0
 		if hasChildResources {
 			childResources := outputProperty.Elem.(*schema.Resource).Schema
-			for _, childR := range childResources {
-				childR = setPropertyForDataSourceSchema(childR)
+			for childName, childR := range childResources {
+				childResources[childName] = setPropertyForDataSourceSchema(childR)
 			}
 		}
 	}


Test patch:
diff --git a/openapi/data_source_factory_test.go b/openapi/data_source_factory_test.go
index 8464441f..b0e75514 100644
--- a/openapi/data_source_factory_test.go
+++ b/openapi/data_source_factory_test.go
@@ -82,6 +82,20 @@ func TestCreateTerraformDataSourceSchema(t *testing.T) {
 			},
 			expectedError: errors.New("error due to nil schema def"),
 		},
+		{
+			name: "crappy path - internal call to createDataSourceSchema errors out",
+			openAPIResource: &specStubResource{
+				schemaDefinition: &specSchemaDefinition{
+					Properties: specSchemaDefinitionProperties{
+						&specSchemaDefinitionProperty{
+							Name: "unsupported_type_prop",
+							Type: "unsupported",
+						},
+					},
+				},
+			},
+			expectedError: errors.New("non supported type unsupported"),
+		},
 	}
 
 	for _, tc := range testCases {