@@ -3487,7 +3487,7 @@ const oneOfMapNoDiscriminator: {[index: string]: Array<any>} = {
34873487}
34883488
34893489export class ObjectSerializer {
3490- public static findCorrectType ( data : any , expectedType : string ) {
3490+ public static findCorrectType ( data : any , expectedType : string , serializer : boolean ) {
34913491 if ( data == undefined ) {
34923492 return expectedType ;
34933493 } else if ( primitives . indexOf ( expectedType . toLowerCase ( ) ) !== - 1 ) {
@@ -3505,9 +3505,16 @@ export class ObjectSerializer {
35053505 // the type does not have a discriminator.
35063506 if ( oneOfMapNoDiscriminator [ expectedType ] ) {
35073507 for ( const index in oneOfMapNoDiscriminator [ expectedType ] ) {
3508- if ( ObjectSerializer . validateType ( data , typeMap [ oneOfMapNoDiscriminator [ expectedType ] [ index ] ] ) ) {
3509- return oneOfMapNoDiscriminator [ expectedType ] [ index ] ;
3508+ if ( serializer ) {
3509+ if ( ObjectSerializer . serializerValidateType ( data , typeMap [ oneOfMapNoDiscriminator [ expectedType ] [ index ] ] ) ) {
3510+ return oneOfMapNoDiscriminator [ expectedType ] [ index ] ;
3511+ }
3512+ } else {
3513+ if ( ObjectSerializer . deserializerValidateType ( data , typeMap [ oneOfMapNoDiscriminator [ expectedType ] [ index ] ] ) ) {
3514+ return oneOfMapNoDiscriminator [ expectedType ] [ index ] ;
3515+ }
35103516 }
3517+
35113518 }
35123519 }
35133520 return expectedType ; // discriminator was not present (or an empty string)
@@ -3527,10 +3534,10 @@ export class ObjectSerializer {
35273534 }
35283535 }
35293536
3530- public static validateType ( data : any , potentialType : any ) : boolean {
3537+ public static deserializerValidateType ( data : any , potentialType : any ) : boolean {
35313538 for ( const index in potentialType . getAttributeTypeMap ( ) ) {
35323539 const attribute = potentialType . getAttributeTypeMap ( ) [ index ] ;
3533- if ( ! data [ attribute . baseName ] ) {
3540+ if ( ! data . hasOwnProperty ( attribute . baseName ) ) {
35343541 return false ;
35353542 }
35363543 if ( enumsMap [ attribute . type ] ) {
@@ -3541,6 +3548,16 @@ export class ObjectSerializer {
35413548 }
35423549 return true ;
35433550 }
3551+ public static serializerValidateType ( data : Object , potentialType : any ) : boolean {
3552+ const properties = Object . getOwnPropertyNames ( data )
3553+ for ( const index in properties ) {
3554+ const property = properties [ index ]
3555+ if ( ! potentialType . getAttributeTypeMap ( ) . find ( ( attribute ) => attribute . name === property ) ) {
3556+ return false
3557+ }
3558+ }
3559+ return true
3560+ }
35443561
35453562 public static serialize ( data : any , type : string ) {
35463563 if ( data == undefined ) {
@@ -3562,12 +3579,12 @@ export class ObjectSerializer {
35623579 if ( enumsMap [ type ] ) {
35633580 return data ;
35643581 }
3565- if ( ! typeMap [ type ] ) { // in case we dont know the type
3566- return data ;
3582+ if ( ! typeMap [ type ] && ! oneOfMapNoDiscriminator [ type ] ) { // in case we dont know the type
3583+ return data
35673584 }
35683585
35693586 // Get the actual type of this object
3570- type = this . findCorrectType ( data , type ) ;
3587+ type = this . findCorrectType ( data , type , true ) ;
35713588
35723589 // get the map for the correct type.
35733590 let attributeTypes = typeMap [ type ] . getAttributeTypeMap ( ) ;
@@ -3582,7 +3599,7 @@ export class ObjectSerializer {
35823599
35833600 public static deserialize ( data : any , type : string ) {
35843601 // polymorphism may change the actual type.
3585- type = ObjectSerializer . findCorrectType ( data , type ) ;
3602+ type = ObjectSerializer . findCorrectType ( data , type , false ) ;
35863603 if ( data == undefined ) {
35873604 return data ;
35883605 } else if ( primitives . indexOf ( type . toLowerCase ( ) ) !== - 1 ) {
0 commit comments