Skip to content
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

Check keys().hasOnly() for nested object #32

Open
PegasisForever opened this issue Jan 20, 2022 · 0 comments
Open

Check keys().hasOnly() for nested object #32

PegasisForever opened this issue Jan 20, 2022 · 0 comments

Comments

@PegasisForever
Copy link

For type definition:

const DBData = z.object({
  nested: z.object({
    a: z.string(),
    b: z.string(),
  }),
})

The following validator is generated:

function __validator_0__(data) {
  return (__validator_meta__(data) && (
    __validator_keys__(data, ['nested'])
      && (data.nested.a is string && data.nested.b is string)
  ));
}

However the validator doesn't check if there's extra keys in data.nested, so the following data would be allowed:

{
  nested: {
    a: '',
    b: '',
    other: 'hey!',
  },
}

Fireschema should generate something like:

function __validator_0__(data) {
  return (__validator_meta__(data) && (
    __validator_keys__(data, ['nested'])
      && (data.nested.a is string && data.nested.b is string && data.nested.keys().hasOnly(['a', 'b']))
  ));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant