don't validate 400 request body or query params

Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
aramissennyeydd
2024-07-07 16:39:10 -04:00
parent f63ad78082
commit ea8ffdb9dc
2 changed files with 7 additions and 2 deletions
@@ -39,7 +39,7 @@ export function mockttpToFetchResponse(response: CompletedResponse) {
export function humanifyAjvError(error: ErrorObject) {
switch (error.keyword) {
case 'required':
return `The ${error.params.missingProperty} property is required`;
return `The "${error.params.missingProperty}" property is required`;
case 'type':
return `${
error.instancePath ? `"${error.instancePath}"` : 'Value'
@@ -33,7 +33,12 @@ class RequestBodyValidator implements Validator {
}
async validate({ pair, operation }: ValidatorParams) {
const { request } = pair;
const { request, response } = pair;
if (response.statusCode === 400) {
// If the response is a 400, then the request is invalid and we shouldn't validate the parameters
return;
}
// NOTE: There may be a worthwhile optimization here to cache these results to avoid re-parsing the schema for every request. As is, I don't think this is a big deal.
const parser = RequestBodyParser.fromOperation(operation, { ajv });
const fetchRequest = mockttpToFetchRequest(request);