File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ type FieldInfo struct {
21
21
}
22
22
23
23
func AppendFields (fields []FieldInfo , parentIndex []int , t reflect.Type ) []FieldInfo {
24
+ if t .Kind () == reflect .Ptr {
25
+ t = t .Elem ()
26
+ }
24
27
// For each field
25
28
numField := t .NumField ()
26
29
iteration:
Original file line number Diff line number Diff line change @@ -85,6 +85,36 @@ func TestEmbeddedStructs(t *testing.T) {
85
85
require .Equal (t , true , ok )
86
86
}
87
87
88
+ func TestEmbeddedPointerStructs (t * testing.T ) {
89
+ type EmbeddedStruct struct {
90
+ ID string
91
+ }
92
+
93
+ type ContainerStruct struct {
94
+ Name string
95
+ * EmbeddedStruct
96
+ }
97
+
98
+ instance := & ContainerStruct {
99
+ Name : "Container" ,
100
+ EmbeddedStruct : & EmbeddedStruct {
101
+ ID : "Embedded" ,
102
+ },
103
+ }
104
+
105
+ generator := NewGenerator (UseAllExportedFields ())
106
+
107
+ schemaRef , err := generator .GenerateSchemaRef (reflect .TypeOf (instance ))
108
+ require .NoError (t , err )
109
+
110
+ var ok bool
111
+ _ , ok = schemaRef .Value .Properties ["Name" ]
112
+ require .Equal (t , true , ok )
113
+
114
+ _ , ok = schemaRef .Value .Properties ["ID" ]
115
+ require .Equal (t , true , ok )
116
+ }
117
+
88
118
func TestCyclicReferences (t * testing.T ) {
89
119
type ObjectDiff struct {
90
120
FieldCycle * ObjectDiff
You can’t perform that action at this time.
0 commit comments