snok / drf-openapi-tester

Test utility for validating OpenAPI documentation
https://github.com/snok/django-openapi-tester
BSD 3-Clause "New" or "Revised" License
119 stars 23 forks source link

Handle dicts in validate_unique_items #301

Closed arttuperala closed 1 year ago

arttuperala commented 1 year ago

validate_unique_items() validator had a known issue where it could not validate dict objects in any way. Attempting to pass one would result in an immediate TypeError: unhashable type: 'dict'.

This merge request adds support for validating dict objects by serializing them to ordered JSON strings and doing the comparison with those. I imagine that this solution might not be flexible enough to handle every possible dict but it should be better than not being able to handle any dict. And since we are talking about data returned by an API, it's quite likely that the data passed to the validator will actually be JSON serializable.

codecov[bot] commented 1 year ago

Codecov Report

Merging #301 (457384d) into master (8cd209a) will increase coverage by 0.0%. The diff coverage is 100.0%.

@@          Coverage Diff           @@
##           master    #301   +/-   ##
======================================
  Coverage    98.6%   98.6%           
======================================
  Files           9       9           
  Lines         528     531    +3     
  Branches       97      99    +2     
======================================
+ Hits          521     524    +3     
  Misses          4       4           
  Partials        3       3           
Impacted Files Coverage Δ
openapi_tester/validators.py 100.0% <100.0%> (ø)
sondrelg commented 1 year ago

Looks good! Thanks @arttuperala 👏