adonisjs / validator

Schema based validator for AdonisJS
MIT License
116 stars 39 forks source link

Can't match multiple depth arrays with wildcard #28

Closed simontong closed 6 years ago

simontong commented 7 years ago

I have the following rule:

{
  "props.exit_urls.*.url": "required"
}

But when I post the following data:

props[exit_urls][0][url] = ''

It isn't matching the rule.

I tried running the regexp arrayExpressionRegex parser rule in src/Parser/index.js and it appears to only match everything after props..

thetutlage commented 7 years ago

Yes, since Indicative doesn't allow multiple nested arrays. It only support one level deep. Mentioned in docs too http://indicative.adonisjs.com/#indicative-basics-array-expressions

But can we?

Yes we can, but I have to spend some more time the Indicative validation engine, and frankly saying I don't know when I will work on it

Quick fix.

When using Adonis route validator, I define a custom data object documented here and simply limit them to one level of nesting.

If you have too much nested data, this will be pain, but for couple of keys, I believe you can transform them to one level of depth.

simontong commented 7 years ago

Would swapping indicative for https://www.npmjs.com/package/validatorjs be an option as they work quite similarly

thetutlage commented 7 years ago

You can try to use that package manually if you want.

thetutlage commented 6 years ago

@simontong I have added support for this too, will be released soon

simontong commented 6 years ago

thanks, i'll keep an eye out

thetutlage commented 6 years ago

Release as part of v4. Not in Adonis right now, since it will have small breaking changes. So scheduled for 4.1

RomainLanz commented 6 years ago

Closing this since it's fixed in the new release of the framework (4.1). Please upgrade (it takes only a few minutes).