Skip to content

Commit 2cf32f2

Browse files
committed
schema: Let AnyOf/AllOf implement FieldGetter
Lets AnyOf and AllOf implement the FieldGetter interface.
1 parent 505fb07 commit 2cf32f2

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

schema/allof.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ func (v AllOf) Validate(value interface{}) (interface{}, error) {
4747
}
4848
return value, nil
4949
}
50+
51+
// GetField implements the FieldGetter interface. Note that it will return the
52+
// first matching field only.
53+
func (v AllOf) GetField(name string) *Field {
54+
for _, obj := range v {
55+
if fg, ok := obj.(FieldGetter); ok {
56+
return fg.GetField(name)
57+
}
58+
}
59+
return nil
60+
}

schema/anyof.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,14 @@ func (v AnyOf) Serialize(value interface{}) (interface{}, error) {
7979

8080
return value, nil
8181
}
82+
83+
// GetField implements the FieldGetter interface. Note that it will return the
84+
// first matching field only.
85+
func (v AnyOf) GetField(name string) *Field {
86+
for _, obj := range v {
87+
if fg, ok := obj.(FieldGetter); ok {
88+
return fg.GetField(name)
89+
}
90+
}
91+
return nil
92+
}

0 commit comments

Comments
 (0)