Skip to content
This repository was archived by the owner on Apr 19, 2022. It is now read-only.
This repository was archived by the owner on Apr 19, 2022. It is now read-only.

Fail validation when no data is proved at all #253

@McSneaky

Description

@McSneaky

In Indicative version 7.4.4 validation is passing when there is no data to validate and schema contains multiple required fields.

Example code:

validate() {
  const data = undefined;
  const schema = {
    campaignId: 'required|number',
    connectionId: 'required|number',
    objectType: 'required|string'
  };

  return validate(data, schema, {}, {
    removeAdditional: true,
  }).catch(([error]) => {
    throw new Error(error.message);
  });
}

Then calling it with await validate() will always pass

Workaround is to manually check if data exists or not

validate(data) {
  if (!data) {
    throw new Error('No data given');
  }
  const schema = {
    campaignId: 'required|number',
    connectionId: 'required|number',
    objectType: 'required|string'
  };

  return validate(data, schema, {}, {
    removeAdditional: true,
  }).catch(([error]) => {
    throw new Error(error.message);
  });
}

Maybe could make it as default that it fails or if not default, then perhaps some option like allowEmpty that is set to true by default, so it won't break any existing code

Are you willing to work on it with little guidance?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions