@@ -42,7 +42,6 @@ public static class Builder {
42
42
private String defaultMetaSchemaURI ;
43
43
private Map <String , JsonMetaSchema > jsonMetaSchemas = new HashMap <String , JsonMetaSchema >();
44
44
private Map <URL , URL > urlMap = new HashMap <URL , URL >();
45
- private URL rootSchemaUrl = null ;
46
45
47
46
public Builder objectMapper (ObjectMapper objectMapper ) {
48
47
this .objectMapper = objectMapper ;
@@ -76,21 +75,14 @@ public Builder addUrlMappings(Map<URL, URL> map) {
76
75
return this ;
77
76
}
78
77
79
- public Builder setRootSchemaUrl (URL rootSchemaUrl )
80
- {
81
- this .rootSchemaUrl = rootSchemaUrl ;
82
- return this ;
83
- }
84
-
85
78
public JsonSchemaFactory build () {
86
79
// create builtin keywords with (custom) formats.
87
80
return new JsonSchemaFactory (
88
81
objectMapper == null ? new ObjectMapper () : objectMapper ,
89
82
urlFetcher == null ? new StandardURLFetcher (): urlFetcher ,
90
83
defaultMetaSchemaURI ,
91
84
jsonMetaSchemas ,
92
- urlMap ,
93
- rootSchemaUrl
85
+ urlMap
94
86
);
95
87
}
96
88
}
@@ -100,14 +92,12 @@ public JsonSchemaFactory build() {
100
92
private final String defaultMetaSchemaURI ;
101
93
private final Map <String , JsonMetaSchema > jsonMetaSchemas ;
102
94
private final Map <URL , URL > urlMap ;
103
- private final URL rootSchemaUrl ;
104
95
105
96
private JsonSchemaFactory (
106
97
ObjectMapper mapper ,
107
98
URLFetcher urlFetcher ,
108
99
String defaultMetaSchemaURI ,
109
- Map <String , JsonMetaSchema > jsonMetaSchemas , Map <URL , URL > urlMap ,
110
- URL rootSchemaUrl ) {
100
+ Map <String , JsonMetaSchema > jsonMetaSchemas , Map <URL , URL > urlMap ) {
111
101
if (mapper == null ) {
112
102
throw new IllegalArgumentException ("ObjectMapper must not be null" );
113
103
}
@@ -131,7 +121,6 @@ private JsonSchemaFactory(
131
121
this .urlFetcher = urlFetcher ;
132
122
this .jsonMetaSchemas = jsonMetaSchemas ;
133
123
this .urlMap = urlMap ;
134
- this .rootSchemaUrl = rootSchemaUrl ;
135
124
}
136
125
137
126
/**
@@ -163,14 +152,13 @@ public static Builder builder(JsonSchemaFactory blueprint) {
163
152
.urlFetcher (blueprint .urlFetcher )
164
153
.defaultMetaSchemaURI (blueprint .defaultMetaSchemaURI )
165
154
.objectMapper (blueprint .mapper )
166
- .addUrlMappings (blueprint .urlMap )
167
- .setRootSchemaUrl (blueprint .rootSchemaUrl );
155
+ .addUrlMappings (blueprint .urlMap );
168
156
}
169
157
170
- private JsonSchema newJsonSchema (JsonNode schemaNode , SchemaValidatorsConfig config ) {
158
+ private JsonSchema newJsonSchema (URL schemaUrl , JsonNode schemaNode , SchemaValidatorsConfig config ) {
171
159
final ValidationContext validationContext = createValidationContext (schemaNode );
172
160
validationContext .setConfig (config );
173
- JsonSchema jsonSchema = new JsonSchema (validationContext , this . rootSchemaUrl , schemaNode );
161
+ JsonSchema jsonSchema = new JsonSchema (validationContext , schemaUrl , schemaNode );
174
162
return jsonSchema ;
175
163
}
176
164
@@ -188,33 +176,61 @@ private JsonMetaSchema findMetaSchemaForSchema(JsonNode schemaNode) {
188
176
}
189
177
return jsonMetaSchema ;
190
178
}
191
-
179
+
192
180
public JsonSchema getSchema (String schema , SchemaValidatorsConfig config ) {
193
181
try {
194
182
final JsonNode schemaNode = mapper .readTree (schema );
195
- return newJsonSchema (schemaNode , config );
183
+ return newJsonSchema (null , schemaNode , config );
184
+ } catch (IOException ioe ) {
185
+ logger .error ("Failed to load json schema!" , ioe );
186
+ throw new JsonSchemaException (ioe );
187
+ }
188
+ }
189
+
190
+ public JsonSchema getSchema (URL schemaUrl , String schema , SchemaValidatorsConfig config ) {
191
+ try {
192
+ final JsonNode schemaNode = mapper .readTree (schema );
193
+ return newJsonSchema (schemaUrl , schemaNode , config );
196
194
} catch (IOException ioe ) {
197
195
logger .error ("Failed to load json schema!" , ioe );
198
196
throw new JsonSchemaException (ioe );
199
197
}
200
198
}
201
199
202
200
public JsonSchema getSchema (String schema ) {
203
- return getSchema (schema , null );
201
+ return getSchema (null , schema , null );
202
+ }
203
+
204
+ public JsonSchema getSchema (URL schemaUrl , String schema ) {
205
+ return getSchema (schemaUrl , schema , null );
204
206
}
205
207
206
208
public JsonSchema getSchema (InputStream schemaStream , SchemaValidatorsConfig config ) {
207
209
try {
208
210
final JsonNode schemaNode = mapper .readTree (schemaStream );
209
- return newJsonSchema (schemaNode , config );
211
+ return newJsonSchema (null , schemaNode , config );
212
+ } catch (IOException ioe ) {
213
+ logger .error ("Failed to load json schema!" , ioe );
214
+ throw new JsonSchemaException (ioe );
215
+ }
216
+ }
217
+
218
+ public JsonSchema getSchema (URL schemaUrl , InputStream schemaStream , SchemaValidatorsConfig config ) {
219
+ try {
220
+ final JsonNode schemaNode = mapper .readTree (schemaStream );
221
+ return newJsonSchema (schemaUrl , schemaNode , config );
210
222
} catch (IOException ioe ) {
211
223
logger .error ("Failed to load json schema!" , ioe );
212
224
throw new JsonSchemaException (ioe );
213
225
}
214
226
}
215
227
216
228
public JsonSchema getSchema (InputStream schemaStream ) {
217
- return getSchema (schemaStream , null );
229
+ return getSchema (null , schemaStream , null );
230
+ }
231
+
232
+ public JsonSchema getSchema (URL schemaUrl , InputStream schemaStream ) {
233
+ return getSchema (schemaUrl , schemaStream , null );
218
234
}
219
235
220
236
public JsonSchema getSchema (URL schemaURL , SchemaValidatorsConfig config ) {
@@ -232,7 +248,7 @@ public JsonSchema getSchema(URL schemaURL, SchemaValidatorsConfig config) {
232
248
return new JsonSchema (new ValidationContext (jsonMetaSchema , this ), mappedURL , schemaNode , true /*retrieved via id, resolving will not change anything*/ );
233
249
}
234
250
235
- return newJsonSchema (schemaNode , config );
251
+ return newJsonSchema (mappedURL , schemaNode , config );
236
252
} finally {
237
253
if (inputStream != null ) {
238
254
inputStream .close ();
@@ -245,15 +261,23 @@ public JsonSchema getSchema(URL schemaURL, SchemaValidatorsConfig config) {
245
261
}
246
262
247
263
public JsonSchema getSchema (URL schemaURL ) {
248
- return getSchema (schemaURL , null );
264
+ return getSchema (schemaURL , new SchemaValidatorsConfig () );
249
265
}
250
266
251
267
public JsonSchema getSchema (JsonNode jsonNode , SchemaValidatorsConfig config ) {
252
- return newJsonSchema (jsonNode , config );
268
+ return newJsonSchema (null , jsonNode , config );
253
269
}
254
-
270
+
255
271
public JsonSchema getSchema (JsonNode jsonNode ) {
256
- return newJsonSchema (jsonNode , null );
272
+ return newJsonSchema (null , jsonNode , null );
273
+ }
274
+
275
+ public JsonSchema getSchema (URL schemaUrl , JsonNode jsonNode , SchemaValidatorsConfig config ) {
276
+ return newJsonSchema (schemaUrl , jsonNode , config );
277
+ }
278
+
279
+ public JsonSchema getSchema (URL schemaUrl , JsonNode jsonNode ) {
280
+ return newJsonSchema (schemaUrl , jsonNode , null );
257
281
}
258
282
259
283
private boolean idMatchesSourceUrl (JsonMetaSchema metaSchema , JsonNode schema , URL schemaUrl ) {
0 commit comments