-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from postmanlabs/release/1.1.13
Release/1.1.13
- Loading branch information
Showing
17 changed files
with
1,017 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var _ = require('lodash'); | ||
|
||
/** | ||
* This function generates reason and reasonCodes (used in mismatch objects) using Ajv Validation Error | ||
* | ||
* @param {Object} ajvValidationErrorObj Ajv Validation Error Object (reference: https://ajv.js.org/#validation-errors) | ||
* @param {Object} data data needed for generation of mismatch Object | ||
* | ||
* @returns {Object} mismatchObj with reason and reasonCode properties | ||
*/ | ||
function ajvValidationError(ajvValidationErrorObj, data) { | ||
var mismatchPropName = _.get(ajvValidationErrorObj, 'dataPath', '').slice(1), | ||
mismatchObj = { | ||
reason: `The ${data.humanPropName} property "${mismatchPropName}" ` + | ||
`${ajvValidationErrorObj.message}`, | ||
reasonCode: 'INVALID_TYPE' | ||
}; | ||
|
||
switch (ajvValidationErrorObj.keyword) { | ||
|
||
case 'additionalProperties': | ||
mismatchObj.reasonCode = 'MISSING_IN_SCHEMA'; | ||
break; | ||
|
||
case 'dependencies': | ||
mismatchObj.reason = `The ${data.humanPropName} property "${mismatchPropName}" ` + | ||
`should have property "${_.get(ajvValidationErrorObj, 'params.missingProperty')}" when property ` + | ||
`"${_.get(ajvValidationErrorObj, 'params.property')}" is present`; | ||
break; | ||
|
||
case 'required': | ||
mismatchObj.reasonCode = 'MISSING_IN_REQUEST'; | ||
mismatchObj.reason = `The ${data.humanPropName} property "${mismatchPropName}" should have required ` + | ||
`property "${_.get(ajvValidationErrorObj, 'params.missingProperty')}"`; | ||
break; | ||
|
||
case 'propertyNames': | ||
mismatchObj.reason = `The ${data.humanPropName} property "${mismatchPropName}" contains invalid ` + | ||
`property named "${_.get(ajvValidationErrorObj, 'params.propertyName')}"`; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
return mismatchObj; | ||
} | ||
|
||
module.exports = ajvValidationError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.