• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PayU / openapi-validator-middleware / 3632820362

pending completion
3632820362

Pull #188

github

GitHub
Merge 6a1acf7ae into 1effab313
Pull Request #188: Bump qs from 6.5.2 to 6.5.3

51 of 54 branches covered (94.44%)

Branch coverage included in aggregate %.

87 of 87 relevant lines covered (100.0%)

105.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.28
/src/inputValidationError.js
1
'use strict';
2

3
/**
4
 * Represent an input validation error
5
 * errors field will include the `ajv` error
6
 * @class InputValidationError
7
 * @extends {Error}
8
 */
9
class InputValidationError extends Error {
10
    constructor(errors, options = {}) {
×
11
        super('Input validation error');
226✔
12

13
        if (options.beautifyErrors && options.firstError) {
226✔
14
            this.errors = parseAjvError(errors[0]);
67✔
15
        } else if (options.beautifyErrors) {
159✔
16
            this.errors = parseAjvErrors(errors);
49✔
17
        } else {
18
            this.errors = errors;
110✔
19
        }
20
    }
21
}
22

23
const parseAjvError = function(error) {
1✔
24
    return `${buildDataPath(error)} ${buildMessage(error)}`;
143✔
25
};
26

27
const parseAjvErrors = function(errors) {
1✔
28
    return errors.map(parseAjvError);
49✔
29
};
30

31
const buildMessage = function(error){
1✔
32
    if (error.keyword === 'enum') {
143✔
33
        return `${error.message} [${error.params.allowedValues.toString()}]`;
29✔
34
    }
35

36
    if (error.keyword === 'additionalProperties') {
114✔
37
        return `${error.message} '${error.params.additionalProperty.toString()}'`;
7✔
38
    }
39

40
    if (error.validation) {
107✔
41
        return error.errors.message;
7✔
42
    }
43

44
    return error.message;
100✔
45
};
46

47
const buildDataPath = function(error) {
1✔
48
    if (error.dataPath.startsWith('.header')) {
143✔
49
        return error.dataPath
22✔
50
            .replace('.', '')
51
            .replace('[', '/')
52
            .replace(']', '')
53
            .replace('\'', '')
54
            .replace('\'', '');
55
    }
56

57
    if (error.dataPath.startsWith('.path')) {
121✔
58
        return error.dataPath
6✔
59
            .replace('.', '')
60
            .replace('.', '/');
61
    }
62

63
    if (error.dataPath.startsWith('.query')) {
115✔
64
        return error.dataPath
18✔
65
            .replace('.', '')
66
            .replace('.', '/');
67
    }
68

69
    if (error.dataPath.startsWith('.')) {
97✔
70
        return error.dataPath.replace('.', 'body/');
45✔
71
    }
72

73
    if (error.dataPath.startsWith('[')) {
52✔
74
        return `body/${error.dataPath}`;
12✔
75
    }
76

77
    if (error.dataPath === '') {
40✔
78
        return 'body';
39✔
79
    }
80

81
    return undefined;
1✔
82
};
83

84
module.exports = InputValidationError;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc