koajs / joi-router

Configurable, input and output validated routing for koa
MIT License
450 stars 96 forks source link

Query validator doens't work #89

Closed toto6321 closed 5 years ago

toto6321 commented 5 years ago

Hello, genius, I found that it seems the query validator doesn't work. Here is my code:

const Koa = require('koa')
const app = new Koa()

const router = require('koa-joi-router')
const Joi = router.Joi
const p = router()

p.route({
  path: '/',
  method: 'get',
  validate: {
    query: {
      t: Joi.string().min(3)
    },
    body: {
      email: Joi.string().email()
    },
    type: 'json'
  },
  handler: async ctx => {
    ctx.body = 'hello'
  }

})
p.prefix('/api/v1/public')
app.use(p.middleware())

image

If the email is missed in the request body, it works very well. However, it doesn't throw any error without a t in the request query even with the email in the body. What's wrong?

image

toto6321 commented 5 years ago

validator need to append .required() ...