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

Possible formats conflict #179

Open
ikokostya opened this issue Dec 1, 2016 · 2 comments
Open

Possible formats conflict #179

ikokostya opened this issue Dec 1, 2016 · 2 comments

Comments

@ikokostya
Copy link

ikokostya commented Dec 1, 2016

Problem

Currently z-schema uses one shared storage for all custom formats. There are two possible errors:

  • Different instances of validator can't use different formats with the same name.
  • User can unexpectedly get format which was registered in another npm module, because npm v3 try to install dependencies without nesting.

Suggestion

  • Add solution when custom format can be registered per validator instance.

  • Deprecate global registration of custom formats. If user wants to use same format in different validator instances, it can safely create factory:

    function createSchemaValidator() {
        var validator = new ZSchema();
        // Register common formats
        validator.registerFormat(...);
        return validator;
    }
    
    var validator1 = createSchemaValidator();
    var validator2 = createSchemaValidator();
@ikokostya
Copy link
Author

@zaggino What do you think?

@zaggino
Copy link
Owner

zaggino commented Dec 3, 2016

👍 agree with you, if you'll open a PR with tests passing i'll merge it

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

No branches or pull requests

2 participants