Skip to content

Commit ec30886

Browse files
Rakothantonmedv
authored andcommitted
fix docgen for ambiguous fields in embedded structs
1 parent d22339d commit ec30886

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

docgen/docgen.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func CreateDoc(i interface{}) *Context {
5757
}
5858

5959
for name, t := range conf.CreateTypesTable(i) {
60+
if t.Ambiguous {
61+
continue
62+
}
6063
c.Variables[Identifier(name)] = c.use(t.Type, fromMethod(t.Method))
6164
}
6265

docgen/docgen_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,54 @@ func TestCreateDoc(t *testing.T) {
132132
assert.Equal(t, litter.Sdump(expected), litter.Sdump(doc))
133133
}
134134

135+
type A struct {
136+
AmbiguousField int
137+
OkField int
138+
}
139+
type B struct {
140+
AmbiguousField string
141+
}
142+
type EnvAmbiguous struct {
143+
A
144+
B
145+
}
146+
147+
func TestCreateDoc_Ambiguous(t *testing.T) {
148+
doc := CreateDoc(&EnvAmbiguous{})
149+
expected := &Context{
150+
Variables: map[Identifier]*Type{
151+
"A": {
152+
Kind: "struct",
153+
Name: "A",
154+
},
155+
"B": {
156+
Kind: "struct",
157+
Name: "B",
158+
},
159+
"OkField": {
160+
Kind: "int",
161+
},
162+
},
163+
Types: map[TypeName]*Type{
164+
"A": {
165+
Kind: "struct",
166+
Fields: map[Identifier]*Type{
167+
"AmbiguousField": {Kind: "int"},
168+
"OkField": {Kind: "int"},
169+
},
170+
},
171+
"B": {
172+
Kind: "struct",
173+
Fields: map[Identifier]*Type{
174+
"AmbiguousField": {Kind: "string"},
175+
},
176+
},
177+
},
178+
}
179+
180+
assert.Equal(t, litter.Sdump(expected), litter.Sdump(doc))
181+
}
182+
135183
func TestCreateDoc_FromMap(t *testing.T) {
136184
env := map[string]interface{}{
137185
"Tweets": []*Tweet{},

0 commit comments

Comments
 (0)