Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing list of additional properties, when additionalProperties error is thrown #58

Closed
medolino opened this issue Oct 2, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@medolino
Copy link
Contributor

medolino commented Oct 2, 2019

When additionalProperties validation fails, following error is thrown:

{
   stack: 'Error: request.body should NOT have additional properties\n  at Object.POST-/api/....\n',
   message: 'request.body should NOT have additional properties',
   toJSON:[
      Function:toJSON
   ],
   status: 400,
   errors: [
      {
         path:'.body',
         message:'should NOT have additional properties',
         errorCode:'additionalProperties.openapi.validation'
      }
   ],
   name: 'Error',
   toString: [
      Function:toString
   ]
}

Is there any chance to add a list of additional properties to error message. It would be really helpfull to know, which properties should be removed from payload.

Information about additional properties is available in validator.errors array, generated by ajv validator (

const errors = [...(validator.errors || [])];
), but gets lost while creating customized error by calling ajvErrorsToValidatorError util function (
export function ajvErrorsToValidatorError(status, errors) {
).

Avj validation errors:

[
   {
      keyword: 'additionalProperties',
      dataPath: '.body',
      schemaPath: '#/components/schemas/CreateItem/additionalProperties',
      params: {
         additionalProperty: 'invalidProperty'
      },
      message: 'should NOT have additional properties'
   }
]

Customized error object provided by ajvErrorsToValidatorError:

{
   status:400,
   errors:[
      {
         path:'.body',
         message:'should NOT have additional properties',
         errorCode:'additionalProperties.openapi.validation'
      }
   ]
}
@cdimascio
Copy link
Owner

cdimascio commented Oct 2, 2019

Yes we should definitely make this available.
I'm away until next week. I will plan to look at this then. If someone contributes a fix in the meantime I'll certainly have a look.

Thanks for the issue, @medolino

@cdimascio cdimascio added the enhancement New feature or request label Oct 2, 2019
cdimascio added a commit that referenced this issue Oct 2, 2019
Missing list of additional properties, when additionalProperties error is thrown #58
@cdimascio
Copy link
Owner

cdimascio commented Oct 2, 2019

@medolino instead of making the change next week, ive completed it today. check out v2.3.0
The path for each additionalProperty error will contain the offending field name; similar to required

@medolino
Copy link
Contributor Author

medolino commented Oct 3, 2019

@cdimascio, it works great! Thanks for the quick response and resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants