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
“compare is not a function” when using formatMinimum with date format #56
Comments
Please add a minimal code sample - ideally to runkit - it's not clear what you are doing wrong otherwise... Most likely you are not passing the correct options to ajv-formats. |
Added a RunKit example above! Thanks so much for looking. |
any updates on that one? it also occurs when using the example in your documentation, which i basically copied verbatim into runkit runkit A: https://runkit.com/cdxoo/62f79994b6b4b90009190fe4 for interaction with ajv@8.11.0 the issue occurs in both of those var Ajv = require('ajv@8.11.0');
var ajvFormats = require('ajv-formats@2.1.1');
var ajv = new Ajv();
ajvFormats(ajv);
var schema = {
type: "string",
format: "date",
formatMinimum: "2016-02-06",
formatExclusiveMaximum: "2016-12-27",
}
ajv.validate(schema, '2016-02-06'); |
I think the problem comes after |
It does appear that using |
Here is an example of the (faulty) validation code being generated by the library for a schema with type=string, format=date-time or format=date, and formatMinimum specified (presumably it does the same for formatMaximum too):
We can see that the code generation is failing to create valid javascript. It is leaving objects as placeholders for what it wants on either side of the I studied it for hours, but there is a steep learning curve to this library. The magic is being performed in the CodeGen class in It was a little tricky to find, as it happens when the schema gets compiled for the first time. I can surmise that the following block of generated validation javascript:
should instead be something like
... and it simply didn't get turned into javascript correctly. Hopefully this will help get if fixed more easily & quicker. In the meantime, I'd love to hear form the authoritative source what is the proposed workaround. |
The workaround I used for now was to set the version explicitly in |
This is my schema (with unrelated properties removed):
As-is, everything works and validates correctly. But when I add
formatMinimum
tolaunchDate
:… I get the following console error:
Update:
RunKit example: https://runkit.com/brandondurham/compare-is-not-a-function-when-using-formatminimum-with-date-format
The text was updated successfully, but these errors were encountered: