@@ -10,21 +10,20 @@ const Ajv2019 = require('ajv/dist/2019')
10
10
const Ajv2020 = require ( 'ajv/dist/2020' )
11
11
const AjvDraft06SchemaJson = require ( 'ajv/dist/refs/json-schema-draft-06.json' )
12
12
const AjvStandalone = require ( 'ajv/dist/standalone' ) . default
13
- const tv4 = require ( 'tv4' )
14
13
const TOML = require ( '@ltd/j-toml' )
15
14
const YAML = require ( 'yaml' )
16
15
const schemasafe = require ( '@exodus/schemasafe' )
17
16
const prettier = require ( 'prettier' )
18
17
const axios = require ( 'axios' ) . default
19
18
const findDuplicatedPropertyKeys = require ( 'find-duplicated-property-keys' )
20
19
20
+ const temporaryPreviousTv4OnlySchemas = [ 'tslint.json' , 'cloudify.json' ]
21
21
const temporaryCoverageDir = 'temp'
22
22
const schemaDir = 'schemas/json'
23
23
const testPositiveDir = 'test'
24
24
const testNegativeDir = 'negative_test'
25
25
const urlSchemaStore = 'https://json.schemastore.org/'
26
26
const catalog = require ( './api/json/catalog.json' )
27
- const schemaV4JSON = require ( path . resolve ( schemaDir , 'schema-draft-v4.json' ) )
28
27
const schemaValidation = require ( './schema-validation.json' )
29
28
const schemasToBeTested = fs . readdirSync ( schemaDir )
30
29
const foldersPositiveTest = fs . readdirSync ( testPositiveDir )
@@ -146,7 +145,6 @@ module.exports = function (grunt) {
146
145
/**
147
146
* @typedef {Object } localSchemaFileAndTestFileParameter2
148
147
* @prop {boolean } fullScanAllFiles
149
- * @prop {boolean } calledByTV4Validator
150
148
* @prop {boolean } skipReadFile
151
149
* @prop {boolean } ignoreSkiptest
152
150
* @prop {string } processOnlyThisOneSchemaFile
@@ -169,7 +167,6 @@ module.exports = function (grunt) {
169
167
} ,
170
168
{
171
169
fullScanAllFiles = false ,
172
- calledByTV4Validator = false ,
173
170
skipReadFile = true ,
174
171
ignoreSkiptest = false ,
175
172
processOnlyThisOneSchemaFile = undefined ,
@@ -198,13 +195,7 @@ module.exports = function (grunt) {
198
195
if ( fullScanAllFiles ) {
199
196
return true // All tests are always performed.
200
197
} 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
208
199
}
209
200
}
210
201
@@ -411,111 +402,6 @@ module.exports = function (grunt) {
411
402
}
412
403
}
413
404
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
-
519
405
/**
520
406
* @typedef {Object } FactoryAJVParameter
521
407
* @prop {string } schemaName
@@ -888,23 +774,6 @@ module.exports = function (grunt) {
888
774
} ,
889
775
)
890
776
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
-
908
777
grunt . registerTask (
909
778
'local_test_ajv' ,
910
779
'Use AJV to validate local schemas in ./test/' ,
@@ -1136,7 +1005,7 @@ module.exports = function (grunt) {
1136
1005
}
1137
1006
}
1138
1007
}
1139
- // Get all the json file for AJV and tv4
1008
+ // Get all the json file for AJV
1140
1009
localSchemaFileAndTestFile (
1141
1010
{ schemaOnlyScan : schemaFileCompare } ,
1142
1011
{ fullScanAllFiles : true } ,
@@ -1578,7 +1447,6 @@ module.exports = function (grunt) {
1578
1447
}
1579
1448
}
1580
1449
}
1581
- checkForDuplicateInList ( schemaValidation . tv4test , 'tv4test[]' )
1582
1450
checkForDuplicateInList (
1583
1451
schemaValidation . ajvNotStrictMode ,
1584
1452
'ajvNotStrictMode[]' ,
@@ -1724,25 +1592,6 @@ module.exports = function (grunt) {
1724
1592
} ,
1725
1593
)
1726
1594
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
-
1746
1595
grunt . registerTask (
1747
1596
'local_assert_schema-validation.json_no_missing_schema_files' ,
1748
1597
'Check if all schema JSON files are present' ,
@@ -1760,7 +1609,6 @@ module.exports = function (grunt) {
1760
1609
}
1761
1610
} )
1762
1611
}
1763
- x ( schemaValidation . tv4test )
1764
1612
x ( schemaValidation . ajvNotStrictMode )
1765
1613
x ( schemaValidation . skiptest )
1766
1614
x ( schemaValidation . missingcatalogurl )
@@ -1783,61 +1631,6 @@ module.exports = function (grunt) {
1783
1631
} ,
1784
1632
)
1785
1633
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
-
1841
1634
grunt . registerTask (
1842
1635
'local_coverage' ,
1843
1636
'Run one selected schema in coverage mode' ,
@@ -1968,12 +1761,6 @@ module.exports = function (grunt) {
1968
1761
'Must start "make" file with schema name parameter.' ,
1969
1762
] )
1970
1763
}
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
- }
1977
1764
generateCoverage ( schemaNameToBeCoverage )
1978
1765
grunt . log . ok ( 'OK' )
1979
1766
} ,
@@ -2065,11 +1852,11 @@ module.exports = function (grunt) {
2065
1852
'lint_catalog_entry_no_schema_word' ,
2066
1853
'lint_top_level_$ref_is_standalone' ,
2067
1854
] )
1855
+
2068
1856
grunt . registerTask ( 'local_test_filesystem' , [
2069
1857
'local_assert_directory_structure_is_valid' ,
2070
1858
'local_assert_filenames_have_correct_extensions' ,
2071
1859
'local_assert_test_folders_have_at_least_one_test_schema' ,
2072
- 'local_assert_tv4_validator_has_no_negative_tests' ,
2073
1860
] )
2074
1861
grunt . registerTask ( 'local_test_schema_validation_json' , [
2075
1862
'local_assert_schema-validation.json_no_duplicate_list' ,
@@ -2099,7 +1886,6 @@ module.exports = function (grunt) {
2099
1886
'local_print_schemas_tested_in_full_strict_mode' ,
2100
1887
'local_print_schemas_without_positive_test_files' ,
2101
1888
'local_test_ajv' ,
2102
- 'local_test_tv4_only_for_non_compliance_schema' ,
2103
1889
'local_print_url_counts_in_catalog' ,
2104
1890
'local_print_count_schema_versions' ,
2105
1891
] )
0 commit comments