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

payload validation for routes that have multiple method arguments #2659

Closed
ugate opened this issue Jul 23, 2015 · 6 comments
Closed

payload validation for routes that have multiple method arguments #2659

ugate opened this issue Jul 23, 2015 · 6 comments
Assignees
Labels
support Questions, discussions, and general support

Comments

@ugate
Copy link

ugate commented Jul 23, 2015

Is there a way to handle payload validation for routes that have multiple method arguments?

server.route({
    method: [ 'GET', 'POST' ],
    config: {
        validate: {
            payload: {
                value: Joi.string().required()
            } 
        }
    }
});

I get the following error:
Cannot validate HEAD or GET requests

v8.8.0

@mtharrison
Copy link
Contributor

I would advise making those routes separately. Payload validation doesn't make sense for GET requests.

@hueniverse
Copy link
Contributor

The right solution as @mtharrison said is to split it.

@hueniverse hueniverse added the support Questions, discussions, and general support label Jul 23, 2015
@hueniverse hueniverse self-assigned this Jul 23, 2015
@ugate
Copy link
Author

ugate commented Jul 23, 2015

@mtharrison @hueniverse just wanted to reduce the amount of boilerplate... seems redundant to have duplicate route properties just because of one separate property, no? isn't that the point of allowing method to take an Array in the first place?

What about allowing validate to take an Array like the following?

server.route({
    method: [ 'GET', 'POST' ],
    config: {
        validate: [
            {
                query: {
                    value: Joi.string().required()
                }
            },
            {
                payload: {
                    value: Joi.string().required()
                }
            }
        ]
    }
});

...or a more explicit alternative?

server.route({
    method: [ 'GET', 'POST' ],
    config: {
        validate: {
            GET: {
                query: {
                    value: Joi.string().required()
                }
            },
            POST: {
                payload: {
                    value: Joi.string().required()
                }
            }
        }
    }
});

@hueniverse
Copy link
Contributor

Method array makes sense when the routes are really identical. It is really just a shortcut and internally it is the same as adding two completely separate routes. In this case verbosity is better.

@ugate
Copy link
Author

ugate commented Jul 23, 2015

@hueniverse The routes are near-identical with the exception of the method and validation. the handler, path, etc. are all the same. So, verbosity in the 2nd proposed solution makes sense?

@hueniverse
Copy link
Contributor

I am not going to add this. Multiple methods is a simple shortcut. If you need more, either write your own helper or just repeat the route.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

3 participants