Skip to content

Commit 325af6b

Browse files
committed
adding javadoc to ValidationListener
1 parent a8073ab commit 325af6b

File tree

3 files changed

+118
-1
lines changed

3 files changed

+118
-1
lines changed

core/src/main/java/org/everit/json/schema/event/ConditionalSchemaValidationEvent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public ConditionalSchemaValidationEvent(ConditionalSchema schema, Object instanc
3131
this.keyword = keyword;
3232
}
3333

34+
public Keyword getKeyword() {
35+
return keyword;
36+
}
37+
3438
@Override public boolean equals(Object o) {
3539
if (this == o)
3640
return true;

core/src/main/java/org/everit/json/schema/event/ValidationListener.java

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,143 @@
22

33
/**
44
* Interface to capture which schemas are matching against a specific event in the {@code ValidatingVisitor}.
5+
* <p>
6+
* All methods of this interface have a default empty implementation, so if an interface implementation is
7+
* interested only about a few specific event types, there is no need to add empty overrides of the unhandles events.
8+
* </p>
59
*/
610
public interface ValidationListener {
711

12+
/**
13+
* Default no-operation implementation
14+
*/
815
ValidationListener NOOP = new ValidationListener() {
916
};
1017

18+
/**
19+
* Called when a {@link org.everit.json.schema.CombinedSchema}'s given subschema matches the instance.
20+
* <p>
21+
* The {@link org.everit.json.schema.CombinedSchema} (which means an {@code "allOf"} or {@code "anyOf"} or
22+
* {@code "oneOf"} schema) can be referenced by calling {@link CombinedSchemaMatchEvent#getSchema()} and the
23+
* matching subschema is returned by {@link CombinedSchemaMatchEvent#getSubSchema()}.
24+
* </p>
25+
*/
1126
default void combinedSchemaMatch(CombinedSchemaMatchEvent event) {
1227
}
1328

29+
/**
30+
* Called when a {@link org.everit.json.schema.CombinedSchema}'s given subschema does not match the instance.
31+
* <p>
32+
* The {@link org.everit.json.schema.CombinedSchema} (which means an {@code "allOf"} or {@code "anyOf"} or
33+
* {@code "oneOf"} schema) can be referenced by calling {@link CombinedSchemaMismatchEvent#getSchema()} and the
34+
* matching subschema is returned by {@link CombinedSchemaMismatchEvent#getSubSchema()}. The validation failure
35+
* of the subschema is returned by {@link CombinedSchemaMismatchEvent#getFailure()}.
36+
* </p>
37+
*
38+
* <p>
39+
* <em>Note: the invocation of this method by the validator does not necessarily mean that the validation
40+
* against the {@link org.everit.json.schema.CombinedSchema} will fail. In the case of the {@code "anyOf"} and
41+
* {@code "oneOf"} schemas it can be an intermediate failure while the root-level schema validation still
42+
* passes.</em>
43+
* </p>
44+
*/
45+
1446
default void combinedSchemaMismatch(CombinedSchemaMismatchEvent event) {
1547
}
1648

49+
/**
50+
* Called when a {@code "$ref"} JSON reference is resolved.
51+
* <p>
52+
* The referred schema is returned by {@link SchemaReferencedEvent#getReferredSchema()}, and the
53+
* {@link org.everit.json.schema.ReferenceSchema "$ref"} itself is returned by
54+
* {@link SchemaReferencedEvent#getSchema()}
55+
* </p>
56+
*/
1757
default void schemaReferenced(SchemaReferencedEvent event) {
1858
}
1959

60+
/**
61+
* Called when an {@code "if"} schema matches.
62+
* <p>
63+
* The {@link org.everit.json.schema.ConditionalSchema} (holding both the {@code "if"}, {@code "then"} and
64+
* {@code "else"} schemas) is returned by {@link ConditionalSchemaMatchEvent#getSchema()}, and
65+
* {@link ConditionalSchemaMatchEvent#getKeyword()} always returns
66+
* {@link org.everit.json.schema.event.ConditionalSchemaValidationEvent.Keyword#IF} in this method.
67+
* </p>
68+
*
69+
* <p>
70+
* <em>Note: the invocation of this method does not necessarily mean that the validation of the
71+
* {@link org.everit.json.schema.ConditionalSchema} will succeed. Instead it means that the evaluation continues
72+
* with the {@code "then"} schema.</em>
73+
* </p>
74+
*/
2075
default void ifSchemaMatch(ConditionalSchemaMatchEvent event) {
2176
}
2277

78+
/**
79+
* Called when the instance does not pass the validation against an {@code "if"} schema.
80+
* <p>
81+
* The {@link org.everit.json.schema.ConditionalSchema} (holding both the {@code "if"}, {@code "then"} and
82+
* {@code "else"} schemas) is returned by {@link ConditionalSchemaMatchEvent#getSchema()}, and
83+
* {@link ConditionalSchemaMatchEvent#getKeyword()} always returns
84+
* {@link org.everit.json.schema.event.ConditionalSchemaValidationEvent.Keyword#IF} in this method.
85+
* </p>
86+
*
87+
* <p>
88+
* <em>Note: the invocation of this method does not necessarily mean that the validation of the
89+
* {@link org.everit.json.schema.ConditionalSchema} will fail. Instead it means that the evaluation continues
90+
* with the {@code "else"} schema.</em>
91+
* </p>
92+
*/
2393
default void ifSchemaMismatch(ConditionalSchemaMismatchEvent event) {
2494
}
2595

96+
/**
97+
* Called when the instance passes the validation against a {@code "then"} schema.
98+
* <p>
99+
* The {@link org.everit.json.schema.ConditionalSchema} (holding both the {@code "if"}, {@code "then"} and
100+
* {@code "else"} schemas) is returned by {@link ConditionalSchemaMatchEvent#getSchema()}, and
101+
* {@link ConditionalSchemaMatchEvent#getKeyword()} always returns
102+
* {@link org.everit.json.schema.event.ConditionalSchemaValidationEvent.Keyword#THEN} in this method.
103+
* </p>
104+
*/
26105
default void thenSchemaMatch(ConditionalSchemaMatchEvent event) {
27106
}
28107

108+
/**
109+
* Called when the instance does not pass the validation against a {@code "then"} schema.
110+
* <p>
111+
* The {@link org.everit.json.schema.ConditionalSchema} (holding both the {@code "if"}, {@code "then"} and
112+
* {@code "else"} schemas) is returned by {@link ConditionalSchemaMatchEvent#getSchema()}, and
113+
* {@link ConditionalSchemaMatchEvent#getKeyword()} always returns
114+
* {@link org.everit.json.schema.event.ConditionalSchemaValidationEvent.Keyword#THEN} in this method.
115+
* </p>
116+
*/
29117
default void thenSchemaMismatch(ConditionalSchemaMismatchEvent event) {
30118
}
31119

120+
/**
121+
* Called when the instance passes the validation against a {@code "else"} schema.
122+
* <p>
123+
* The {@link org.everit.json.schema.ConditionalSchema} (holding both the {@code "if"}, {@code "then"} and
124+
* {@code "else"} schemas) is returned by {@link ConditionalSchemaMatchEvent#getSchema()}, and
125+
* {@link ConditionalSchemaMatchEvent#getKeyword()} always returns
126+
* {@link org.everit.json.schema.event.ConditionalSchemaValidationEvent.Keyword#ELSE} in this method.
127+
* </p>
128+
*/
32129
default void elseSchemaMatch(ConditionalSchemaMatchEvent event) {
33130

34131
}
35132

133+
/**
134+
* Called when the instance does not pass the validation against a {@code "else"} schema.
135+
* <p>
136+
* The {@link org.everit.json.schema.ConditionalSchema} (holding both the {@code "if"}, {@code "then"} and
137+
* {@code "else"} schemas) is returned by {@link ConditionalSchemaMatchEvent#getSchema()}, and
138+
* {@link ConditionalSchemaMatchEvent#getKeyword()} always returns
139+
* {@link org.everit.json.schema.event.ConditionalSchemaValidationEvent.Keyword#ELSE} in this method.
140+
* </p>
141+
*/
36142
default void elseSchemaMismatch(ConditionalSchemaMismatchEvent event) {
37143
}
38144
}

core/src/test/java/org/everit/json/schema/ConditionalSchemaEventsTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ public class ConditionalSchemaEventsTest {
3535
}
3636

3737
private void validateInstance(String instance) {
38-
new ValidatingVisitor(instance, reporter, ReadWriteValidator.NONE, listener).visit(schema);
38+
try {
39+
Validator.builder()
40+
.withListener(listener)
41+
.build()
42+
.performValidation(schema, instance);
43+
} catch (ValidationException e) {
44+
// intentionally ignored
45+
}
3946
}
4047

4148
@Test

0 commit comments

Comments
 (0)