z-schema icon indicating copy to clipboard operation
z-schema copied to clipboard

discuss: Custom formats are module-scoped

Open whitlockjc opened this issue 6 years ago • 4 comments

What was the reasoning behind making ZSchema.registerFormat instead of validator.registerFormat? As it stands right now, using multiple ZSchema instances in the same process with different custom formats is impossible because the registry of custom formats is stored in the ZSchema module itself, not in the ZSchema instance. Before I blindly ask for, or submit a PR to, make the custom formats scoped to the ZSchema instance, I wanted to better understand.

whitlockjc avatar Jun 19 '18 21:06 whitlockjc

The only thing that pops to my mind years after writing this is that I never expected a conflict. If you have a format xxx meaning one thing and format xxx meaning other thing within one application, something smells very weird?

zaggino avatar Jun 25 '18 23:06 zaggino

Don't think of it in terms of conflicts in how a format is handled but in terms of different validators (dis)allowing different formats. Maybe I'm just writing tests that are too strict but since I wrap z-schema, I typically start a test where I register a format by using z-schema in a way where the format hasn't been registered, asserting that there was a failure, registering the format with my API and then running the same test to ensure there was no failure.

Where this becomes an issue is when I create a new ZSchema in between test runs. If I run a pre/post registration test flow more than once, the second set of tests fail unless I use a unique format name for each set of tests.

whitlockjc avatar Jun 25 '18 23:06 whitlockjc

Yeah, in this case, that's bad. It probably should have lived on the instance, not the class. I don't see a downside in changing that with a PR.

zaggino avatar Jun 26 '18 05:06 zaggino

I'll get started.

whitlockjc avatar Jun 26 '18 15:06 whitlockjc