openapi: Fix response validation bug.

Currently there are no checks in validate_against_openapi_schema
to check whether the `content` it received actually matched with
the `response code`. For example during testing if a certain endpoint
was returning 400 but it was expected to return 200, then it would
pass schema validation as it would only have `msg` and `result` keys.
Add this validation and fix the wrong response returning points.
This commit is contained in:
orientor
2020-06-11 00:48:27 +05:30
committed by Tim Abbott
parent 03ef5e0b31
commit e989c87a18
3 changed files with 8 additions and 5 deletions

View File

@@ -124,6 +124,9 @@ def validate_against_openapi_schema(content: Dict[str, Any], endpoint: str,
"""Compare a "content" dict with the defined schema for a specific method
in an endpoint.
"""
# Check if the response matches its code
if response.startswith('2') and (content.get('result', 'success').lower() != 'success'):
raise SchemaError("Response is not 200 but is validating against 200 schema")
global exclusion_list
schema = get_schema(endpoint, method, response)
# In a single response schema we do not have two keys with the same name.