Skip to content

Commit

Permalink
Merge pull request #4 from emilgelman/fix-list-of-objects
Browse files Browse the repository at this point in the history
fix terraform list of objects
  • Loading branch information
emilgelman authored Oct 28, 2021
2 parents a7857d6 + 0ebfc33 commit 5298943
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
4 changes: 3 additions & 1 deletion pkg/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func (m *Mapper) parseDefinition(rootName, name string, openapiSchema *spec.Sche
}
path := prop.SchemaProps.Items.Schema.Ref.Ref.GetURL().Path
ss := schemas[strings.ToLower(path)]
tfSchema[i] = &schema.Schema{Type: schema.TypeList, Elem: &ss}
tfSchema[i] = &schema.Schema{Type: schema.TypeList, Elem: &schema.Resource{
Schema: ss,
}}
continue
}
m.parseDefinition(rootName, i, &prop, tfSchema, schemas)
Expand Down
10 changes: 6 additions & 4 deletions pkg/mapper/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ func TestMapArrayOfObject(t *testing.T) {
"cylinders": &schema.Schema{
Type: schema.TypeList,
Required: true,
Elem: &map[string]*schema.Schema{
"number": {
Type: schema.TypeString,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"number": {
Type: schema.TypeString,
Required: true,
},
},
},
},
Expand Down
20 changes: 12 additions & 8 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ var expectedSchemas = map[string]map[string]*schema.Schema{
"cylinders": &schema.Schema{
Type: schema.TypeList,
Required: true,
Elem: &map[string]*schema.Schema{"number": {
Type: schema.TypeString,
Required: true,
}},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{"number": {
Type: schema.TypeString,
Required: true,
}},
},
},
},
"GetcarSchema": {
Expand All @@ -33,10 +35,12 @@ var expectedSchemas = map[string]map[string]*schema.Schema{
"cylinders": {
Type: schema.TypeList,
Required: true,
Elem: &map[string]*schema.Schema{"number": {
Type: schema.TypeString,
Required: true,
}},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{"number": {
Type: schema.TypeString,
Required: true,
}},
},
},
}},
},
Expand Down

0 comments on commit 5298943

Please sign in to comment.