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

Consider renaming 'valid' to 'enum' or an alias #536

Closed
capaj opened this issue Jan 24, 2015 · 12 comments
Closed

Consider renaming 'valid' to 'enum' or an alias #536

capaj opened this issue Jan 24, 2015 · 12 comments
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@capaj
Copy link

capaj commented Jan 24, 2015

I think that the method 'valid' which allows to specify/ENUMERATE the allowed values should be renamed to enum.
Reasons?
For someone new who hasn't memoired the API yet, 'valid' can be confused with the actual validation, also 'enum' is a term known in many type-safe languages which means exactly this and Mongoose uses it too. Googling joi valid doesn't yield anything related to enumerations, because Google is picking all the mentions of Joi.validate method.
Last, but not least when teaching someone and dictating code it can get confusing-especially for people from foreign countries.

Joi.number().valid('a').validate('a');         
Joi.number().enum('a').validate(3);           

Or just create an alias 'enum'?
I haven't used Joi very extensively yet, but I think there should not be a problem to just deprecate 'valid' and add enum() from next major version.

@Marsup
Copy link
Collaborator

Marsup commented Jan 26, 2015

I'm not really convinced by your arguments, I'll let it open to see if other people have similar opinion. What would be the opposite of enum (invalid)?

@Marsup Marsup added the request label Jan 26, 2015
@kanongil
Copy link
Contributor

I don't know about the language issue, but from the naming I would expect valid to do the same as allow does. The name enum better communicates the exclusion of other values.

As for invalid, the actual function can also be considered the opposite of allow, so I guess disallow would work.

@capaj
Copy link
Author

capaj commented Jan 26, 2015

@kanongil allow and disallow would be better then valid/valid, If not enum, I would be for these names for those methods.
👍

@AdriVanHoudt
Copy link
Contributor

Would something like only (for valid/enum) and except (for not-enum/invalid/disallow) work?
only to me is pretty clear to what it does. except maybe not so much but it is more aligned to only.
And for the record I, to, think allow and valid look the same for someone new (like me).

@jamlen
Copy link

jamlen commented Feb 11, 2015

I like allow and disallow, but then I also think that only is very clear. I don't mind except but how about exclude?

@AdriVanHoudt
Copy link
Contributor

I favor exclude over except 👍

@Marsup
Copy link
Collaborator

Marsup commented Feb 21, 2015

So let me sum this up :

  • allow remains allow
  • valid is aliased to only
  • invalid is aliased to disallow

Is everyone OK with this or do we still need to debate that last one ?

@Marsup Marsup self-assigned this Feb 21, 2015
@Marsup Marsup added this to the 6.0.0 milestone Feb 21, 2015
@capaj
Copy link
Author

capaj commented Feb 21, 2015

Love it. I expected this issue to be closed as irrelevant. I am truly glad that you accepted it and acted on it. :+1

@AdriVanHoudt
Copy link
Contributor

👍

@Marsup Marsup closed this as completed in 2bfe9d8 Feb 22, 2015
@boneskull
Copy link

@Marsup Would you be opposed to a PR which modifies the documentation for valid to use the word "enumeration" somewhere? I was searching README.md for "enumeration" -- would have saved me a trip to a search engine.

@Marsup
Copy link
Collaborator

Marsup commented May 24, 2015

OK, just an aka somewhere would do.

@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

7 participants