This repository was archived by the owner on Nov 8, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +24
-15
lines changed Expand file tree Collapse file tree 4 files changed +24
-15
lines changed Original file line number Diff line number Diff line change 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 } ) {
2
8
return errors . length === 0 ;
3
9
}
4
10
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 ) ;
12
18
}
13
19
14
- module . exports = { isValid, isValidComponent } ;
20
+ module . exports = {
21
+ isValidResult,
22
+ isValidField
23
+ } ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ const mediaTyper = require('media-typer');
3
3
const contentTypeUtils = require ( 'content-type' ) ;
4
4
5
5
const { TextDiff, JsonExample, JsonSchema } = require ( '../validators' ) ;
6
- const { isValidComponent } = require ( './isValid' ) ;
6
+ const { isValidField } = require ( './isValid' ) ;
7
7
8
8
function isPlainText ( mediaType ) {
9
9
return mediaType . type === 'text' && mediaType . subtype === 'plain' ;
@@ -214,7 +214,7 @@ function validateBody(expected, real) {
214
214
errors . push ( ...validationErrors ) ;
215
215
216
216
return {
217
- isValid : isValidComponent ( errors ) ,
217
+ isValid : isValidField ( { errors } ) ,
218
218
validator : ValidatorClass && ValidatorClass . name ,
219
219
realType : mediaTyper . format ( realType ) ,
220
220
expectedType : mediaTyper . format ( expectedType ) ,
Original file line number Diff line number Diff line change 1
1
const { HeadersJsonExample } = require ( '../validators' ) ;
2
- const { isValidComponent } = require ( './isValid' ) ;
2
+ const { isValidField } = require ( './isValid' ) ;
3
3
4
4
const APIARY_JSON_HEADER_TYPE = 'application/vnd.apiary.http-headers+json' ;
5
5
@@ -42,7 +42,7 @@ and expected data media type
42
42
}
43
43
44
44
return {
45
- isValid : isValidComponent ( errors ) ,
45
+ isValid : isValidField ( { errors } ) ,
46
46
validator : validator && 'HeadersJsonExample' ,
47
47
realType,
48
48
expectedType,
Original file line number Diff line number Diff line change 1
1
const isset = require ( './utils/isset' ) ;
2
2
const { coerce, coerceWeak } = require ( './units/coerce' ) ;
3
3
const { normalize } = require ( './units/normalize' ) ;
4
- const { isValid } = require ( './units/isValid' ) ;
4
+ const { isValidResult } = require ( './units/isValid' ) ;
5
5
const { validateMethod } = require ( './units/validateMethod' ) ;
6
6
const { validateURI } = require ( './units/validateURI' ) ;
7
7
const { validateStatusCode } = require ( './units/validateStatusCode' ) ;
@@ -47,7 +47,7 @@ function validate(expectedMessage, realMessage) {
47
47
}
48
48
49
49
// Indicates the validity of the real message
50
- result . isValid = isValid ( result ) ;
50
+ result . isValid = isValidResult ( result ) ;
51
51
52
52
return result ;
53
53
}
You can’t perform that action at this time.
0 commit comments