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

Route validation does not work #67

Closed
clayrisser opened this issue Feb 25, 2018 · 6 comments
Closed

Route validation does not work #67

clayrisser opened this issue Feb 25, 2018 · 6 comments

Comments

@clayrisser
Copy link
Contributor

I cannot seem to get route validation to work.

My config looks like the following . . .

    config: {
      validate: {
        body: object({
          name: Joi.string()
            .min(3)
            .max(4)
            .required()
        })
      }
    }
@clayrisser
Copy link
Contributor Author

So it turns out validation works on everything but body.

@clayrisser
Copy link
Contributor Author

It looks like the bug was created by not handling the hapi compatible payload correctly.

@jaumard
Copy link
Contributor

jaumard commented Feb 25, 2018

No in fact it's because you need to use hapi notation (at least it was designed like this) and use payload instead of body, body is not supported

@clayrisser
Copy link
Contributor Author

Express is not hapi. That's counterintuitive and confusing for express users. I think it should support both.

@jaumard
Copy link
Contributor

jaumard commented Feb 25, 2018

Route definition is global to Trails project whatever the web server (and not hapi/express specific), meaning that whatever the definition you have here, it has to work for any web server under the hood. The trails team choose to base his route definition on the hapi one that's why it use payload and not body. Sure we can support body but in that case trailpack-hapi will have to support it too, but for me it's not a good thing to offer the same functionality with two different name.

What we can do is to enhance the route definition validation here https://github.com/trailsjs/trailpack-router/blob/master/lib/schemas/route.js#L21 to add the missing validation. Like this when someone put body it will say that it's forbidden. At least there will be a real error instead of just ignoring the entry.

If someone have other opinion/idea you're welcome @trailsjs/maintainers :)

@clayrisser
Copy link
Contributor Author

Ok, I guess that makes sense. I'm happy to at least know what the issue was. I need to use payload instead of body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants