You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A new class SpecVersion has been introduced to indicate which version of the specification is used when creating the JsonSchemaFactory. The SpecVersion has an enum and two methods to convert a long to an EnumSet or a set of VersionFlags to a long value.
41
70
42
71
```
43
-
public enum VersionFlag {
72
+
public enum VersionFlag {
44
73
45
-
V4(1<<0),
46
-
V6(1<<1),
47
-
V7(1<<2),
48
-
V201909(1<<3);
74
+
V4(1<<0),
75
+
V6(1<<1),
76
+
V7(1<<2),
77
+
V201909(1<<3);
49
78
50
79
```
51
80
@@ -69,80 +98,97 @@ For most of the validators, the version code should be 15, which is 1111. This m
69
98
For example.
70
99
71
100
```
72
-
MAXIMUM("maximum", "1011", new MessageFormat("{0}: must have a maximum value of {1}"), MaximumValidator.class, 15),
101
+
MAXIMUM("maximum", "1011", new MessageFormat("{0}: must have a maximum value of {1}"), MaximumValidator.class, 15),
73
102
```
74
103
75
104
Since if-then-else was introduced in the V7, it only works for V7 and V2019-09
EXCLUSIVE_MAXIMUM("exclusiveMaximum", "1038", new MessageFormat("{0}: must have a exclusive maximum value of {1}"), ExclusiveMaximumValidator.class, 14), // V6|V7|V201909
113
+
EXCLUSIVE_MAXIMUM("exclusiveMaximum", "1038", new MessageFormat("{0}: must have a exclusive maximum value of {1}"), ExclusiveMaximumValidator.class, 14), // V6|V7|V201909
85
114
```
86
115
87
116
The getNonFormatKeywords method is updated to accept a SpecVersion.VersionFlag so that only the keywords supported by the specification will be loaded.
88
117
89
118
```
90
-
public static List<ValidatorTypeCode> getNonFormatKeywords(SpecVersion.VersionFlag versionFlag) {
91
-
final List<ValidatorTypeCode> result = new ArrayList<ValidatorTypeCode>();
92
-
for (ValidatorTypeCode keyword: values()) {
93
-
if (!FORMAT.equals(keyword) && specVersion.getVersionFlags(keyword.versionCode).contains(versionFlag)) {
94
-
result.add(keyword);
95
-
}
119
+
public static List<ValidatorTypeCode> getNonFormatKeywords(SpecVersion.VersionFlag versionFlag) {
120
+
final List<ValidatorTypeCode> result = new ArrayList<ValidatorTypeCode>();
121
+
for (ValidatorTypeCode keyword: values()) {
122
+
if (!FORMAT.equals(keyword) && specVersion.getVersionFlags(keyword.versionCode).contains(versionFlag)) {
123
+
result.add(keyword);
96
124
}
97
-
return result;
98
125
}
126
+
return result;
127
+
}
99
128
```
100
129
101
-
### JsonMetaSchema
130
+
####JsonMetaSchema
102
131
103
132
We have created four different static classes V4, V6, V7, and V201909 to build different JsonMetaSchema instances.
104
133
105
134
For the BUILDIN_FORMATS, there is a common section, and each static class has its version-specific BUILDIN_FORMATS section.
106
135
107
-
108
-
### JsonSchemaFactory
136
+
#### JsonSchemaFactory
109
137
110
138
The getInstance supports a parameter SpecVersion.VersionFlag to get the right instance of the JsonMetaShema to create the factory. If there is no parameter, then V4 is used by default.
111
139
112
140
```
113
-
public static JsonSchemaFactory getInstance() {
114
-
return getInstance(SpecVersion.VersionFlag.V4);
141
+
@Deprecated
142
+
public static JsonSchemaFactory getInstance() {
143
+
return getInstance(SpecVersion.VersionFlag.V4);
144
+
}
145
+
146
+
public static JsonSchemaFactory getInstance(SpecVersion.VersionFlag versionFlag) {
147
+
JsonMetaSchema metaSchema = null;
148
+
switch (versionFlag) {
149
+
case V201909:
150
+
metaSchema = JsonMetaSchema.getV201909();
151
+
break;
152
+
case V7:
153
+
metaSchema = JsonMetaSchema.getV7();
154
+
break;
155
+
case V6:
156
+
metaSchema = JsonMetaSchema.getV6();
157
+
break;
158
+
case V4:
159
+
metaSchema = JsonMetaSchema.getV4();
160
+
break;
115
161
}
162
+
return builder()
163
+
.defaultMetaSchemaURI(metaSchema.getUri())
164
+
.addMetaSchema(metaSchema)
165
+
.build();
166
+
}
167
+
```
116
168
117
-
public static JsonSchemaFactory getInstance(SpecVersion.VersionFlag versionFlag) {
0 commit comments