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

Improve validation error context #90

Open
delaguilaluis opened this issue Sep 19, 2017 · 0 comments
Open

Improve validation error context #90

delaguilaluis opened this issue Sep 19, 2017 · 0 comments

Comments

@delaguilaluis
Copy link

If a validation error happens, I would like to know the location of the parameter. e.g.header, query, path, body.

Also I would like the context.key to have the right key name instead of 'value'.

The desired result would contain the parameter location under context.location and the right key name under context.key. I've done a local experiment and achieved the desired results by adding this after L129 of lib/validator.js:

detail.context.key = parameter.name;
detail.context.location = parameter.in;
  • Current result:
{
  ValidationError: "Authorization" is required
  // Stacktrace goes here
  name: 'ValidationError',
  details: [
    {
      message: '"Authorization" is required',
      path: 'Authorization',
      type: 'any.required',
      context: {
        key: 'value'
      }
    }
  ],
  _object: undefined,
  annotate: [Function],
  status: 400
}
  • Desired result:
{
  ValidationError: "Authorization" is required
  // Stacktrace goes here
  name: 'ValidationError',
  details: [
    {
      message: '"Authorization" is required',
      path: 'Authorization',
      type: 'any.required',
      context: {
        key: 'Authorization',
        location: 'header'
      }
    }
  ],
  _object: undefined,
  annotate: [Function],
  status: 400
}

Please let me know what do you think. I hope to be making a related PR soon. 😄

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

No branches or pull requests

1 participant