Skip to content

Commit bdb6198

Browse files
feat: add OpenAPI schema validation using Schemathesis (#19)
* fix: remove method from kwargs and mark tests as ERROR on exceptions - Remove 'method' from kwargs before passing to auth.request() to fix 'got multiple values' error - Set test status to ERROR when exceptions occur during test execution - Fixes issue where all 190 tests were failing but showing as passed * fix: remove url parameter from kwargs to prevent duplication The case.as_transport_kwargs() method returns a dictionary that includes both 'method' and 'url' keys. We already fixed the 'method' duplication in the previous commit, but 'url' was also causing the same issue. When we pass path as a positional argument to auth.request(), which then passes it to httpx.Client.request() as the 'url' parameter, having 'url' also in **kwargs causes 'got multiple values for argument url' error. This fix removes both 'method' and 'url' from kwargs before passing to auth.request() to prevent parameter duplication. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix: handle OperationDefinition object in Schemathesis 4.x response validation In Schemathesis 4.x, operation.definition is an OperationDefinition object, not a dictionary. The code was calling .get() on it which caused AttributeError. This fix makes _check_response() defensive by: 1. Checking if definition is a dict or object 2. Accessing responses as dict.get() or object.responses 3. Wrapping in try-except to handle unexpected structures gracefully Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * feat: add OpenAPI schema validation using Schemathesis Enhanced response validation to use Schemathesis's built-in schema validation via case.validate_response(). This will detect discrepancies between API responses and the OpenAPI specification including: - Missing required fields - Wrong field types - Invalid enum values - Schema constraint violations - Additional properties not defined in spec When validation fails, the error is captured as a Discrepancy with: - Type: CONSTRAINT_MISMATCH - Constraint: schema_validation - Details: The specific validation error from Schemathesis This should now detect the discrepancies that were found in local testing. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent b9df2ca commit bdb6198

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

scripts/utils/schemathesis_runner.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,26 @@ def _test_operation(self, operation: Any) -> SchemathesisResult:
227227
)
228228
result.status = TestStatus.ERROR
229229

230-
# Check for validation discrepancies
230+
# Validate response against schema using Schemathesis
231+
try:
232+
# Schemathesis 4.x validation
233+
case.validate_response(response)
234+
except Exception as validation_error:
235+
# Schema validation failed - this is a discrepancy
236+
discrepancy = Discrepancy(
237+
path=case.path,
238+
property_name="response_schema",
239+
constraint_type="schema_validation",
240+
discrepancy_type=DiscrepancyType.CONSTRAINT_MISMATCH,
241+
spec_value="Valid per OpenAPI schema",
242+
api_behavior=str(validation_error),
243+
test_values=[self._case_to_dict(case)],
244+
recommendation=f"Update schema or fix API response: {validation_error}",
245+
)
246+
result.discrepancies.append(discrepancy)
247+
result.status = TestStatus.FAILED
248+
249+
# Additional validation checks
231250
discrepancy = self._check_response(case, response)
232251
if discrepancy:
233252
result.discrepancies.append(discrepancy)

0 commit comments

Comments
 (0)