RocksonZeta / koa-validate

validate koa request params and format request params
https://github.com/RocksonZeta/koa-validate
MIT License
284 stars 32 forks source link

Added support to parse objects and arrays in the request for both params and body #12

Open srinivasiyer opened 9 years ago

srinivasiyer commented 9 years ago

The change is pretty light weight that allows nested object bodies and array notations in URLS to be validated using a '.' separator

http://localhost:3000?foo[bar]=foobar can be validated as

this.checkQuery('foo.bar').eq('foobar')

the above example would require the koa-qs library to parse the get params

Also a body of

{
  "foo": [{"bar": "foobar"}]
}

can be validated using

this.checkBody('foo.0.bar').eq('foobar', 'Needs to be foobar');

I have worked with nested bodies in many projects and this would really useful if you can merge the request.

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-75.67%) to 21.36% when pulling a5af795fcc11e86442fb83f9233667e838118aa9 on srinivasiyer:master into 0252d70d93321f7ee74ce7d508cf99874700c83d on RocksonZeta:master.