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

Prevent mixing different versions of joi schema types #1913

Closed
kanongil opened this issue Jun 19, 2019 · 1 comment
Closed

Prevent mixing different versions of joi schema types #1913

kanongil opened this issue Jun 19, 2019 · 1 comment
Assignees
Labels
breaking changes Change that can breaking existing code
Milestone

Comments

@kanongil
Copy link
Contributor

Context

  • joi version: @hapi/joi@16.0.0-rc2 & joi@14.3.1

What are you trying to achieve or the steps to reproduce ?

Validate old schema:

const Joi = require('@hapi/joi');
const Joi14 = require('joi');

const schema = Joi14.number();

console.log(Joi.validate(1, schema));

Which result you had ?

/Users/gil/test/joi/node_modules/@hapi/joi/lib/cast.js:73
        throw err;
        ^

AssertionError [ERR_ASSERTION]: Cannot add other alternatives without at least one schema(_tests)
    at new AssertionError (internal/assert.js:269:11)
    at Object.exports.assert (/Users/gil/test/joi/node_modules/@hapi/hoek/lib/index.js:592:11)
    at internals.Alternatives.try (/Users/gil/test/joi/node_modules/@hapi/joi/lib/types/alternatives.js:104:14)
    at Object.exports.schema (/Users/gil/test/joi/node_modules/@hapi/joi/lib/cast.js:31:42)
    at internals.Object.keys (/Users/gil/test/joi/node_modules/@hapi/joi/lib/types/object.js:401:35)
    at Object.exports.schema (/Users/gil/test/joi/node_modules/@hapi/joi/lib/cast.js:42:29)
    at Object.internals.appendPath (/Users/gil/test/joi/node_modules/@hapi/joi/lib/cast.js:66:24)
    at Object.exports.schema (/Users/gil/test/joi/node_modules/@hapi/joi/lib/cast.js:15:26)
    at module.exports.internals.Any.root.compile (/Users/gil/test/joi/node_modules/@hapi/joi/lib/index.js:176:21)
    at module.exports.internals.Any.root.validate (/Users/gil/test/joi/node_modules/@hapi/joi/lib/index.js:161:29)

What did you expect ?

Either a successful validation by calling into the old joi logic, or a more descriptive thrown error.

Note that this is the way that Hapi currently validates schemas in routes, causing such an error whenever an old schema is passed.

@hueniverse
Copy link
Contributor

I am going to change the way hapi uses joi to compile provided schemas. This has been a PITA for a long time, requiring breaking hapi releases for joi updates.

@hueniverse hueniverse changed the title v16 Joi.validate() fails hard with old schema Prevent mixing different versions of joi schema types Jun 22, 2019
@hueniverse hueniverse self-assigned this Jun 22, 2019
@hueniverse hueniverse added the breaking changes Change that can breaking existing code label Jun 22, 2019
@hueniverse hueniverse added this to the 16.0.0 milestone Jun 22, 2019
@hueniverse hueniverse added the v16 label Aug 11, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking changes Change that can breaking existing code
Projects
None yet
Development

No branches or pull requests

2 participants