-
-
Notifications
You must be signed in to change notification settings - Fork 877
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
Error when validating with standalone/precompiled function #1837
Comments
There are two ways it can be done with standalone code:
Both approaches are a bit hacky, but it works. |
@epoberezkin thanks for the quick response! I'm sorry but I don't really understand either of the suggestions you are making. Can you possibly provide some kind of example code to illustrate this? |
@epoberezkin ping - bumping this up in your awareness after the holidays and the new year. Any assistance you can provide would be much appreciated. Thanks! |
What @epoberezkin meant is that you just set the format before loading the custom compile function:
|
ajv seems to have some bugs around precompiling and formats, particularly when using ESM: * ajv-validator/ajv#1837 * ajv-validator/ajv-cli#200 Workaround for non-esm works for cloudevents/sdk-javascript#471 So if we want to work with this, we should look at how that is done, but it is taking too many cycles to pursue for now.
I'd like to precompile my validation functions, and also use some custom formatters but am getting errors when doing so. I've created a project here to illustrate the issue: https://github.com/lance/ajv-test
My schema in
schema/schema.json
is simple. There is a singletime
field with a custom format ofjs-date-time
. The format validation code is inschema/formats.js
.I generate the validation function with the command
This can also be run via
npm run build
for convenience, outputting a nicely formatted JS file.The code that uses this validation function is in
app.js
and simply attempts to validate an object with what should be a valid value. When I callvalidate()
, however, I get an error.If you look at the prettified JavaScript generated for the validation function, it's easy to see that, in fact,
formats0
is not a function.I'm not sure what I am doing wrong here. Any guidance is appreciated.
What version of Ajv are you using? Does the issue happen if you use the latest version?
8.8.2 - the latest as of this writing
Ajv options object
Called from the CLI with the following options
JSON Schema
Sample data
Your code
Please see this simplified test project: https://github.com/lance/ajv-test
Validation result, data AFTER validation, error messages
What results did you expect?
Successful validation of the test object.
Are you going to resolve the issue?
If you tell me how! :)
The text was updated successfully, but these errors were encountered: