tlivings / enjoi

Converts a JSON schema to a Joi schema.
Apache License 2.0
282 stars 56 forks source link

allow extension constructors #100

Closed nlundquist closed 3 years ago

nlundquist commented 3 years ago

While using Enjoi (latest) recently I ran into a bug. Joi (17.3.0) modifies passed extension rule objects so they include the argsByName key, however this additional key means they no longer are valid extension objects.

Due to this, passing the same set of extensions (must include an extension with rule arguments) to Enjoi will fail with a validation error during the second usage.

Opened an issue for this here: https://github.com/sideway/joi/issues/2514

The easiest way to avoid this is to pass extension constructor functions that return a new instance of the extension each time rather than passing a reused set of objects. However Enjoi's validation required this change to allow extension constructor functions.