You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Package type: module (native node ESM ending in .js)
Feature
Allow access to response param in errorTransformer so the error can be more informative. As a work-around I overwrite the validateResponse method to 'cache' the last response on validator.lastTarget, so I can log the erroneous value together with the rest of the error:
constvalidator=newOpenAPIResponseValidator({
components,responses: {'200': components.responses.Data},definitions: components.schemas,errorTransformer: function(openapiError,ajvError){constkeypath=openapiError.path.replace(/\//g,'.')constpathparts=keypath.split('.')letvalue=validator.lastTargetfor(leti=0;i<pathparts.length;i++){if(!value)breakvalue=value[pathparts[i]]}return`Error: Target ${keypath}${openapiError.message}. Target ${keypath} value is: ${JSON.stringify(value,null,2)}`}})// overwrite and store last validated target for error reportingvalidator.validateResponse=function(statusCode,context){validator.lastTarget=contextreturnOpenAPIResponseValidator.default.prototype.validateResponse.call(this,statusCode,context)}console.log(validator.validateResponse(invalidData))// {// message: 'The response was not valid.',// errors: [// 'Error: Target data.items.2.instance must be object. Target data.items.2.instance value is: true'// ]// }
The text was updated successfully, but these errors were encountered:
Context
.js
)Feature
Allow access to response param in errorTransformer so the error can be more informative. As a work-around I overwrite the
validateResponse
method to 'cache' the last response onvalidator.lastTarget
, so I can log the erroneous value together with the rest of the error:The text was updated successfully, but these errors were encountered: