1
1
// Import the modules
2
- const Ajv = require ( "ajv" ) ;
3
2
const Ajv2020 = require ( "ajv/dist/2020" ) ;
4
3
const addFormats = require ( "ajv-formats" ) ;
5
4
const readdirp = require ( "readdirp" ) ;
6
5
const npath = require ( "path" ) ;
7
- const compareVersions = require ( "compare-versions" ) ;
6
+ const { compareVersions } = require ( "compare-versions" ) ;
8
7
9
8
/**
10
9
* Retrieve the value of the given option.
@@ -74,7 +73,7 @@ const options = {
74
73
console . log ( "" ) ;
75
74
76
75
// ... create ajv instance
77
- const ajv = ajvFactory ( version ) ;
76
+ const ajv = ajvFactory ( ) ;
78
77
79
78
// ... add schemas to ajv instance
80
79
await addSchemas ( ajv , version ) ;
@@ -110,12 +109,11 @@ const options = {
110
109
111
110
/**
112
111
* Generate new instance of Ajv validator.
113
- * @param {String } version - The version of the JSON:API spec that will be validated
114
- * @returns {Ajv|Ajv2020 } - An in stance of Ajv validator
112
+ * @returns {Ajv2020 } - An instance of Ajv validator
115
113
*/
116
- const ajvFactory = function ( version ) {
114
+ const ajvFactory = function ( ) {
117
115
// ... create ajv instance
118
- const ajv = ( version === "1.0" ) ? new Ajv ( ) : new Ajv2020 ( ) ;
116
+ const ajv = new Ajv2020 ( ) ;
119
117
120
118
// ...add formats to ajv validator
121
119
addFormats ( ajv ) ;
@@ -125,7 +123,7 @@ const ajvFactory = function (version) {
125
123
126
124
/**
127
125
* Load all version-related schemas and register them with the instance of the Ajv validator.
128
- * @param {Ajv| Ajv2020 } ajv - An instance of Ajv validator
126
+ * @param {Ajv2020 } ajv - An instance of Ajv validator
129
127
* @param {String } version - The version of the JSON:API spec that will be validated
130
128
* @return {void }
131
129
*/
@@ -156,7 +154,7 @@ const addSchemas = async function (ajv, version) {
156
154
157
155
/**
158
156
* Check all the test files for the given version of the JSON:API spec.
159
- * @param {Ajv| Ajv2020 } ajv - An instance of Ajv validator
157
+ * @param {Ajv2020 } ajv - An instance of Ajv validator
160
158
* @param {String } version - The version of the JSON:API spec that will be validated
161
159
* @return {{ok: String[], ko: String[]} } - The results of the tests.
162
160
*/
@@ -178,7 +176,7 @@ const handleTests = async function (ajv, version) {
178
176
179
177
/**
180
178
* Check all the test files for the given version of the JSON:API spec.
181
- * @param {Ajv| Ajv2020 } ajv - An instance of Ajv validator
179
+ * @param {Ajv2020 } ajv - An instance of Ajv validator
182
180
* @param {String } version - The version of the JSON:API spec that will be validated
183
181
* @param {{ok: String[], ko: String[]} } results - The results of the tests.
184
182
* @return {void }
@@ -206,7 +204,7 @@ const runAllTests = async function (ajv, version, results) {
206
204
207
205
/**
208
206
* Run a single test for the given version of the JSON:API spec and the test file that was passed in the options.
209
- * @param {Ajv| Ajv2020 } ajv - An instance of Ajv validator
207
+ * @param {Ajv2020 } ajv - An instance of Ajv validator
210
208
* @param {String } version - The version of the JSON:API spec that will be validated
211
209
* @param {{ok: String[], ko: String[]} } results - The result of the test.
212
210
* @return {void }
@@ -231,7 +229,7 @@ const runSingleTest = async function (ajv, version, results) {
231
229
232
230
/**
233
231
* Check a single test files for the given version of the JSON:API spec.
234
- * @param {Ajv| Ajv2020 } ajv - An instance of Ajv validator
232
+ * @param {Ajv2020 } ajv - An instance of Ajv validator
235
233
* @param {String } version - The version of the JSON:API spec that will be validated
236
234
* @param {String } relativePath - The relative path of the test file that will be validated
237
235
* @param {String } fullPath - The absolute path of the test file that will be validated
@@ -275,7 +273,7 @@ const readTestDir = async function (version, callback) {
275
273
276
274
/**
277
275
* validate a test file for the given version of the JSON:API spec.
278
- * @param {Ajv| Ajv2020 } ajv - An instance of Ajv validator
276
+ * @param {Ajv2020 } ajv - An instance of Ajv validator
279
277
* @param {String } version - The version of the JSON:API spec that will be validated
280
278
* @param {String } relativePath - The relative path of the file to validate.
281
279
* @param {String } fullPath - The absolute path of the file to validate.
0 commit comments