Core: Object validation issue

Created on 4 Oct 2020  路  2Comments  路  Source: adonisjs/core

Hi! I'm getting the following error when validating an object with any arbitrary members:
Validator_1.schema.object(...).anyMembers is not a function

Package version

@adonisjs/core: 5.0.0-preview-rc-1.12

Node.js and npm version

node: v12.18.4
npm: 6.14.8

Sample Code (to reproduce the issue)

 const { flowChart } = await request.validate({
    schema: schema.create({
    flowChart: schema.object().anyMembers(),
  }),
});
Bug

Most helpful comment

Fixed in validator. https://github.com/adonisjs/validator/commit/47204efd9547424edee431c6243811f30325f4a5

You will have to wait for a couple of days more before you can use the newer release of the validator that has the fix

All 2 comments

Might be as simple as the function is missing in the Schema implementation.

Currently it states:

/**
 * Object schema type
 */
function object(rules?: Rule[]) {
  return {
    members(schema: any) {
      return getObjectType(
        false,
        Object.keys(schema).reduce((result, field) => {
          [field] = schema[field].getTree()
          return result
        }, {}),
        rules || []
      )
    },
  } as ReturnType<ObjectType>
}
object.optional = function optionalObject(rules?: Rule[]) {
  return {
    members(schema: any) {
      return getObjectType(
        true,
        Object.keys(schema).reduce((result, field) => {
          result[field] = schema[field].getTree()
          return result
        }, {}),
        rules || []
      )
    },
  } as ReturnType<ObjectType['optional']>
}

It's missing the implementation of anyMembers()

Fixed in validator. https://github.com/adonisjs/validator/commit/47204efd9547424edee431c6243811f30325f4a5

You will have to wait for a couple of days more before you can use the newer release of the validator that has the fix

Was this page helpful?
0 / 5 - 0 ratings

Related issues

milosdakic picture milosdakic  路  3Comments

PC-HUB picture PC-HUB  路  4Comments

aligoren picture aligoren  路  4Comments

blendsoft picture blendsoft  路  3Comments

codingphasedotcom picture codingphasedotcom  路  3Comments