Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bdd5d6e

Browse files
committedAug 9, 2023
Merge branch 'master' into hyperupcall-various-improvements
2 parents 86f0276 + dc99b5b commit bdd5d6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2665
-459
lines changed
 

‎.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
repos:
33
- repo: https://github.com/pre-commit/mirrors-prettier
4-
rev: "v3.0.0"
4+
rev: "v3.0.1"
55
hooks:
66
- id: prettier
77
types_or: [yaml, json, javascript, css, markdown]

‎src/Gruntfile.cjs

+4-218
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ const Ajv2019 = require('ajv/dist/2019')
1010
const Ajv2020 = require('ajv/dist/2020')
1111
const AjvDraft06SchemaJson = require('ajv/dist/refs/json-schema-draft-06.json')
1212
const AjvStandalone = require('ajv/dist/standalone').default
13-
const tv4 = require('tv4')
1413
const TOML = require('@ltd/j-toml')
1514
const YAML = require('yaml')
1615
const schemasafe = require('@exodus/schemasafe')
1716
const prettier = require('prettier')
1817
const axios = require('axios').default
1918
const findDuplicatedPropertyKeys = require('find-duplicated-property-keys')
2019

20+
const temporaryPreviousTv4OnlySchemas = ['tslint.json', 'cloudify.json']
2121
const temporaryCoverageDir = 'temp'
2222
const schemaDir = 'schemas/json'
2323
const testPositiveDir = 'test'
2424
const testNegativeDir = 'negative_test'
2525
const urlSchemaStore = 'https://json.schemastore.org/'
2626
const catalog = require('./api/json/catalog.json')
27-
const schemaV4JSON = require(path.resolve(schemaDir, 'schema-draft-v4.json'))
2827
const schemaValidation = require('./schema-validation.json')
2928
const schemasToBeTested = fs.readdirSync(schemaDir)
3029
const foldersPositiveTest = fs.readdirSync(testPositiveDir)
@@ -146,7 +145,6 @@ module.exports = function (grunt) {
146145
/**
147146
* @typedef {Object} localSchemaFileAndTestFileParameter2
148147
* @prop {boolean} fullScanAllFiles
149-
* @prop {boolean} calledByTV4Validator
150148
* @prop {boolean} skipReadFile
151149
* @prop {boolean} ignoreSkiptest
152150
* @prop {string} processOnlyThisOneSchemaFile
@@ -169,7 +167,6 @@ module.exports = function (grunt) {
169167
},
170168
{
171169
fullScanAllFiles = false,
172-
calledByTV4Validator = false,
173170
skipReadFile = true,
174171
ignoreSkiptest = false,
175172
processOnlyThisOneSchemaFile = undefined,
@@ -198,13 +195,7 @@ module.exports = function (grunt) {
198195
if (fullScanAllFiles) {
199196
return true // All tests are always performed.
200197
} else {
201-
// Schema must be run for tv4 or AJV validator
202-
// calledByTV4Validator is only set true when it is called by tv4 validator
203-
// If schema is present in "tv4test" list then it can only be run if calledByTV4Validator = true
204-
// If schema is NOT present in "tv4test" list then it can only be run if calledByTV4Validator = false
205-
return schemaValidation.tv4test.includes(jsonFilename)
206-
? calledByTV4Validator
207-
: !calledByTV4Validator
198+
return true
208199
}
209200
}
210201

@@ -411,111 +402,6 @@ module.exports = function (grunt) {
411402
}
412403
}
413404

414-
function tv4Validator() {
415-
// tv4 validator can only process draft-04 schema
416-
// All unknown keyword used in draft-06 and newer are just ignored.
417-
// This is the correct implementation of the json schema specification.
418-
const schemaVersion = showSchemaVersions()
419-
const textValidate = 'validate | '
420-
const textPassSchema = 'pass schema | '
421-
const textPositivePassTest = 'pass positive test | '
422-
const textPositiveFailedTest = 'failed positive test | '
423-
424-
let schemaToBeValidated
425-
let countSchema = 0
426-
427-
const processSchemaFile = (/** @type {Schema} */ schema) => {
428-
// Start validate the JSON schema
429-
let validated
430-
let versionObj
431-
let schemaVersionStr = 'unknown'
432-
try {
433-
// select the correct AJV object for this schema
434-
schemaToBeValidated = schema.jsonObj
435-
versionObj = schemaVersion.getObj(schemaToBeValidated)
436-
437-
// What schema draft version is it?
438-
schemaVersionStr = versionObj ? versionObj.schemaName : 'unknown'
439-
440-
// validate the schema with draft-04. This is the only draft version it understands.
441-
validated = tv4.validate(schemaToBeValidated, schemaV4JSON)
442-
} catch (err) {
443-
throwWithErrorText([
444-
`${textValidate}${schema.urlOrFilePath} (${schemaVersionStr})`,
445-
err,
446-
])
447-
}
448-
if (!validated) {
449-
throwWithErrorText([
450-
`${textValidate}${schema.urlOrFilePath} (${schemaVersionStr}`,
451-
`(Schema file) keywordLocation: ${tv4.error.schemaPath}`,
452-
`(Test file) instanceLocation: ${tv4.error.dataPath}`,
453-
`(Message) ${tv4.error.message}`,
454-
'Error in validation',
455-
])
456-
}
457-
countSchema++
458-
grunt.log.writeln()
459-
grunt.log.ok(
460-
`${textPassSchema}${schema.urlOrFilePath} (${schemaVersionStr})`,
461-
)
462-
}
463-
464-
const processSchemaFileDone = () => {
465-
grunt.log.writeln()
466-
grunt.log.writeln(`Total schemas validated with tv4: ${countSchema}`)
467-
countSchema = 0
468-
}
469-
470-
const processPositiveTestFile = (/** @type {Schema} */ schema) => {
471-
const testFile = schema.jsonObj
472-
const validated = tv4.validate(testFile, schemaToBeValidated)
473-
if (tv4.missing.length > 0) {
474-
throwWithErrorText([
475-
`${textPositiveFailedTest}${schema.urlOrFilePath}`,
476-
`Missing URL: ${tv4.missing[0]}`,
477-
'Must add URL and schema file in schema-validation.json (tv4ExternalRef list)',
478-
])
479-
}
480-
if (validated) {
481-
grunt.log.ok(`${textPositivePassTest}${schema.urlOrFilePath}`)
482-
} else {
483-
throwWithErrorText([
484-
`${textPositiveFailedTest}${schema.urlOrFilePath}`,
485-
`(Schema file) keywordLocation: ${tv4.error.schemaPath}`,
486-
`(Test file) instanceLocation: ${tv4.error.dataPath}`,
487-
`(Message) ${tv4.error.message}`,
488-
'Error in positive test.',
489-
])
490-
}
491-
}
492-
493-
const loadExternalSchema = () => {
494-
for (const property in schemaValidation.tv4ExternalRef) {
495-
try {
496-
const schema = require(path.resolve(
497-
'.',
498-
schemaDir,
499-
schemaValidation.tv4ExternalRef[property],
500-
))
501-
tv4.addSchema(property, schema)
502-
} catch (err) {
503-
throwWithErrorText([
504-
`Error in processing tv4ExternalRef ${property} : ${schemaValidation.tv4ExternalRef[property]}`,
505-
err,
506-
])
507-
}
508-
}
509-
}
510-
511-
loadExternalSchema()
512-
return {
513-
testSchemaFile: processSchemaFile,
514-
testSchemaFileDone: processSchemaFileDone,
515-
positiveTestFile: processPositiveTestFile,
516-
}
517-
}
518-
519405
/**
520406
* @typedef {Object} FactoryAJVParameter
521407
* @prop {string} schemaName
@@ -888,23 +774,6 @@ module.exports = function (grunt) {
888774
},
889775
)
890776

891-
grunt.registerTask(
892-
'local_test_tv4_only_for_non_compliance_schema',
893-
'Use tv4 to validate local schemas in ./test/',
894-
function () {
895-
const x = tv4Validator()
896-
// tv4 is an outdated/unreliable validator. Do not add a negative test scan here.
897-
localSchemaFileAndTestFile(
898-
{
899-
schemaForTestScan: x.testSchemaFile,
900-
positiveTestScan: x.positiveTestFile,
901-
schemaForTestScanDone: x.testSchemaFileDone,
902-
},
903-
{ calledByTV4Validator: true, skipReadFile: false },
904-
)
905-
},
906-
)
907-
908777
grunt.registerTask(
909778
'local_test_ajv',
910779
'Use AJV to validate local schemas in ./test/',
@@ -1136,7 +1005,7 @@ module.exports = function (grunt) {
11361005
}
11371006
}
11381007
}
1139-
// Get all the json file for AJV and tv4
1008+
// Get all the json file for AJV
11401009
localSchemaFileAndTestFile(
11411010
{ schemaOnlyScan: schemaFileCompare },
11421011
{ fullScanAllFiles: true },
@@ -1578,7 +1447,6 @@ module.exports = function (grunt) {
15781447
}
15791448
}
15801449
}
1581-
checkForDuplicateInList(schemaValidation.tv4test, 'tv4test[]')
15821450
checkForDuplicateInList(
15831451
schemaValidation.ajvNotStrictMode,
15841452
'ajvNotStrictMode[]',
@@ -1724,25 +1592,6 @@ module.exports = function (grunt) {
17241592
},
17251593
)
17261594

1727-
grunt.registerTask(
1728-
'local_assert_tv4_validator_has_no_negative_tests',
1729-
'Check for forbidden negative test folder',
1730-
function () {
1731-
const found = foldersNegativeTest.find((x) =>
1732-
schemaValidation.tv4test.includes(x + '.json'),
1733-
)
1734-
if (found) {
1735-
throwWithErrorText([
1736-
`Negative folder found for TV4 validator => ${path.join(
1737-
testNegativeDir,
1738-
found,
1739-
)}`,
1740-
])
1741-
}
1742-
grunt.log.ok('OK')
1743-
},
1744-
)
1745-
17461595
grunt.registerTask(
17471596
'local_assert_schema-validation.json_no_missing_schema_files',
17481597
'Check if all schema JSON files are present',
@@ -1760,7 +1609,6 @@ module.exports = function (grunt) {
17601609
}
17611610
})
17621611
}
1763-
x(schemaValidation.tv4test)
17641612
x(schemaValidation.ajvNotStrictMode)
17651613
x(schemaValidation.skiptest)
17661614
x(schemaValidation.missingcatalogurl)
@@ -1783,61 +1631,6 @@ module.exports = function (grunt) {
17831631
},
17841632
)
17851633

1786-
grunt.registerTask(
1787-
'local_assert_schema-validation.json_valid_skiptest',
1788-
'schemas in skiptest[] list must not be present anywhere else',
1789-
function () {
1790-
let countSchemaValidationItems = 0
1791-
const x = (list, listName) => {
1792-
list.forEach((schemaName) => {
1793-
if (schemaName.endsWith('.json')) {
1794-
countSchemaValidationItems++
1795-
if (schemaValidation.skiptest.includes(schemaName)) {
1796-
throwWithErrorText([
1797-
`Disabled/skiptest[] schema: ${schemaName} found in => ${listName}[]`,
1798-
])
1799-
}
1800-
}
1801-
})
1802-
}
1803-
x(schemaValidation.tv4test, 'tv4test')
1804-
x(schemaValidation.ajvNotStrictMode, 'ajvNotStrictMode')
1805-
x(schemaValidation.missingcatalogurl, 'missingcatalogurl')
1806-
x(schemaValidation.highSchemaVersion, 'highSchemaVersion')
1807-
1808-
for (const item of schemaValidation.options) {
1809-
const schemaName = Object.keys(item).pop()
1810-
if (schemaName !== 'readme_example.json') {
1811-
countSchemaValidationItems++
1812-
if (schemaValidation.skiptest.includes(schemaName)) {
1813-
throwWithErrorText([
1814-
`Disabled/skiptest[] schema: ${schemaName} found in => options[]`,
1815-
])
1816-
}
1817-
}
1818-
}
1819-
1820-
// Test folder must not exist if defined in skiptest[]
1821-
schemaValidation.skiptest.forEach((schemaName) => {
1822-
countSchemaValidationItems++
1823-
const folderName = schemaName.replace('.json', '')
1824-
if (foldersPositiveTest.includes(folderName)) {
1825-
throwWithErrorText([
1826-
`Disabled/skiptest[] schema: ${schemaName} cannot have positive test folder`,
1827-
])
1828-
}
1829-
if (foldersNegativeTest.includes(folderName)) {
1830-
throwWithErrorText([
1831-
`Disabled/skiptest[] schema: ${schemaName} cannot have negative test folder`,
1832-
])
1833-
}
1834-
})
1835-
grunt.log.ok(
1836-
`Total schema-validation.json items check: ${countSchemaValidationItems}`,
1837-
)
1838-
},
1839-
)
1840-
18411634
grunt.registerTask(
18421635
'local_coverage',
18431636
'Run one selected schema in coverage mode',
@@ -1968,12 +1761,6 @@ module.exports = function (grunt) {
19681761
'Must start "make" file with schema name parameter.',
19691762
])
19701763
}
1971-
// Not for tv4 schema files
1972-
if (schemaValidation.tv4test.includes(schemaNameToBeCoverage)) {
1973-
throwWithErrorText([
1974-
`Coverage is not possible for tv4-validator schema file :${schemaNameToBeCoverage}`,
1975-
])
1976-
}
19771764
generateCoverage(schemaNameToBeCoverage)
19781765
grunt.log.ok('OK')
19791766
},
@@ -2065,11 +1852,11 @@ module.exports = function (grunt) {
20651852
'lint_catalog_entry_no_schema_word',
20661853
'lint_top_level_$ref_is_standalone',
20671854
])
1855+
20681856
grunt.registerTask('local_test_filesystem', [
20691857
'local_assert_directory_structure_is_valid',
20701858
'local_assert_filenames_have_correct_extensions',
20711859
'local_assert_test_folders_have_at_least_one_test_schema',
2072-
'local_assert_tv4_validator_has_no_negative_tests',
20731860
])
20741861
grunt.registerTask('local_test_schema_validation_json', [
20751862
'local_assert_schema-validation.json_no_duplicate_list',
@@ -2099,7 +1886,6 @@ module.exports = function (grunt) {
20991886
'local_print_schemas_tested_in_full_strict_mode',
21001887
'local_print_schemas_without_positive_test_files',
21011888
'local_test_ajv',
2102-
'local_test_tv4_only_for_non_compliance_schema',
21031889
'local_print_url_counts_in_catalog',
21041890
'local_print_count_schema_versions',
21051891
])

0 commit comments

Comments
 (0)
Please sign in to comment.