-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat: enable Ajv2019 and Ajv2020 #152
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,19 +1,14 @@ | ||||||
| 'use strict' | ||||||
|
|
||||||
| const Ajv = require('ajv').default | ||||||
| const AjvJTD = require('ajv/dist/jtd') | ||||||
|
|
||||||
| const defaultAjvOptions = require('./default-ajv-options') | ||||||
|
|
||||||
| class ValidatorCompiler { | ||||||
| constructor (externalSchemas, options) { | ||||||
| // This instance of Ajv is private | ||||||
| // it should not be customized or used | ||||||
| if (options.mode === 'JTD') { | ||||||
| this.ajv = new AjvJTD(Object.assign({}, defaultAjvOptions, options.customOptions)) | ||||||
| } else { | ||||||
| this.ajv = new Ajv(Object.assign({}, defaultAjvOptions, options.customOptions)) | ||||||
| } | ||||||
| const ajvPath = ['JTD', '2019', '2020'].includes(options.mode) ? `ajv/dist/${options.mode.toLowerCase()}` : 'ajv' | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would refactor a bit here, because it is strange to me that we don't support the default version. I would implement something like: |
||||||
| const Ajv = require(ajvPath) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like same as before. Previously, accessing the
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allows using Ajv2019 and Ajv2020 by passing 2019 or 2020 in If If I'm misunderstanding the question, please help me understand.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I means
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Thanks for explaining. This became a learning opportunity for me. What I learned is, Ajv is ESM. According to Node docs
In Ajv code, Ajv uses My guess is that, in the past, I don't mind adding a commit to add the
But |
||||||
| this.ajv = new Ajv(Object.assign({}, defaultAjvOptions, options.customOptions)) | ||||||
|
|
||||||
| let addFormatPlugin = true | ||||||
| if (options.plugins && options.plugins.length > 0) { | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.