-
Notifications
You must be signed in to change notification settings - Fork 141
Description
Breaking Change in HyperSchema ResponseValidator Status Code Handling
Problem Description
PR #433 introduced a breaking change in the Committee::SchemaValidator::HyperSchema::ResponseValidator that causes validation failures due to overly strict status code matching.
Root Cause
The ResponseValidator now creates validators based on exact status code expectations from link.status_success:
# In ResponseValidator#initialize
@validators[link.status_success] = JsonSchema::Validator.new(target_schema(link))This creates a rigid mapping:
rel="create"→ expects exactly201rel="empty"→ expects exactly202- All others → expect exactly
200
The Issue
When the actual response status code doesn't match the expected link.status_success, validation fails with:
raise InvalidResponse, "Invalid response.#{@link.href} status code #{status} definition does not exist" if @validators[status].nil?This happens because @validators[status] is nil when the status doesn't match the single expected value.
Impact
This breaks backward compatibility for applications where:
- Create operations return
200instead of201 - Async operations return
200or204instead of202 - Existing working code suddenly fails validation after upgrading
Example Failure Scenario
# Schema defines rel="create" (expects 201)
# But application returns 200 for creates
# Result: ValidationError because @validators[200] is nilProposed Solutions
Option 1: Flexible Status Code Ranges
Accept multiple valid status codes per relation type:
def acceptable_statuses(rel)
case rel
when "create" then [200, 201]
when "empty" then [200, 202, 204]
else [200]
end
endOption 2: Fallback Validation
Try exact status first, then fall back to common success codes:
validator = @validators[status] || @validators[200] || @validators.values.firstOption 3: Configuration Flag
Add strict_status_codes option to allow users to choose validation strictness.