1818
1919import com .networknt .schema .i18n .DefaultMessageSource ;
2020import com .networknt .schema .i18n .MessageSource ;
21+ import com .networknt .schema .path .JsonPointer ;
2122import com .networknt .schema .regex .ECMAScriptRegularExpressionFactory ;
2223import com .networknt .schema .regex .JDKRegularExpressionFactory ;
2324import com .networknt .schema .regex .RegularExpressionFactory ;
2627import java .util .Locale ;
2728import java .util .Map ;
2829import java .util .Objects ;
30+ import java .util .function .Supplier ;
2931
3032/**
3133 * Configuration for SchemaRegistry that applies to all the schemas its
@@ -98,7 +100,7 @@ public static SchemaRegistryConfig getInstance() {
98100 /**
99101 * The approach used to generate paths in reported messages, logs and errors. Default is the legacy "JSONPath-like" approach.
100102 */
101- private final PathType pathType ;
103+ private final Supplier < NodePath > nodePathFactory ;
102104
103105 /**
104106 * Controls if the schema will automatically be preloaded.
@@ -140,7 +142,7 @@ protected SchemaRegistryConfig(boolean cacheRefs,
140142 Boolean formatAssertionsEnabled ,
141143 boolean javaSemantics ,
142144 Locale locale , boolean losslessNarrowing ,
143- MessageSource messageSource , PathType pathType ,
145+ MessageSource messageSource , Supplier < NodePath > nodePathFactory ,
144146 boolean preloadSchema , int preloadSchemaRefMaxNestingDepth ,
145147 RegularExpressionFactory regularExpressionFactory , SchemaIdValidator schemaIdValidator ,
146148 Map <String , Boolean > strictness , boolean typeLoose ) {
@@ -154,7 +156,7 @@ protected SchemaRegistryConfig(boolean cacheRefs,
154156 this .locale = locale ;
155157 this .losslessNarrowing = losslessNarrowing ;
156158 this .messageSource = messageSource ;
157- this .pathType = pathType ;
159+ this .nodePathFactory = nodePathFactory ;
158160 this .preloadSchema = preloadSchema ;
159161 this .preloadSchemaRefMaxNestingDepth = preloadSchemaRefMaxNestingDepth ;
160162 this .regularExpressionFactory = regularExpressionFactory ;
@@ -216,8 +218,8 @@ public MessageSource getMessageSource() {
216218 *
217219 * @return The path generation approach.
218220 */
219- public PathType getPathType () {
220- return this .pathType ;
221+ public Supplier < NodePath > getNodePathFactory () {
222+ return this .nodePathFactory ;
221223 }
222224
223225 /**
@@ -349,7 +351,7 @@ public static Builder builder(SchemaRegistryConfig config) {
349351 builder .locale = config .locale ;
350352 builder .losslessNarrowing = config .losslessNarrowing ;
351353 builder .messageSource = config .messageSource ;
352- builder .pathType = config .pathType ;
354+ builder .nodePathFactory = config .nodePathFactory ;
353355 builder .preloadSchema = config .preloadSchema ;
354356 builder .preloadSchemaRefMaxNestingDepth = config .preloadSchemaRefMaxNestingDepth ;
355357 builder .regularExpressionFactory = config .regularExpressionFactory ;
@@ -382,7 +384,7 @@ public static abstract class BuilderSupport<T> {
382384 protected Locale locale = null ; // This must be null to use Locale.getDefault() as the default can be changed
383385 protected boolean losslessNarrowing = false ;
384386 protected MessageSource messageSource = null ;
385- protected PathType pathType = PathType . JSON_POINTER ;
387+ protected Supplier < NodePath > nodePathFactory = JsonPointer :: getRoot ;
386388 protected boolean preloadSchema = true ;
387389 protected int preloadSchemaRefMaxNestingDepth = DEFAULT_PRELOAD_SCHEMA_REF_MAX_NESTING_DEPTH ;
388390 protected RegularExpressionFactory regularExpressionFactory = JDKRegularExpressionFactory .getInstance ();
@@ -497,13 +499,13 @@ public T messageSource(MessageSource messageSource) {
497499 /**
498500 * Sets the path type to use when reporting the instance location of errors.
499501 * <p>
500- * Defaults to {@link PathType#JSON_POINTER }.
502+ * Defaults to {@link JsonPointer#getRoot() }.
501503 *
502- * @param pathType the path type
503- * @return the path type
504+ * @param nodePathFactory the node path factory
505+ * @return the node path factory
504506 */
505- public T pathType ( PathType pathType ) {
506- this .pathType = pathType ;
507+ public T nodePathFactory ( Supplier < NodePath > nodePathFactory ) {
508+ this .nodePathFactory = nodePathFactory ;
507509 return self ();
508510 }
509511 /**
@@ -575,7 +577,7 @@ public SchemaRegistryConfig build() {
575577 return new SchemaRegistryConfig (cacheRefs , errorMessageKeyword ,
576578 executionContextCustomizer , failFast , formatAssertionsEnabled ,
577579 javaSemantics , locale , losslessNarrowing , messageSource ,
578- pathType , preloadSchema , preloadSchemaRefMaxNestingDepth ,
580+ nodePathFactory , preloadSchema , preloadSchemaRefMaxNestingDepth ,
579581 regularExpressionFactory , schemaIdValidator , strictness , typeLoose
580582 );
581583 }
0 commit comments