mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	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:
		@@ -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.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user