Skip to content

Commit 512b465

Browse files
committed
Remove hard coded instance location for the error message
1 parent 4d59bac commit 512b465

File tree

75 files changed

+2128
-2123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2128
-2123
lines changed

src/main/java/com/networknt/schema/DefaultJsonMetaSchemaFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected JsonMetaSchema loadMetaSchema(String iri, JsonSchemaFactory schemaFact
4646
throw e;
4747
} catch (Exception e) {
4848
ValidationMessage validationMessage = ValidationMessage.builder()
49-
.message("Failed to load meta-schema ''{1}''").arguments(iri).build();
49+
.message("Failed to load meta-schema ''{0}''").arguments(iri).build();
5050
throw new InvalidSchemaException(validationMessage, e);
5151
}
5252
}

src/main/java/com/networknt/schema/DisallowUnknownJsonMetaSchemaFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class DisallowUnknownJsonMetaSchemaFactory implements JsonMetaSchemaFacto
2323
@Override
2424
public JsonMetaSchema getMetaSchema(String iri, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config) {
2525
throw new InvalidSchemaException(ValidationMessage.builder()
26-
.message("Unknown meta-schema ''{1}''. Only meta-schemas that are explicitly configured can be used.")
26+
.message("Unknown meta-schema ''{0}''. Only meta-schemas that are explicitly configured can be used.")
2727
.arguments(iri).build());
2828
}
2929

src/main/java/com/networknt/schema/DisallowUnknownKeywordFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class DisallowUnknownKeywordFactory implements KeywordFactory {
2828
public Keyword getKeyword(String value, ValidationContext validationContext) {
2929
logger.error("Keyword '{}' is unknown and must be configured on the meta-schema or vocabulary", value);
3030
throw new InvalidSchemaException(ValidationMessage.builder()
31-
.message("Keyword ''{1}'' is unknown and must be configured on the meta-schema or vocabulary")
31+
.message("Keyword ''{0}'' is unknown and must be configured on the meta-schema or vocabulary")
3232
.arguments(value).build());
3333
}
3434

src/main/java/com/networknt/schema/DynamicRefValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void validate(ExecutionContext executionContext, JsonNode node, JsonNode
9595
JsonSchema refSchema = this.schema.getSchema();
9696
if (refSchema == null) {
9797
ValidationMessage validationMessage = message().keyword(ValidatorTypeCode.DYNAMIC_REF.getValue())
98-
.messageKey("internal.unresolvedRef").message("{0}: Reference {1} cannot be resolved")
98+
.messageKey("internal.unresolvedRef").message("Reference {0} cannot be resolved")
9999
.instanceLocation(instanceLocation).evaluationPath(getEvaluationPath())
100100
.arguments(schemaNode.asText()).build();
101101
throw new InvalidSchemaRefException(validationMessage);
@@ -112,7 +112,7 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
112112
JsonSchema refSchema = this.schema.getSchema();
113113
if (refSchema == null) {
114114
ValidationMessage validationMessage = message().keyword(ValidatorTypeCode.DYNAMIC_REF.getValue())
115-
.messageKey("internal.unresolvedRef").message("{0}: Reference {1} cannot be resolved")
115+
.messageKey("internal.unresolvedRef").message("Reference {0} cannot be resolved")
116116
.instanceLocation(instanceLocation).evaluationPath(getEvaluationPath())
117117
.arguments(schemaNode.asText()).build();
118118
throw new InvalidSchemaRefException(validationMessage);

src/main/java/com/networknt/schema/JsonMetaSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public JsonMetaSchema build() {
284284
}
285285
} else if (Boolean.TRUE.equals(entry.getValue())) {
286286
ValidationMessage validationMessage = ValidationMessage.builder()
287-
.message("Meta-schema ''{1}'' has unknown required vocabulary ''{2}''")
287+
.message("Meta-schema ''{0}'' has unknown required vocabulary ''{1}''")
288288
.arguments(this.iri, id).build();
289289
throw new InvalidSchemaException(validationMessage);
290290
}

src/main/java/com/networknt/schema/JsonSchema.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ public JsonSchema getSubSchema(JsonNodePath fragment) {
510510
if (found == null) {
511511
ValidationMessage validationMessage = ValidationMessage.builder()
512512
.keyword(ValidatorTypeCode.REF.getValue()).messageKey("internal.unresolvedRef")
513-
.message("{0}: Reference {1} cannot be resolved")
513+
.message("Reference {0} cannot be resolved")
514514
.instanceLocation(schemaLocation.getFragment())
515515
.schemaLocation(schemaLocation)
516516
.evaluationPath(evaluationPath)
@@ -630,7 +630,7 @@ private List<JsonValidator> read(JsonNode schemaNode) {
630630
ValidationMessage validationMessage = ValidationMessage.builder().keyword("$recursiveAnchor")
631631
.messageKey("internal.invalidRecursiveAnchor")
632632
.message(
633-
"{0}: The value of a $recursiveAnchor must be a Boolean literal but is {1}")
633+
"The value of a $recursiveAnchor must be a Boolean literal but is {0}")
634634
.instanceLocation(path)
635635
.evaluationPath(path)
636636
.schemaLocation(schemaPath)

src/main/java/com/networknt/schema/RecursiveRefValidator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public RecursiveRefValidator(SchemaLocation schemaLocation, JsonNodePath evaluat
3737
if (!"#".equals(refValue)) {
3838
ValidationMessage validationMessage = message()
3939
.keyword(ValidatorTypeCode.RECURSIVE_REF.getValue()).messageKey("internal.invalidRecursiveRef")
40-
.message("{0}: The value of a $recursiveRef must be '#' but is '{1}'").instanceLocation(schemaLocation.getFragment())
40+
.message("The value of a $recursiveRef must be '#' but is '{0}'").instanceLocation(schemaLocation.getFragment())
4141
.instanceNode(this.schemaNode)
4242
.evaluationPath(evaluationPath).arguments(refValue).build();
4343
throw new JsonSchemaException(validationMessage);
@@ -90,7 +90,7 @@ public void validate(ExecutionContext executionContext, JsonNode node, JsonNode
9090
JsonSchema refSchema = this.schema.getSchema();
9191
if (refSchema == null) {
9292
ValidationMessage validationMessage = message().keyword(ValidatorTypeCode.RECURSIVE_REF.getValue())
93-
.messageKey("internal.unresolvedRef").message("{0}: Reference {1} cannot be resolved")
93+
.messageKey("internal.unresolvedRef").message("Reference {0} cannot be resolved")
9494
.instanceLocation(instanceLocation).evaluationPath(getEvaluationPath())
9595
.arguments(schemaNode.asText()).build();
9696
throw new InvalidSchemaRefException(validationMessage);
@@ -107,7 +107,7 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
107107
JsonSchema refSchema = this.schema.getSchema();
108108
if (refSchema == null) {
109109
ValidationMessage validationMessage = message().keyword(ValidatorTypeCode.RECURSIVE_REF.getValue())
110-
.messageKey("internal.unresolvedRef").message("{0}: Reference {1} cannot be resolved")
110+
.messageKey("internal.unresolvedRef").message("Reference {0} cannot be resolved")
111111
.instanceLocation(instanceLocation).evaluationPath(getEvaluationPath())
112112
.arguments(schemaNode.asText()).build();
113113
throw new InvalidSchemaRefException(validationMessage);

src/main/java/com/networknt/schema/RefValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void validate(ExecutionContext executionContext, JsonNode node, JsonNode
179179
JsonSchema refSchema = this.schema.getSchema();
180180
if (refSchema == null) {
181181
ValidationMessage validationMessage = message().keyword(ValidatorTypeCode.REF.getValue())
182-
.messageKey("internal.unresolvedRef").message("{0}: Reference {1} cannot be resolved")
182+
.messageKey("internal.unresolvedRef").message("Reference {0} cannot be resolved")
183183
.instanceLocation(instanceLocation).evaluationPath(getEvaluationPath())
184184
.arguments(schemaNode.asText()).build();
185185
throw new InvalidSchemaRefException(validationMessage);
@@ -196,7 +196,7 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
196196
JsonSchema refSchema = this.schema.getSchema();
197197
if (refSchema == null) {
198198
ValidationMessage validationMessage = message().keyword(ValidatorTypeCode.REF.getValue())
199-
.messageKey("internal.unresolvedRef").message("{0}: Reference {1} cannot be resolved")
199+
.messageKey("internal.unresolvedRef").message("Reference {0} cannot be resolved")
200200
.instanceLocation(instanceLocation).evaluationPath(getEvaluationPath())
201201
.arguments(schemaNode.asText()).build();
202202
throw new InvalidSchemaRefException(validationMessage);

src/main/java/com/networknt/schema/ValidationMessage.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* Schema</a>
4242
*/
4343
@JsonIgnoreProperties({ "messageSupplier", "schemaNode", "instanceNode", "valid", "error" })
44-
@JsonPropertyOrder({ "type", "code", "message", "instanceLocation", "property", "evaluationPath", "schemaLocation",
44+
@JsonPropertyOrder({ "keyword", "instanceLocation", "message", "evaluationPath", "schemaLocation",
4545
"messageKey", "arguments", "details" })
4646
@JsonInclude(Include.NON_NULL)
4747
public class ValidationMessage {
@@ -202,7 +202,17 @@ public String getError() {
202202

203203
@Override
204204
public String toString() {
205-
return messageSupplier.get();
205+
StringBuilder builder = new StringBuilder();
206+
if (instanceLocation != null) {
207+
// Validation Error
208+
builder.append(instanceLocation.toString());
209+
} else if (schemaLocation != null) {
210+
// Parse Error
211+
builder.append(schemaLocation.toString());
212+
}
213+
builder.append(": ");
214+
builder.append(messageSupplier.get());
215+
return builder.toString();
206216
}
207217

208218
@Override
@@ -400,14 +410,9 @@ public ValidationMessage build() {
400410
return new ValidationMessage(keyword, evaluationPath, schemaLocation, instanceLocation,
401411
arguments, details, messageKey, messageSupplier, this.instanceNode, this.schemaNode);
402412
}
403-
413+
404414
protected Object[] getMessageArguments() {
405-
Object[] objs = new Object[(arguments == null ? 0 : arguments.length) + 1];
406-
objs[0] = instanceLocation;
407-
if (arguments != null) {
408-
System.arraycopy(arguments, 0, objs, 1, objs.length - 1);
409-
}
410-
return objs;
415+
return arguments;
411416
}
412417

413418
protected String getKeyword() {

src/main/java/com/networknt/schema/regex/AllowRegularExpressionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ public RegularExpression getRegularExpression(String regex) {
3939
return this.delegate.getRegularExpression(regex);
4040
}
4141
throw new InvalidSchemaException(ValidationMessage.builder()
42-
.message("Regular expression ''{1}'' is not allowed to be used.").arguments(regex).build());
42+
.message("Regular expression ''{0}'' is not allowed to be used.").arguments(regex).build());
4343
}
4444
}

0 commit comments

Comments
 (0)