Skip to content

tuple item dosent support default and optioanl #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
uinz opened this issue Jul 5, 2020 · 3 comments · Fixed by #226
Closed

tuple item dosent support default and optioanl #175

uinz opened this issue Jul 5, 2020 · 3 comments · Fixed by #226
Labels

Comments

@uinz
Copy link

uinz commented Jul 5, 2020

default

const V = require('fastest-validator');

const v = new V();

const schema = {
  tuple: {
    type: 'tuple',
    empty: false,
    items: [{ type: 'string', default: '1' }],
  },
};

const data = { tuple: [] };
console.log(v.validate(data, schema));
console.log(data);
[
  {
    type: 'tupleEmpty',
    message: "The 'tuple' field must not be an empty array.",
    field: 'tuple',
    actual: []
  }
]
{ tuple: [] }

optional

const schema = {
  tuple: {
    type: 'tuple',
    empty: false,
    items: [
      { type: 'string' },
      { type: 'number', optional: true },
    ],
  },
};

const data = { tuple: ['str', undefined] };
console.log(v.validate(data, schema));
console.log(data);
[
  {
    type: 'number',
    message: "The 'tuple[1]' field must be a number.",
    field: 'tuple[1]',
    actual: undefined
  }
]
{ tuple: [ 'str', undefined ] }
@intech
Copy link
Contributor

intech commented Sep 6, 2020

I would call this a critical bug. The empty: true rule won't work either, we need to fix the list of properties that should be checked at the top level of the rule.

@icebob
Copy link
Owner

icebob commented Sep 9, 2020

@Gamote could you help with this issue?

@Gamote
Copy link
Contributor

Gamote commented Sep 10, 2020

@icebob yes, I'll do a PR with the changes soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants