@@ -657,31 +657,20 @@ class SpecResolver {
657657 // Adding the model name or it's discriminator value as an enum constraint with one value (constant) on property marked as discriminator
658658 if ( definitions [ name ] && definitions [ name ] . properties && definitions [ name ] . properties [ discriminator ] ) {
659659 let val = name ;
660- let discriminatorType = 'string' ;
661660 if ( definitions [ name ] [ 'x-ms-discriminator-value' ] ) {
662661 val = definitions [ name ] [ 'x-ms-discriminator-value' ] ;
663662 }
664- // Ensure that the property marked as a discriminator has only one enum constraint and it should be the one that we want to set as a constant.
665- if ( definitions [ name ] . properties [ discriminator ] . enum ) {
666- delete definitions [ name ] . properties [ discriminator ] . enum ;
667- }
663+ // Ensure that the property marked as a discriminator has only one value in the enum constraint for that model and it
664+ // should be the one that is the model name or the value indicated by x-ms-discriminator-value. This will make the discriminator
665+ // property a constant (in json schema terms).
668666 if ( definitions [ name ] . properties [ discriminator ] [ '$ref' ] ) {
669- let obj ;
670- try {
671- obj = utils . getObject ( this . specInJson , definitions [ name ] . properties [ discriminator ] [ '$ref' ] . slice ( 1 ) ) ;
672- if ( obj && obj . type ) {
673- discriminatorType = obj . type ;
674- }
675- } catch ( err ) {
676- // do nothing, we tried to find the object and it's type. We will set it to "string" by default. It is safe to assume that properties
677- // marked as "discriminator" will be of type "string" as it needs to refer to a model definition name which logically should be a
678- // string as it is the key in the definitions object in the swagger spec.
679- }
680667 delete definitions [ name ] . properties [ discriminator ] [ '$ref' ] ;
681668 }
682- // Set the type if not set.
669+ // We will set "type" to "string". It is safe to assume that properties marked as "discriminator" will be of type "string"
670+ // as it needs to refer to a model definition name. Model name would be a key in the definitions object/dictionary in the
671+ // swagger spec. keys would always be a string in a JSON object/dictionary.
683672 if ( ! definitions [ name ] . properties [ discriminator ] . type ) {
684- definitions [ name ] . properties [ discriminator ] . type = discriminatorType ;
673+ definitions [ name ] . properties [ discriminator ] . type = 'string' ;
685674 }
686675 definitions [ name ] . properties [ discriminator ] . enum = [ `${ val } ` ] ;
687676 }
0 commit comments