@@ -10,6 +10,7 @@ import (
1010 "math/big"
1111 "regexp"
1212 "strconv"
13+ "strings"
1314 "unicode/utf16"
1415
1516 "github.com/getkin/kin-openapi/jsoninfo"
@@ -839,18 +840,30 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
839840 if v := schema .OneOf ; len (v ) > 0 {
840841
841842 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 {
847848 if mapref , okcheck := schema .Discriminator .Mapping [discriminatorVal .(string )]; okcheck {
848849 for _ , item := range v {
849850 if item .Ref == mapref {
850851 return item .Value .visitJSON (settings , value )
851852 }
852853 }
853854 }
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+ }
854867 }
855868 }
856869 }
0 commit comments