Skip to content

Conversation

@HCanber
Copy link
Contributor

@HCanber HCanber commented Nov 5, 2018

Previous functionality

In 0.3.0 - 0.6.10 the returned function from compile looked like this:

function(obj, _schema, pathStack)

0.3.0: https://github.com/icebob/fastest-validator/blob/v0.3.0/lib/validator.js#L128
0.6.10: https://github.com/icebob/fastest-validator/blob/v0.6.10/lib/validator.js#L169

_schema was never used but pathStack was, so it was possible to provide a custom path from code:

const v = new Validator()
const validate =  v.compile(schema)
const result = validate(myObject, null, 'custom.path')

The custom path was used in error messages and also become part of the path forwarded to custom validators, so they could use that info when validating.

Current functionality: Breaking change

In 0.6.11 this was changed to:

function(value)

This was breaking change and broke some of our tests, where we use fastest-validator to validate parts of the objects. Custom validators that relies on path in the same way as the example above are used. Currently we have locked to use version 0.6.10

Restored functionality

This PR brings back the 0.6.10 functionality, however; As a breaking change already was introduced in 0.6.11, instead of restoring 0.6.10 functionality as it was (with an unused _schema argument) the returned function now looks like this.

function(value, path, parent)

So it's still a breaking change to what 0.6.10 looked like, but at least it makes it possible, after changing calls from validate(myObject, null, 'custom.path') to validate(myObject, 'custom.path'), to provide custom paths.

Tests

Tests have been added that verifies

  • that path, and when calling compile with schemas in an array: parent is used.
  • that calling the returned checker, without path and parent, still works.

To be clear: This PR introduces no breaking changes to 0.6.12

This was possible in v0.3.0-v0.6.10 but removed in v0.6.11
@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 100.0% when pulling 691887f on HCanber:compile-fix into d4efae5 on icebob:master.

Copy link
Owner

@icebob icebob left a comment

Choose a reason for hiding this comment

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

Thank you!

@icebob icebob merged commit 274fe00 into icebob:master Nov 5, 2018
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

Successfully merging this pull request may close these issues.

3 participants