Skip to content

Commit 5547859

Browse files
Avoid failfast and return proper error when mapping is available
(cherry picked from commit d743e52)
1 parent 45c1543 commit 5547859

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

openapi3/schema.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,25 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
837837
}
838838

839839
if v := schema.OneOf; len(v) > 0 {
840+
841+
if schema.Discriminator != nil {
842+
if len(schema.Discriminator.Mapping) > 0 {
843+
/* Find mapped object by ref */
844+
if valuemap, okcheck := value.(map[string]interface{}); okcheck {
845+
pn := schema.Discriminator.PropertyName
846+
if discriminatorVal, okcheck := valuemap[pn]; okcheck {
847+
if mapref, okcheck := schema.Discriminator.Mapping[discriminatorVal.(string)]; okcheck {
848+
for _, item := range v {
849+
if item.Ref == mapref {
850+
return item.Value.visitJSON(settings, value)
851+
}
852+
}
853+
}
854+
}
855+
}
856+
}
857+
}
858+
840859
ok := 0
841860
for _, item := range v {
842861
v := item.Value

0 commit comments

Comments
 (0)