ajv-validator / ajv-formats

JSON Schema format validation for Ajv v8+
https://ajv.js.org
MIT License
184 stars 36 forks source link

[question] can you use ajv-formats with ajv@6.12.6 ? #26

Open linfanxxxx opened 3 years ago

linfanxxxx commented 3 years ago

please,i need format: int 32 , bug ajv don't include

seriousme commented 3 years ago

Version 2.1.0 will include int32, see #22 and #25. Until then you can add:

const MIN_INT32 = -(2 ** 31)
const MAX_INT32 = 2 ** 31 - 1

function validateInt32(value) {
  return Number.isInteger(value) && value <= MAX_INT32 && value >= MIN_INT32
}

ajv.addFormat("int32", {type: "number", validate: validateInt32})
epoberezkin commented 3 years ago

I am wondering if it would work with 6.12.6... You can definitely require just the format definition out of it and add manually.