@@ -50,8 +50,6 @@ public static class Builder {
50
50
private URNFactory urnFactory ;
51
51
private final Map <String , JsonMetaSchema > jsonMetaSchemas = new HashMap <String , JsonMetaSchema >();
52
52
private final Map <String , String > uriMap = new HashMap <String , String >();
53
- private boolean forceHttps = true ;
54
- private boolean removeEmptyFragmentSuffix = true ;
55
53
private boolean enableUriSchemaCache = true ;
56
54
private final CompositeURITranslator uriTranslators = new CompositeURITranslator ();
57
55
@@ -129,13 +127,13 @@ public Builder uriFetcher(final URIFetcher uriFetcher, final Iterable<String> sc
129
127
}
130
128
131
129
public Builder addMetaSchema (final JsonMetaSchema jsonMetaSchema ) {
132
- this .jsonMetaSchemas .put (jsonMetaSchema .getUri (), jsonMetaSchema );
130
+ this .jsonMetaSchemas .put (normalizeMetaSchemaUri ( jsonMetaSchema .getUri ()) , jsonMetaSchema );
133
131
return this ;
134
132
}
135
133
136
134
public Builder addMetaSchemas (final Collection <? extends JsonMetaSchema > jsonMetaSchemas ) {
137
135
for (JsonMetaSchema jsonMetaSchema : jsonMetaSchemas ) {
138
- this . jsonMetaSchemas . put ( jsonMetaSchema . getUri (), jsonMetaSchema );
136
+ addMetaSchema ( jsonMetaSchema );
139
137
}
140
138
return this ;
141
139
}
@@ -163,13 +161,21 @@ public Builder addUrnFactory(URNFactory urnFactory) {
163
161
return this ;
164
162
}
165
163
164
+ /**
165
+ * @deprecated No longer necessary.
166
+ * @param forceHttps ignored.
167
+ * @return this builder.
168
+ */
166
169
public Builder forceHttps (boolean forceHttps ) {
167
- this .forceHttps = forceHttps ;
168
170
return this ;
169
171
}
170
172
173
+ /**
174
+ * @deprecated No longer necessary.
175
+ * @param removeEmptyFragmentSuffix ignored.
176
+ * @return this builder.
177
+ */
171
178
public Builder removeEmptyFragmentSuffix (boolean removeEmptyFragmentSuffix ) {
172
- this .removeEmptyFragmentSuffix = removeEmptyFragmentSuffix ;
173
179
return this ;
174
180
}
175
181
@@ -189,8 +195,6 @@ public JsonSchemaFactory build() {
189
195
urnFactory ,
190
196
jsonMetaSchemas ,
191
197
uriMap ,
192
- forceHttps ,
193
- removeEmptyFragmentSuffix ,
194
198
enableUriSchemaCache ,
195
199
uriTranslators
196
200
);
@@ -207,8 +211,6 @@ public JsonSchemaFactory build() {
207
211
private final Map <String , JsonMetaSchema > jsonMetaSchemas ;
208
212
private final Map <String , String > uriMap ;
209
213
private final ConcurrentMap <URI , JsonSchema > uriSchemaCache = new ConcurrentHashMap <URI , JsonSchema >();
210
- private final boolean forceHttps ;
211
- private final boolean removeEmptyFragmentSuffix ;
212
214
private final boolean enableUriSchemaCache ;
213
215
214
216
@@ -221,8 +223,6 @@ private JsonSchemaFactory(
221
223
final URNFactory urnFactory ,
222
224
final Map <String , JsonMetaSchema > jsonMetaSchemas ,
223
225
final Map <String , String > uriMap ,
224
- final boolean forceHttps ,
225
- final boolean removeEmptyFragmentSuffix ,
226
226
final boolean enableUriSchemaCache ,
227
227
final CompositeURITranslator uriTranslators ) {
228
228
if (jsonMapper == null ) {
@@ -237,7 +237,7 @@ private JsonSchemaFactory(
237
237
throw new IllegalArgumentException ("URIFetcher must not be null" );
238
238
} else if (jsonMetaSchemas == null || jsonMetaSchemas .isEmpty ()) {
239
239
throw new IllegalArgumentException ("Json Meta Schemas must not be null or empty" );
240
- } else if (jsonMetaSchemas .get (defaultMetaSchemaURI ) == null ) {
240
+ } else if (jsonMetaSchemas .get (normalizeMetaSchemaUri ( defaultMetaSchemaURI ) ) == null ) {
241
241
throw new IllegalArgumentException ("Meta Schema for default Meta Schema URI must be provided" );
242
242
} else if (uriMap == null ) {
243
243
throw new IllegalArgumentException ("URL Mappings must not be null" );
@@ -252,8 +252,6 @@ private JsonSchemaFactory(
252
252
this .urnFactory = urnFactory ;
253
253
this .jsonMetaSchemas = jsonMetaSchemas ;
254
254
this .uriMap = uriMap ;
255
- this .forceHttps = forceHttps ;
256
- this .removeEmptyFragmentSuffix = removeEmptyFragmentSuffix ;
257
255
this .enableUriSchemaCache = enableUriSchemaCache ;
258
256
this .uriTranslators = uriTranslators ;
259
257
}
@@ -348,7 +346,7 @@ private JsonMetaSchema findMetaSchemaForSchema(final JsonNode schemaNode) {
348
346
if (uriNode != null && !uriNode .isNull () && !uriNode .isTextual ()) {
349
347
throw new JsonSchemaException ("Unknown MetaSchema: " + uriNode .toString ());
350
348
}
351
- final String uri = uriNode == null || uriNode .isNull () ? defaultMetaSchemaURI : normalizeMetaSchemaUri (uriNode .textValue (), forceHttps , removeEmptyFragmentSuffix );
349
+ final String uri = uriNode == null || uriNode .isNull () ? defaultMetaSchemaURI : normalizeMetaSchemaUri (uriNode .textValue ());
352
350
final JsonMetaSchema jsonMetaSchema = jsonMetaSchemas .computeIfAbsent (uri , this ::fromId );
353
351
return jsonMetaSchema ;
354
352
}
@@ -504,17 +502,12 @@ private boolean isYaml(final URI schemaUri) {
504
502
return (".yml" .equals (extension ) || ".yaml" .equals (extension ));
505
503
}
506
504
507
- static protected String normalizeMetaSchemaUri (String u , boolean forceHttps , boolean removeEmptyFragmentSuffix ) {
505
+ static protected String normalizeMetaSchemaUri (String u ) {
508
506
try {
509
507
URI uri = new URI (u );
510
- String scheme = forceHttps ? "https" : uri .getScheme ();
511
- URI newUri = new URI (scheme , uri .getUserInfo (), uri .getHost (), uri .getPort (), uri .getPath (), null , null );
508
+ URI newUri = new URI ("https" , uri .getUserInfo (), uri .getHost (), uri .getPort (), uri .getPath (), null , null );
512
509
513
- if (!removeEmptyFragmentSuffix && u .endsWith ("#" )) {
514
- return newUri + "#" ;
515
- } else {
516
- return newUri .toString ();
517
- }
510
+ return newUri .toString ();
518
511
} catch (URISyntaxException e ) {
519
512
throw new JsonSchemaException ("Wrong MetaSchema URI: " + u );
520
513
}
0 commit comments