Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Handle dicts in validate_unique_items #301

Merged
merged 1 commit into from
Jul 4, 2023
Merged

Handle dicts in validate_unique_items #301

merged 1 commit into from
Jul 4, 2023

Conversation

arttuperala
Copy link
Contributor

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
Copy link

codecov bot commented Jul 4, 2023

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
Copy link
Member

sondrelg commented Jul 4, 2023

Looks good! Thanks @arttuperala 👏

@sondrelg sondrelg merged commit 6a9a2c9 into snok:master Jul 4, 2023
@arttuperala arttuperala deleted the unique-dict branch July 4, 2023 09:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants