response method
Validates the response body of operationId with status; a status the operation does
not list is a violation.
Implementation
List<ContractViolation> response(
String operationId,
int status,
Object? body,
) {
final responses = operation(operationId).responseSchemas;
final key = responses.containsKey('$status')
? '$status'
: responses.containsKey('${status ~/ 100}XX')
? '${status ~/ 100}XX'
: responses.containsKey('default')
? 'default'
: null;
if (key == null) {
return [ContractViolation('', 'invalid', 'status $status not listed')];
}
final schema = responses[key];
if (schema == null) {
return body == null
? const []
: const [ContractViolation('', 'invalid', 'no body expected')];
}
return validate(body, schema);
}