https://github.com/lance/ajv-test
https://github.com/lance/ajv-test
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/lance/ajv-test
- Owner: lance
- Created: 2021-12-08T19:00:16.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-08T22:25:45.000Z (over 4 years ago)
- Last Synced: 2025-02-10T11:48:48.296Z (over 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Illustration of a problem I'm having with Ajv
I'd like to precompile my validation functions, and also use some custom formatters. This project includes some code illustrating a problem I am having.
My schema in `schema/schema.json` is simple. There is a single `time` field with a format of `js-date-time`. The format validation code is in `schema/formats.js`.
I generate the validation function with the command `ajv compile -c ./schema/formats.js -s ./schema/schema.json -o ./schema/validate.js`, which can also be run via `npm run build` for convenience.
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 call `validate()`, however, I get an error.
```
TypeError: formats0 is not a function
```
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.
```
const formats0 = {
_items: ['require("ajv-formats/dist/formats").', { str: "fullFormats" }, ""],
}["js-date-time"];
```
I'm not sure what I am doing wrong here. Any guidance is appreciated.