snok/drf-openapi-tester

Cannot validate response with empty content

Closed this issue · 1 comments

Hello!
I'm really excited about this project because it perfectly fit my current needs - I want to have a custom open api file, but verify if it's not out of sync with the API.

However, there's one problem I'm having now I need your help.
When I test response of an endpoint that returns no content, I get this error:

E           openapi_tester.exceptions.UndocumentedSchemaSectionError: Error: Unsuccessfully tried to index the OpenAPI schema by `content`. 
E           
E           No content documented for method: delete, path: /endpoint/{version}/path

I've looked it up in code and it is raised in the SchemaTester.get_key_value, which raises error when a key is not defined.
It is however possible to have no content key. This way you define an empty response in OpenAPI 3.x.

How could I get it fixed? Should I skip testing empty responses?
I think I could provide a fix for this, but please tell me what is the desired way of solving this problem.

Hi @radowit! Thanks for reporting this 👏

I agree, this seems like the right way to document a 204 response. Also found this document to back it up.

If you want to create a fix for this that would be great!

I would imagine just checking for a content key and returning early when it's missing might be enough to fix the bug, but I haven't looked at this code in a while so can't be 100% sure. Feel free to try and implement a fix, and I can look at this more closely over the weekend if needed 👍