From 2743fdbd9a4f64a1af0e76c08e09e93e57a3461d Mon Sep 17 00:00:00 2001 From: Vlad Barosan Date: Wed, 8 May 2019 10:13:30 -0700 Subject: [PATCH] Dont validate discriminator value when in the case of lenient discriminator (#72) --- lib/validation/custom-zschema-validators.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/validation/custom-zschema-validators.js b/lib/validation/custom-zschema-validators.js index e11012c..3706e20 100644 --- a/lib/validation/custom-zschema-validators.js +++ b/lib/validation/custom-zschema-validators.js @@ -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 }