Skip to content

Commit

Permalink
fixup!: apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jannyHou committed Jun 29, 2020
1 parent b545786 commit 7bf25e4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/rest/src/coercion/coerce-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async function coerceObject(
) {
const data = parseJsonIfNeeded(input, spec);

if (data === undefined || data === null) {
if (data == null) {
// Skip any further checks and coercions, nothing we can do with `undefined`
return data;
}
Expand All @@ -185,7 +185,7 @@ async function coerceObject(
data,
schema,
{},
{...options, coerceTypes: true, position: 'parameter'},
{...options, coerceTypes: true, source: 'parameter'},
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export interface ValueValidationOptions extends RequestBodyValidationOptions {
* Where the data comes from. It can be 'body', 'path', 'header',
* 'query', 'cookie', etc...
*/
position?: string;
source?: string;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/rest/src/validation/request-body.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function validateRequestBody(
options = {coerceTypes: !!body.coercionRequired, ...options};
await validateValueAgainstSchema(body.value, schema, globalSchemas, {
...options,
position: 'body',
source: 'body',
});
}

Expand Down Expand Up @@ -155,7 +155,7 @@ export async function validateValueAgainstSchema(
const validationResult = await validate(value);
// When value is optional & values is empty / null, ajv returns null
if (validationResult || validationResult === null) {
debug('Value passed AJV validation.');
debug(`Value from ${options.source} passed AJV validation.`);
return;
}
} catch (error) {
Expand All @@ -176,7 +176,7 @@ export async function validateValueAgainstSchema(
}

// Throw invalid request body error
if (options.position === 'body') {
if (options.source === 'body') {
const error = RestHttpErrors.invalidRequestBody();
addErrorDetails(error, validationErrors);
throw error;
Expand Down

0 comments on commit 7bf25e4

Please sign in to comment.