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

Ability to perform custom calculations on referenced fields #1807

Closed
mgildea opened this issue May 11, 2019 · 0 comments
Closed

Ability to perform custom calculations on referenced fields #1807

mgildea opened this issue May 11, 2019 · 0 comments
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@mgildea
Copy link

mgildea commented May 11, 2019

Describe the problem you are trying to fix (provide as much context as possible)

I am trying to validate the min and max number of elements based on the value of a referenced field, where the min is greater than or equal the value of the referenced field, and the max is less than or equal to TWICE the value of the referenced field.

It's possible I'm missing something in the APIs which would achieve this functionality; I have not figured out how to to do this.

Which API (or modification of the current API) do you suggest to solve that problem ?

for this specific problem, one might modify or overload the min and max functions in the array api, but I believe a feature like this should be applied to all/most "comparing" functions

It would be nice if these methods also accepted a function to perform a custom calculation that resolved to the originally expected input type.

Example might be:

schema : {
        daysPerWeek: Joi.number()
          .integer()
          .min(3)
          .max(7),
        movements: Joi.array()
          .min(Joi.ref("daysPerWeek"))
          .max(Joi.ref("daysPerWeek"), value => {
            return value * 2;
          })
          .items(Joi.string())
}

I believe this enable functionality to validate against some external resource as well.

Are you ready to work on a pull request if your suggestion is accepted ?

Yes

@hueniverse hueniverse self-assigned this Jun 2, 2019
@hueniverse hueniverse added the feature New functionality or improvement label Jun 2, 2019
@hueniverse hueniverse added this to the 16.0.0 milestone Jun 2, 2019
@hueniverse hueniverse added the v16 label Aug 10, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 6, 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

2 participants