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

[✨ Feature Request]: Can we return an issues object on the custom dev defined validation pipeline methods? #161

Closed
demarchenac opened this issue Sep 15, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request priority This has priority

Comments

@demarchenac
Copy link

Hi @fabian-hiller!

I hope you're having a great day!

Ok, basically what I'm asking is if I could have a custom pipeline validation method to return multiple issues, why? you may ask.

So I can summarize common-wise validations within an object() schema such as:

const mySchema = object({
    field1: optional(string()),
    field2: optional(string()),
    field3: optional(string()),
    ...,
    fieldN: string(),
}, [
    (input) => {
        if(input.fieldN && !input?.field1){
            return { issue: {...} } // return some issue related to field1
        }
       return { output: input }
    },
    (input) => {
        if(input.fieldN && !input?.field2){
            return { issue: {...} } // return some issue related to field2
        }
       return { output: input }
    },
    (input) => {
        if(input.fieldN && !input?.field3){
            return { issue: {...} } // return some issue related to field3
        }
       return { output: input }
    },
])

into something more compact like:

const mySchema = object({
    field1: optional(string()),
    field2: optional(string()),
    field3: optional(string()),
    ...,
    fieldN: string(),
}, [
    (input) => {
        const issues = []

       ['field1', 'field2', 'field3'].forEach((fieldKey) => {
            if(input.fieldN && !input?.[fieldKey]){
                 issues.push({ issue: {...} }) // some issue related to fieldKey*
            }
       })

       return issues.length > 0 ? { issues } : { output: input }
    },
])

It's worth noting that this one was one basic example that I thought to explain the feature request, but it could be any kind of complex validations.

What do you think about this one?

@fabian-hiller fabian-hiller self-assigned this Sep 15, 2023
@fabian-hiller fabian-hiller added the enhancement New feature or request label Sep 15, 2023
@fabian-hiller
Copy link
Owner

Thank you for creating this issue! I plan to change issue to issues with the next version.

@fabian-hiller fabian-hiller added the priority This has priority label Sep 15, 2023
@fabian-hiller
Copy link
Owner

However, I recommend using our validation functions such as custom whenever possible. This usually makes the code more readable.

@demarchenac
Copy link
Author

Hey absolutely, this was just a silly example I came by to explain my feature request, thanks for working through this one! 👏🏻

@fabian-hiller
Copy link
Owner

The new version is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority This has priority
Projects
None yet
Development

No branches or pull requests

2 participants