@@ -10,6 +10,7 @@ import (
10
10
"math/big"
11
11
"regexp"
12
12
"strconv"
13
+ "strings"
13
14
"unicode/utf16"
14
15
15
16
"github.com/getkin/kin-openapi/jsoninfo"
@@ -839,18 +840,30 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
839
840
if v := schema .OneOf ; len (v ) > 0 {
840
841
841
842
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 {
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 len ( schema . Discriminator . Mapping ) > 0 {
847
848
if mapref , okcheck := schema .Discriminator .Mapping [discriminatorVal .(string )]; okcheck {
848
849
for _ , item := range v {
849
850
if item .Ref == mapref {
850
851
return item .Value .visitJSON (settings , value )
851
852
}
852
853
}
853
854
}
855
+ } else {
856
+ /* Assume implicit mapping on objectType as stated in Mapping Type Names section:
857
+ ``It is implied, that the property to which discriminator refers, contains the
858
+ name of the target schema. In the example above, the objectType property should
859
+ contain either simpleObject, or complexObject string.''*/
860
+ for _ , oneof := range schema .OneOf {
861
+ /* TODO: ugly.. should this be a property of the SchemaRef? */
862
+ objectType := strings .ReplaceAll (oneof .Ref , "#/components/schemas/" , "" )
863
+ if objectType == discriminatorVal {
864
+ return oneof .Value .visitJSON (settings , value )
865
+ }
866
+ }
854
867
}
855
868
}
856
869
}
0 commit comments