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

JTD values form accepts any value #1949

Closed
VirtuaBoza opened this issue Apr 6, 2022 · 1 comment
Closed

JTD values form accepts any value #1949

VirtuaBoza opened this issue Apr 6, 2022 · 1 comment
Milestone

Comments

@VirtuaBoza
Copy link

What version of Ajv are you using? Does the issue happen if you use the latest version?

8.11.0 (latest at time of writing)

Ajv options object

undefined

JSON Type Definition

{
  values: {}
}

Sample data

undefined

Your code

import Ajv from "ajv/dist/jtd";

const ajv = new Ajv();
console.log(ajv.validate({ values: {} }, undefined)); // true, expected false
console.log(ajv.validate({ values: {} }, null)); // true, expected false
console.log(ajv.validate({ values: {} }, 1)); // true, expected false
console.log(ajv.validate({ values: {} }, "foo")); // true, expected false

Validation result, data AFTER validation, error messages

true

What results did you expect?

I expected false. Unless I misunderstand the documentation, { values: {} } is equivalent to Record<string, any>, but it appears to be treated as any.

Are you going to resolve the issue?

First I'm interested to know if I'm mistaken. I haven't taken a look at the source code to know if I might be able to resolve it myself.

My workaround for the moment is to replace { values: {} } with { optionalProperties: { foo: {} }, additionalProperties: true }.

@epoberezkin
Copy link
Member

This is indeed a bug - it happens with an empty "values" form.

As a workaround, you should be using "properties" form without properties.

@epoberezkin epoberezkin added this to the 8.12 milestone Nov 13, 2022
epoberezkin added a commit that referenced this issue Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants