Merge pull request #64 from svanharmelen/b-fix-flattening-empty-objects
Fix flattening of empty objects
This commit is contained in:
commit
1688f22977
@ -76,6 +76,12 @@ func flattenObjectType(
|
||||
item *ast.ObjectItem,
|
||||
items []*ast.ObjectItem,
|
||||
frontier []*ast.ObjectItem) ([]*ast.ObjectItem, []*ast.ObjectItem) {
|
||||
// If the list has no items we do not have to flatten anything
|
||||
if ot.List.Items == nil {
|
||||
items = append(items, item)
|
||||
return items, frontier
|
||||
}
|
||||
|
||||
// All the elements of this object must also be objects!
|
||||
for _, subitem := range ot.List.Items {
|
||||
if _, ok := subitem.Val.(*ast.ObjectType); !ok {
|
||||
|
@ -182,6 +182,7 @@ func TestFlattenObjects(t *testing.T) {
|
||||
var literals = []struct {
|
||||
src string
|
||||
nodeType []ast.Node
|
||||
itemLen int
|
||||
}{
|
||||
{
|
||||
`{
|
||||
@ -196,8 +197,19 @@ func TestFlattenObjects(t *testing.T) {
|
||||
&ast.ObjectType{},
|
||||
&ast.LiteralType{},
|
||||
&ast.LiteralType{},
|
||||
&ast.ListType{},
|
||||
},
|
||||
3,
|
||||
},
|
||||
{
|
||||
`{
|
||||
"variable": {
|
||||
"foo": {}
|
||||
}
|
||||
}`,
|
||||
[]ast.Node{
|
||||
&ast.ObjectType{},
|
||||
},
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
||||
@ -229,6 +241,10 @@ func TestFlattenObjects(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if the number of items is correct
|
||||
equals(t, l.itemLen, i)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user