Skip to content

Commit

Permalink
Merge branch 'investigation/nested-objects-readonly-props-diffing' of…
Browse files Browse the repository at this point in the history
… github.com:dikhan/terraform-provider-openapi into investigation/nested-objects-readonly-props-diffing
  • Loading branch information
dikhan committed Sep 2, 2019
2 parents d3e90b3 + 36c7624 commit a9aae5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion openapi/openapi_spec_resource_schema_definition_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ func (s *specSchemaDefinitionProperty) terraformSchema() (*schema.Schema, error)
// complex data structures
switch s.Type {
case typeObject:
shouldUseLegacyTerraformSDKApproachForBlocks, err := s.shouldUseLegacyTerraformSDKBlockApproachForComplexObjects() //todo: handle the error
shouldUseLegacyTerraformSDKApproachForBlocks, err := s.shouldUseLegacyTerraformSDKBlockApproachForComplexObjects()
if err != nil {
return nil, err
}
if shouldUseLegacyTerraformSDKApproachForBlocks {
terraformSchema.Type = schema.TypeList
terraformSchema.MaxItems = 1
Expand Down
16 changes: 16 additions & 0 deletions openapi/openapi_spec_resource_schema_definition_property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,21 @@ func TestTerraformSchema(t *testing.T) {
})
})

Convey("Given a swagger schema definition that has a nested object with no specSchemaDefinition", t, func() {
s := &specSchemaDefinitionProperty{
Name: "top_level_object",
Type: typeObject,
}
Convey("When terraformSchema method is called", func() {
tfPropSchema, err := s.terraformSchema()
Convey("Then the resulting tfPropSchema should be nil and an error should be raised", func() {
So(err, ShouldNotBeNil)
So(tfPropSchema, ShouldBeNil)
So(err.Error(), ShouldEqual, `missing spec schema definition for object property 'top_level_object'`)
})
})
})

Convey("Given a swagger schema definition that has complex object", t, func() {
complexObjectName := "complex_object_which_is_nested"
s := &specSchemaDefinitionProperty{
Expand Down Expand Up @@ -1531,6 +1546,7 @@ func TestValidateFunc(t *testing.T) {
}

func Test_shouldUseLegacyTerraformSDKBlockApproachForComplexObjects(t *testing.T) {

Convey("shouldUseLegacyTerraformSDKBlockApproachForComplexObject", t, func() {
Convey("returns an error", func() {
Convey("Given a specSchemaDefinitionProperty with Type of 'object' and nothing else"+
Expand Down

0 comments on commit a9aae5c

Please sign in to comment.