Yelp / bravado-core

Other
109 stars 98 forks source link

Fix issue #359: properly validate nullable polymorphic models #367

Closed macisamuele closed 4 years ago

macisamuele commented 4 years ago

The goal of this review is to address the validation issue that affects polymorphic models that are nullable (via x-nullable field).

In order to better highlight the reported issue I've modified the polymorphic_specs to ensure that the operation (endpoint) used for testing does return an object that is not directly the polymorphic model.

The issue was mostly caused by the fact that discriminator validation was not using the usual safe check around nullability and so in case of instance=None entering bravado_core.swagger20_validator.discriminator_validator was not short circuiting and instead trying to extract the discriminator key from instance (which was none) and so leading to TypeError being thrown.

Adding the null-gate address the issue an so resolves #359

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.001%) to 98.621% when pulling 0841fe345e483a4f1ef91e02ac9585477b5aab44 on macisamuele:maci-issue-359 into 7c0a3bd02814354f818ebd46e6aded05397bdacb on Yelp:master.