2121import com .networknt .schema .Schema ;
2222import com .networknt .schema .SchemaLocation ;
2323import com .networknt .schema .SpecificationVersion ;
24+ import com .networknt .schema .SpecificationVersionRange ;
2425import com .networknt .schema .SchemaContext ;
2526
2627import java .util .ArrayList ;
27- import java .util .Arrays ;
28- import java .util .EnumSet ;
2928import java .util .HashMap ;
3029import java .util .List ;
3130import java .util .Map ;
@@ -36,87 +35,62 @@ KeywordValidator newInstance(SchemaLocation schemaLocation, NodePath evaluationP
3635 Schema parentSchema , SchemaContext schemaContext );
3736}
3837
39- enum VersionCode {
40- None (new SpecificationVersion [] { }),
41- AllVersions (new SpecificationVersion [] { SpecificationVersion .DRAFT_4 , SpecificationVersion .DRAFT_6 , SpecificationVersion .DRAFT_7 , SpecificationVersion .DRAFT_2019_09 , SpecificationVersion .DRAFT_2020_12 }),
42- MinV6 (new SpecificationVersion [] { SpecificationVersion .DRAFT_6 , SpecificationVersion .DRAFT_7 , SpecificationVersion .DRAFT_2019_09 , SpecificationVersion .DRAFT_2020_12 }),
43- MinV6MaxV7 (new SpecificationVersion [] { SpecificationVersion .DRAFT_6 , SpecificationVersion .DRAFT_7 }),
44- MinV7 (new SpecificationVersion [] { SpecificationVersion .DRAFT_7 , SpecificationVersion .DRAFT_2019_09 , SpecificationVersion .DRAFT_2020_12 }),
45- MaxV7 (new SpecificationVersion [] { SpecificationVersion .DRAFT_4 , SpecificationVersion .DRAFT_6 , SpecificationVersion .DRAFT_7 }),
46- MaxV201909 (new SpecificationVersion [] { SpecificationVersion .DRAFT_4 , SpecificationVersion .DRAFT_6 , SpecificationVersion .DRAFT_7 , SpecificationVersion .DRAFT_2019_09 }),
47- MinV201909 (new SpecificationVersion [] { SpecificationVersion .DRAFT_2019_09 , SpecificationVersion .DRAFT_2020_12 }),
48- MinV202012 (new SpecificationVersion [] { SpecificationVersion .DRAFT_2020_12 }),
49- V201909 (new SpecificationVersion [] { SpecificationVersion .DRAFT_2019_09 }),
50- V7 (new SpecificationVersion [] { SpecificationVersion .DRAFT_7 });
51-
52- private final EnumSet <SpecificationVersion > versions ;
53-
54- VersionCode (SpecificationVersion [] versionFlags ) {
55- this .versions = EnumSet .noneOf (SpecificationVersion .class );
56- this .versions .addAll (Arrays .asList (versionFlags ));
57- }
58-
59- EnumSet <SpecificationVersion > getVersions () {
60- return this .versions ;
61- }
62- }
63-
6438public enum Keywords implements Keyword {
65- ADDITIONAL_PROPERTIES ("additionalProperties" , AdditionalPropertiesValidator ::new , VersionCode .MaxV7 ),
66- ALL_OF ("allOf" , AllOfValidator ::new , VersionCode .MaxV7 ),
67- ANY_OF ("anyOf" , AnyOfValidator ::new , VersionCode .MaxV7 ),
68- CONST ("const" , ConstValidator ::new , VersionCode .MinV6MaxV7 ),
69- CONTAINS ("contains" , ContainsValidator ::new , VersionCode .MinV6MaxV7 ),
70- CONTENT_ENCODING ("contentEncoding" , ContentEncodingValidator ::new , VersionCode .V7 ),
71- CONTENT_MEDIA_TYPE ("contentMediaType" , ContentMediaTypeValidator ::new , VersionCode .V7 ),
72- DEPENDENCIES ("dependencies" , DependenciesValidator ::new , VersionCode .AllVersions ),
73- DEPENDENT_REQUIRED ("dependentRequired" , DependentRequired ::new , VersionCode .None ),
74- DEPENDENT_SCHEMAS ("dependentSchemas" , DependentSchemas ::new , VersionCode .None ),
75- DISCRIMINATOR ("discriminator" , DiscriminatorValidator ::new , VersionCode .None ),
76- DYNAMIC_REF ("$dynamicRef" , DynamicRefValidator ::new , VersionCode .None ),
77- ENUM ("enum" , EnumValidator ::new , VersionCode .MaxV7 ),
78- EXCLUSIVE_MAXIMUM ("exclusiveMaximum" , ExclusiveMaximumValidator ::new , VersionCode .MinV6MaxV7 ),
79- EXCLUSIVE_MINIMUM ("exclusiveMinimum" , ExclusiveMinimumValidator ::new , VersionCode .MinV6MaxV7 ),
80- FALSE ("false" , FalseValidator ::new , VersionCode .MinV6 ),
81- FORMAT ("format" , null , VersionCode .MaxV7 ) {
39+ ADDITIONAL_PROPERTIES ("additionalProperties" , AdditionalPropertiesValidator ::new , SpecificationVersionRange .MaxV7 ),
40+ ALL_OF ("allOf" , AllOfValidator ::new , SpecificationVersionRange .MaxV7 ),
41+ ANY_OF ("anyOf" , AnyOfValidator ::new , SpecificationVersionRange .MaxV7 ),
42+ CONST ("const" , ConstValidator ::new , SpecificationVersionRange .MinV6MaxV7 ),
43+ CONTAINS ("contains" , ContainsValidator ::new , SpecificationVersionRange .MinV6MaxV7 ),
44+ CONTENT_ENCODING ("contentEncoding" , ContentEncodingValidator ::new , SpecificationVersionRange .V7 ),
45+ CONTENT_MEDIA_TYPE ("contentMediaType" , ContentMediaTypeValidator ::new , SpecificationVersionRange .V7 ),
46+ DEPENDENCIES ("dependencies" , DependenciesValidator ::new , SpecificationVersionRange .AllVersions ),
47+ DEPENDENT_REQUIRED ("dependentRequired" , DependentRequired ::new , SpecificationVersionRange .None ),
48+ DEPENDENT_SCHEMAS ("dependentSchemas" , DependentSchemas ::new , SpecificationVersionRange .None ),
49+ DISCRIMINATOR ("discriminator" , DiscriminatorValidator ::new , SpecificationVersionRange .None ),
50+ DYNAMIC_REF ("$dynamicRef" , DynamicRefValidator ::new , SpecificationVersionRange .None ),
51+ ENUM ("enum" , EnumValidator ::new , SpecificationVersionRange .MaxV7 ),
52+ EXCLUSIVE_MAXIMUM ("exclusiveMaximum" , ExclusiveMaximumValidator ::new , SpecificationVersionRange .MinV6MaxV7 ),
53+ EXCLUSIVE_MINIMUM ("exclusiveMinimum" , ExclusiveMinimumValidator ::new , SpecificationVersionRange .MinV6MaxV7 ),
54+ FALSE ("false" , FalseValidator ::new , SpecificationVersionRange .MinV6 ),
55+ FORMAT ("format" , null , SpecificationVersionRange .MaxV7 ) {
8256 @ Override public KeywordValidator newValidator (SchemaLocation schemaLocation , NodePath evaluationPath , JsonNode schemaNode , Schema parentSchema , SchemaContext schemaContext ) {
8357 throw new UnsupportedOperationException ("Use FormatKeyword instead" );
8458 }
8559 },
86- ID ("id" , null , VersionCode .AllVersions ),
87- IF_THEN_ELSE ("if" , IfValidator ::new , VersionCode .V7 ),
88- ITEMS_202012 ("items" , ItemsValidator202012 ::new , VersionCode .None ),
89- ITEMS ("items" , ItemsValidator ::new , VersionCode .MaxV7 ),
90- MAX_CONTAINS ("maxContains" ,MinMaxContainsValidator ::new , VersionCode .None ),
91- MAX_ITEMS ("maxItems" , MaxItemsValidator ::new , VersionCode .MaxV7 ),
92- MAX_LENGTH ("maxLength" , MaxLengthValidator ::new , VersionCode .MaxV7 ),
93- MAX_PROPERTIES ("maxProperties" , MaxPropertiesValidator ::new , VersionCode .MaxV7 ),
94- MAXIMUM ("maximum" , MaximumValidator ::new , VersionCode .MaxV7 ),
95- MIN_CONTAINS ("minContains" , MinMaxContainsValidator ::new , VersionCode .None ),
96- MIN_ITEMS ("minItems" , MinItemsValidator ::new , VersionCode .MaxV7 ),
97- MIN_LENGTH ("minLength" , MinLengthValidator ::new , VersionCode .MaxV7 ),
98- MIN_PROPERTIES ("minProperties" , MinPropertiesValidator ::new , VersionCode .MaxV7 ),
99- MINIMUM ("minimum" , MinimumValidator ::new , VersionCode .MaxV7 ),
100- MULTIPLE_OF ("multipleOf" , MultipleOfValidator ::new , VersionCode .MaxV7 ),
101- NOT_ALLOWED ("notAllowed" , NotAllowedValidator ::new , VersionCode .AllVersions ),
102- NOT ("not" , NotValidator ::new , VersionCode .MaxV7 ),
103- ONE_OF ("oneOf" , OneOfValidator ::new , VersionCode .MaxV7 ),
104- PATTERN_PROPERTIES ("patternProperties" , PatternPropertiesValidator ::new , VersionCode .MaxV7 ),
105- PATTERN ("pattern" , PatternValidator ::new , VersionCode .MaxV7 ),
106- PREFIX_ITEMS ("prefixItems" , PrefixItemsValidator ::new , VersionCode .None ),
107- PROPERTIES ("properties" , PropertiesValidator ::new , VersionCode .MaxV7 ),
108- PROPERTYNAMES ("propertyNames" , PropertyNamesValidator ::new , VersionCode .MinV6MaxV7 ),
109- READ_ONLY ("readOnly" , ReadOnlyValidator ::new , VersionCode .V7 ),
110- RECURSIVE_REF ("$recursiveRef" , RecursiveRefValidator ::new , VersionCode .None ),
111- REF ("$ref" , RefValidator ::new , VersionCode .MaxV7 ),
112- REQUIRED ("required" , RequiredValidator ::new , VersionCode .MaxV7 ),
113- TRUE ("true" , TrueValidator ::new , VersionCode .MinV6 ),
114- TYPE ("type" , TypeValidator ::new , VersionCode .MaxV7 ),
115- UNEVALUATED_ITEMS ("unevaluatedItems" , UnevaluatedItemsValidator ::new , VersionCode .None ),
116- UNEVALUATED_PROPERTIES ("unevaluatedProperties" ,UnevaluatedPropertiesValidator ::new ,VersionCode .None ),
117- UNION_TYPE ("unionType" , UnionTypeValidator ::new , VersionCode .None ),
118- UNIQUE_ITEMS ("uniqueItems" , UniqueItemsValidator ::new , VersionCode .MaxV7 ),
119- WRITE_ONLY ("writeOnly" , WriteOnlyValidator ::new , VersionCode .V7 ),
60+ ID ("id" , null , SpecificationVersionRange .AllVersions ),
61+ IF_THEN_ELSE ("if" , IfValidator ::new , SpecificationVersionRange .V7 ),
62+ ITEMS_202012 ("items" , ItemsValidator202012 ::new , SpecificationVersionRange .None ),
63+ ITEMS ("items" , ItemsValidator ::new , SpecificationVersionRange .MaxV7 ),
64+ MAX_CONTAINS ("maxContains" ,MinMaxContainsValidator ::new , SpecificationVersionRange .None ),
65+ MAX_ITEMS ("maxItems" , MaxItemsValidator ::new , SpecificationVersionRange .MaxV7 ),
66+ MAX_LENGTH ("maxLength" , MaxLengthValidator ::new , SpecificationVersionRange .MaxV7 ),
67+ MAX_PROPERTIES ("maxProperties" , MaxPropertiesValidator ::new , SpecificationVersionRange .MaxV7 ),
68+ MAXIMUM ("maximum" , MaximumValidator ::new , SpecificationVersionRange .MaxV7 ),
69+ MIN_CONTAINS ("minContains" , MinMaxContainsValidator ::new , SpecificationVersionRange .None ),
70+ MIN_ITEMS ("minItems" , MinItemsValidator ::new , SpecificationVersionRange .MaxV7 ),
71+ MIN_LENGTH ("minLength" , MinLengthValidator ::new , SpecificationVersionRange .MaxV7 ),
72+ MIN_PROPERTIES ("minProperties" , MinPropertiesValidator ::new , SpecificationVersionRange .MaxV7 ),
73+ MINIMUM ("minimum" , MinimumValidator ::new , SpecificationVersionRange .MaxV7 ),
74+ MULTIPLE_OF ("multipleOf" , MultipleOfValidator ::new , SpecificationVersionRange .MaxV7 ),
75+ NOT_ALLOWED ("notAllowed" , NotAllowedValidator ::new , SpecificationVersionRange .AllVersions ),
76+ NOT ("not" , NotValidator ::new , SpecificationVersionRange .MaxV7 ),
77+ ONE_OF ("oneOf" , OneOfValidator ::new , SpecificationVersionRange .MaxV7 ),
78+ PATTERN_PROPERTIES ("patternProperties" , PatternPropertiesValidator ::new , SpecificationVersionRange .MaxV7 ),
79+ PATTERN ("pattern" , PatternValidator ::new , SpecificationVersionRange .MaxV7 ),
80+ PREFIX_ITEMS ("prefixItems" , PrefixItemsValidator ::new , SpecificationVersionRange .None ),
81+ PROPERTIES ("properties" , PropertiesValidator ::new , SpecificationVersionRange .MaxV7 ),
82+ PROPERTYNAMES ("propertyNames" , PropertyNamesValidator ::new , SpecificationVersionRange .MinV6MaxV7 ),
83+ READ_ONLY ("readOnly" , ReadOnlyValidator ::new , SpecificationVersionRange .V7 ),
84+ RECURSIVE_REF ("$recursiveRef" , RecursiveRefValidator ::new , SpecificationVersionRange .None ),
85+ REF ("$ref" , RefValidator ::new , SpecificationVersionRange .MaxV7 ),
86+ REQUIRED ("required" , RequiredValidator ::new , SpecificationVersionRange .MaxV7 ),
87+ TRUE ("true" , TrueValidator ::new , SpecificationVersionRange .MinV6 ),
88+ TYPE ("type" , TypeValidator ::new , SpecificationVersionRange .MaxV7 ),
89+ UNEVALUATED_ITEMS ("unevaluatedItems" , UnevaluatedItemsValidator ::new , SpecificationVersionRange .None ),
90+ UNEVALUATED_PROPERTIES ("unevaluatedProperties" ,UnevaluatedPropertiesValidator ::new ,SpecificationVersionRange .None ),
91+ UNION_TYPE ("unionType" , UnionTypeValidator ::new , SpecificationVersionRange .None ),
92+ UNIQUE_ITEMS ("uniqueItems" , UniqueItemsValidator ::new , SpecificationVersionRange .MaxV7 ),
93+ WRITE_ONLY ("writeOnly" , WriteOnlyValidator ::new , SpecificationVersionRange .V7 ),
12094 ;
12195
12296 private static final Map <String , Keywords > CONSTANTS = new HashMap <>();
@@ -129,9 +103,9 @@ public enum Keywords implements Keyword {
129103
130104 private final String value ;
131105 private final ValidatorFactory validatorFactory ;
132- private final VersionCode versionCode ;
106+ private final SpecificationVersionRange versionCode ;
133107
134- Keywords (String value , ValidatorFactory validatorFactory , VersionCode versionCode ) {
108+ Keywords (String value , ValidatorFactory validatorFactory , SpecificationVersionRange versionCode ) {
135109 this .value = value ;
136110 this .validatorFactory = validatorFactory ;
137111 this .versionCode = versionCode ;
@@ -175,7 +149,7 @@ public String getValue() {
175149 return this .value ;
176150 }
177151
178- public VersionCode getVersionCode () {
152+ public SpecificationVersionRange getVersionCode () {
179153 return this .versionCode ;
180154 }
181155}
0 commit comments