taverntesting / tavern

A command-line tool and Python library and Pytest plugin for automated testing of RESTful APIs, with a simple, concise and flexible YAML-based syntax
https://taverntesting.github.io/
MIT License
1.03k stars 195 forks source link

question about nullable fields. #852

Closed jaanauati closed 1 year ago

jaanauati commented 1 year ago

Hi, how can I validate that a given field in the response is either null or string?

I was thinking on something like the following, which of course does not work:

...
json:
   fieldName: !anystr | null

Does tavern support combining types or nullable fields?

michaelboulton commented 1 year ago

Tavern doesn't support this, and unless there's some support for parsing type hints to Python types (without using eval) I don't think this will ever be supported as it would be quite a bit of work