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

Type casting to ObjectID? #2

Open
craigspaeth opened this issue Feb 18, 2015 · 9 comments
Open

Type casting to ObjectID? #2

craigspaeth opened this issue Feb 18, 2015 · 9 comments

Comments

@craigspaeth
Copy link

Joi does implicit type casting for things like Date. I find myself wanting this plugin to type cast a 24 char alphanumeric string into a require('mongodb').ObjectID. I'm not sure if it makes sense to include mongodb-native as a dependency of this project to do that, but I thought I would throw the idea out there.

If that sounds like something you're interested in I would be happy to submit a pull request for it.

@aheckmann
Copy link
Collaborator

maybe we could just include the bson module?

@devinus
Copy link

devinus commented Feb 24, 2015

I would really like this.

@olistic
Copy link

olistic commented Feb 25, 2015

I've just created a pull request in joi which would cover exactly what you are asking. The PR wasn't merged because of the added BSON dependency. However, you might find a way to reutilise the code in this plugin.

https://github.com/hapijs/joi/pull/563/commits

@aheckmann
Copy link
Collaborator

is it not possible to put that logic in this module? my thinking is that Hapi shouldn't need to care about validating everyone's custom types itself and instead should provide the APIs which we can hook into. separation of concerns

@olistic
Copy link

olistic commented Feb 25, 2015

I think that it is not possible as things are right now. I totally agree with you in that an API which we can hook into would be an awesome enhancement to joi.

@morfj
Copy link

morfj commented Apr 14, 2015

I didn't start using Joi for its pretty syntax (there are validators with more compact/prettier syntaxes out there) but because it also provided typecasting/parsing of types to create proper DTOs from the input. As it stands, this plugin is rather half-done IMHO. It needs to support type-casting!

@aheckmann
Copy link
Collaborator

SGTM. anyone want to open a quick PR with tests?

@olistic
Copy link

olistic commented Apr 14, 2015

I'm in. Will start working on this.

@jlai
Copy link
Contributor

jlai commented Apr 14, 2015

FYI, joi is working on a way to officially support plugins/extensibility (actively being discussed): hapijs/joi#577

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

No branches or pull requests

6 participants