-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Thoughts on something like any.meta(obj)? #241
Comments
How do you expect to extract this information afterwards? |
Couple of options. The first (in keeping with tags and notes) would be to just make it an attribute on the object returned by I think the idea itself is valuable, but I'm not particularly opinionated on how it should be implemented. If you think it's useful but not critical I can try my hand at the implementation once a pattern is settled on. |
I am not a fan of functions returning completely different types of data based on arguments count. We can use |
Hrmm, in that case, we can still do:
|
The problem is that if you put meta on nested keys, it becomes hard to get to that without building the entire description tree. I need to think about it some more. |
+1 on a shallow describe analog to access the info for a single schema without recursion. |
I think a shallow describe option makes a lot of sense. It allows you to determine whether or not you care about metadata on nested keys. The cost of describe I assume is primarily in building the full tree, so the most direct solution is to allow the end user to choose whether or not they require that. |
I'm trying my hand at implementing this now since I require the functionality. @hueniverse Would you prefer that meta be cumulative (as tags is) through extension, or that the last call to meta overwrite the previous ones? I'll implement that latter first since it's marginally simpler and seems like an edge case, but I'll defer to whatever you prefer in the PR. |
Also, in the clone method, would you like meta to be shallow/deep copied? Or is a direct reference acceptable? |
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. |
This is conceptually similar to
any.tags()
,any.notes()
, andany.description()
, but allows the storage of an object rather than a string. This is valuable because, besides annotating the schemas, it allows us to build modules on Joi that provide additional functionality. Example use case:This can currently be accomplished using
tags()
, but it requires string parsing and complicates the logic of actually retrieving the metadata. E.g.The benefit of an
any.meta()
is similar to that of the existing description functions -- the metadata is stored consistently and doesn't need to worry about clobbering / being clobbered by Joi's moving parts.Cheers,
Josh
The text was updated successfully, but these errors were encountered: