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

How can I make a property value depend on the value of another property? #2414

Closed
bertolo1988 opened this issue Apr 13, 2024 · 1 comment
Closed

Comments

@bertolo1988
Copy link

Using ajv is it possible to get a validation error if minPrice is bigger than maxPrice in this schema?

{
  "type": "object",
  "properties": {
    "minPrice": {
      "type": "number"
    },
    "maxPrice": {
      "type": "number"
    }
  }
}
@jasoniangreen
Copy link
Collaborator

I think you can look into the $data keyword. It allows you to refer to the actual validated values of other parts of the data in your validation rules.

https://ajv.js.org/guide/combining-schemas.html#data-reference

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

No branches or pull requests

2 participants