Skip to content

Commit

Permalink
fix docgen for ambiguous fields in embedded structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakoth authored and antonmedv committed May 18, 2020
1 parent d22339d commit ec30886
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func CreateDoc(i interface{}) *Context {
}

for name, t := range conf.CreateTypesTable(i) {
if t.Ambiguous {
continue
}
c.Variables[Identifier(name)] = c.use(t.Type, fromMethod(t.Method))
}

Expand Down
48 changes: 48 additions & 0 deletions docgen/docgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,54 @@ func TestCreateDoc(t *testing.T) {
assert.Equal(t, litter.Sdump(expected), litter.Sdump(doc))
}

type A struct {
AmbiguousField int
OkField int
}
type B struct {
AmbiguousField string
}
type EnvAmbiguous struct {
A
B
}

func TestCreateDoc_Ambiguous(t *testing.T) {
doc := CreateDoc(&EnvAmbiguous{})
expected := &Context{
Variables: map[Identifier]*Type{
"A": {
Kind: "struct",
Name: "A",
},
"B": {
Kind: "struct",
Name: "B",
},
"OkField": {
Kind: "int",
},
},
Types: map[TypeName]*Type{
"A": {
Kind: "struct",
Fields: map[Identifier]*Type{
"AmbiguousField": {Kind: "int"},
"OkField": {Kind: "int"},
},
},
"B": {
Kind: "struct",
Fields: map[Identifier]*Type{
"AmbiguousField": {Kind: "string"},
},
},
},
}

assert.Equal(t, litter.Sdump(expected), litter.Sdump(doc))
}

func TestCreateDoc_FromMap(t *testing.T) {
env := map[string]interface{}{
"Tweets": []*Tweet{},
Expand Down

0 comments on commit ec30886

Please sign in to comment.