Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit c830ff6

Browse files
fix: adjusts namespaces and call signatures of "isValid" utils
1 parent 7870a99 commit c830ff6

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

lib/units/isValid.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
function isValidComponent(errors) {
1+
/**
2+
* Concludes HTTP message's component validity based on the given
3+
* list of validation errors.
4+
* @param {Object<string, any>} errors
5+
* @returns {boolean}
6+
*/
7+
function isValidField({ errors }) {
28
return errors.length === 0;
39
}
410

5-
// Returns a boolean indicating whether a given validation result
6-
// concludes two HTTP messages as valid (matching).
7-
// Separated into its own util only to be used in both next and legacy API.
8-
function isValid(validationResult) {
9-
return Object.values(validationResult.fields).every((resultGroup) => {
10-
return isValidComponent(resultGroup.errors);
11-
});
11+
/**
12+
* Returns a boolean indicating the given validation result as valid.
13+
* @param {Object<string, any>} validationResult
14+
* @returns {boolean}
15+
*/
16+
function isValidResult(validationResult) {
17+
return Object.values(validationResult.fields).every(isValidField);
1218
}
1319

14-
module.exports = { isValid, isValidComponent };
20+
module.exports = {
21+
isValidResult,
22+
isValidField
23+
};

lib/units/validateBody.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const mediaTyper = require('media-typer');
33
const contentTypeUtils = require('content-type');
44

55
const { TextDiff, JsonExample, JsonSchema } = require('../validators');
6-
const { isValidComponent } = require('./isValid');
6+
const { isValidField } = require('./isValid');
77

88
function isPlainText(mediaType) {
99
return mediaType.type === 'text' && mediaType.subtype === 'plain';
@@ -214,7 +214,7 @@ function validateBody(expected, real) {
214214
errors.push(...validationErrors);
215215

216216
return {
217-
isValid: isValidComponent(errors),
217+
isValid: isValidField({ errors }),
218218
validator: ValidatorClass && ValidatorClass.name,
219219
realType: mediaTyper.format(realType),
220220
expectedType: mediaTyper.format(expectedType),

lib/units/validateHeaders.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { HeadersJsonExample } = require('../validators');
2-
const { isValidComponent } = require('./isValid');
2+
const { isValidField } = require('./isValid');
33

44
const APIARY_JSON_HEADER_TYPE = 'application/vnd.apiary.http-headers+json';
55

@@ -42,7 +42,7 @@ and expected data media type
4242
}
4343

4444
return {
45-
isValid: isValidComponent(errors),
45+
isValid: isValidField({ errors }),
4646
validator: validator && 'HeadersJsonExample',
4747
realType,
4848
expectedType,

lib/validate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const isset = require('./utils/isset');
22
const { coerce, coerceWeak } = require('./units/coerce');
33
const { normalize } = require('./units/normalize');
4-
const { isValid } = require('./units/isValid');
4+
const { isValidResult } = require('./units/isValid');
55
const { validateMethod } = require('./units/validateMethod');
66
const { validateURI } = require('./units/validateURI');
77
const { validateStatusCode } = require('./units/validateStatusCode');
@@ -47,7 +47,7 @@ function validate(expectedMessage, realMessage) {
4747
}
4848

4949
// Indicates the validity of the real message
50-
result.isValid = isValid(result);
50+
result.isValid = isValidResult(result);
5151

5252
return result;
5353
}

0 commit comments

Comments
 (0)