Dont validate discriminator value when in the case of lenient discriminator (#72)

This commit is contained in:
Vlad Barosan 2019-05-08 10:13:30 -07:00 коммит произвёл GitHub
Родитель 377b3ea598
Коммит 2743fdbd9a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 8 добавлений и 1 удалений

Просмотреть файл

@ -136,9 +136,12 @@ function validateDiscriminator (report, schema, json) {
// to conform to the Azure specs, we accept a lenient discriminator. if the type is missing in the
// payload we use the base class. Also if the type doesn't match anything, we use the base class.
var basePolymorphicSchemaDiscriminatorType =
basePolymorphicSchema.__$refResolved.properties[discriminatorPropertyName].enum[0]
var jsonDiscriminatorValue =
json[discriminatorPropertyName] ||
basePolymorphicSchema.__$refResolved.properties[discriminatorPropertyName].enum[0]
basePolymorphicSchemaDiscriminatorType
var schemaToValidate =
schema.oneOf.find(
@ -148,6 +151,10 @@ function validateDiscriminator (report, schema, json) {
jsonDiscriminatorValue
) || basePolymorphicSchema
// if the schema to validate is the base schema, we dont need to validate the discriminator enum value.
if (schemaToValidate === basePolymorphicSchema) {
json[discriminatorPropertyName] = basePolymorphicSchemaDiscriminatorType
}
ZSchemaValidator.validate.call(this, report, schemaToValidate, json)
return true
}