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

fix(oneOf): return Result when running imperatively #999

Merged
merged 3 commits into from
May 7, 2021

Conversation

fedeci
Copy link
Member

@fedeci fedeci commented Feb 26, 2021

Description

Fixes #995

Note that the ResultWithContext of a ValidationChain and oneOf is slightly different.

// body('foo').isString().run({ req: { foo: 'foo' } })
ResultWithContext {
  formatter: [Function (anonymous)],
  errors: [
    {
      value: 'foo',
      msg: 'Invalid value',
      param: 'foo',
      location: 'body'
    }
  ],
  context: Context {
    fields: [ 'foo' ],
    locations: [ 'body' ],
    stack: [ [StandardValidation] ],
    optional: false,
    message: undefined,
    _errors: [ [Object] ],
    dataMap: Map(1) { 'body:foo' => [Object] }
  }
}
// oneOf([body('foo').isString()]).run({ req: { foo: 'foo' } })
ResultWithContext {
  formatter: [Function (anonymous)],
  errors: [
    { msg: 'Invalid value(s)', param: '_error', nestedErrors: [Array] }
  ],
  context: Context {
    fields: [],
    locations: [],
    stack: [ [Object] ],
    optional: false,
    message: undefined,
    _errors: [ [Object] ],
    dataMap: Map(0) {}
  }
}

edit: no longer after e5e492a

To-do list

  • I have added tests for what I changed.
  • This pull request is ready to merge.

@coveralls
Copy link

coveralls commented Feb 26, 2021

Coverage Status

Coverage remained the same at 100.0% when pulling e5e492a on fedeci:fix-one-of-imperatively into 735d76a on express-validator:master.

Copy link
Member

@gustavohenke gustavohenke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we lie a bit and say that we only return a Result instead?

@fedeci
Copy link
Member Author

fedeci commented Mar 16, 2021

Yes, it makes sense.

@fedeci fedeci changed the title fix(oneOf): return ResultWithContext when running imperatively fix(oneOf): return Result when running imperatively Apr 21, 2021
@bmax
Copy link

bmax commented Apr 29, 2021

Looking forward to this thank you @fedeci @gustavohenke

@fedeci fedeci merged commit 2a4ad43 into express-validator:master May 7, 2021
@fedeci fedeci deleted the fix-one-of-imperatively branch May 7, 2021 14:13
@gustavohenke
Copy link
Member

This is fixed on v6.11.0 🚀

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

Successfully merging this pull request may close these issues.

Getting "undefined" error when running validations imperatively with "oneOf"
4 participants