@@ -47,6 +47,7 @@ public static class Builder {
4747 private URNFactory urnFactory ;
4848 private final Map <String , JsonMetaSchema > jsonMetaSchemas = new HashMap <String , JsonMetaSchema >();
4949 private final Map <String , String > uriMap = new HashMap <String , String >();
50+ private boolean forceHttps = true ;
5051
5152
5253 public Builder () {
@@ -139,7 +140,10 @@ public Builder addUrnFactory(URNFactory urnFactory) {
139140 return this ;
140141 }
141142
142-
143+ public Builder forceHttps (boolean forceHttps ) {
144+ this .forceHttps = forceHttps ;
145+ return this ;
146+ }
143147
144148 public JsonSchemaFactory build () {
145149 // create builtin keywords with (custom) formats.
@@ -150,7 +154,8 @@ public JsonSchemaFactory build() {
150154 new URISchemeFetcher (uriFetcherMap ),
151155 urnFactory ,
152156 jsonMetaSchemas ,
153- uriMap
157+ uriMap ,
158+ forceHttps
154159 );
155160 }
156161 }
@@ -163,6 +168,7 @@ public JsonSchemaFactory build() {
163168 private final Map <String , JsonMetaSchema > jsonMetaSchemas ;
164169 private final Map <String , String > uriMap ;
165170 private final ConcurrentMap <URI , JsonSchema > uriSchemaCache = new ConcurrentHashMap <URI , JsonSchema >();
171+ private final boolean forceHttps ;
166172
167173
168174 private JsonSchemaFactory (
@@ -172,7 +178,8 @@ private JsonSchemaFactory(
172178 final URISchemeFetcher uriFetcher ,
173179 final URNFactory urnFactory ,
174180 final Map <String , JsonMetaSchema > jsonMetaSchemas ,
175- final Map <String , String > uriMap ) {
181+ final Map <String , String > uriMap ,
182+ final boolean forceHttps ) {
176183 if (mapper == null ) {
177184 throw new IllegalArgumentException ("ObjectMapper must not be null" );
178185 } else if (defaultMetaSchemaURI == null || defaultMetaSchemaURI .trim ().isEmpty ()) {
@@ -195,6 +202,7 @@ private JsonSchemaFactory(
195202 this .urnFactory = urnFactory ;
196203 this .jsonMetaSchemas = jsonMetaSchemas ;
197204 this .uriMap = uriMap ;
205+ this .forceHttps = forceHttps ;
198206 }
199207
200208 /**
@@ -273,7 +281,7 @@ protected ValidationContext createValidationContext(final JsonNode schemaNode) {
273281
274282 private JsonMetaSchema findMetaSchemaForSchema (final JsonNode schemaNode ) {
275283 final JsonNode uriNode = schemaNode .get ("$schema" );
276- final String uri = uriNode == null || uriNode .isNull () ? defaultMetaSchemaURI : normalizeMetaSchemaUri (uriNode .textValue ());
284+ final String uri = uriNode == null || uriNode .isNull () ? defaultMetaSchemaURI : normalizeMetaSchemaUri (uriNode .textValue (), forceHttps );
277285 final JsonMetaSchema jsonMetaSchema = jsonMetaSchemas .get (uri );
278286 if (jsonMetaSchema == null ) {
279287 throw new JsonSchemaException ("Unknown MetaSchema: " + uri );
@@ -395,10 +403,11 @@ private boolean idMatchesSourceUri(final JsonMetaSchema metaSchema, final JsonNo
395403 return result ;
396404 }
397405
398- static protected String normalizeMetaSchemaUri (String u ) {
406+ static protected String normalizeMetaSchemaUri (String u , boolean forceHttps ) {
399407 try {
400408 URI uri = new URI (u );
401- URI newUri = new URI ("https" , uri .getUserInfo (), uri .getHost (), uri .getPort (), uri .getPath (), null , null );
409+ String scheme = forceHttps ? "https" : uri .getScheme ();
410+ URI newUri = new URI (scheme , uri .getUserInfo (), uri .getHost (), uri .getPort (), uri .getPath (), null , null );
402411 return newUri .toString ();
403412 } catch (URISyntaxException e ) {
404413 throw new JsonSchemaException ("Wrong MetaSchema URI: " + u );
0 commit comments