3333import java .util .regex .Pattern ;
3434
3535public final class DefaultValidator implements Validator {
36+
37+ private static final String FORMAT_KEYWORD = "format" ;
38+
3639 private final Function <String , Schema > refResolver ;
3740
3841 public DefaultValidator (Function <String , Schema > refResolver ) {
@@ -46,7 +49,7 @@ public void validate(Object value, Schema schema, String pointer) {
4649 }
4750
4851 switch (schema ) {
49- case RefSchema r -> validate (value , refResolver .apply (r . pointer () ), pointer );
52+ case RefSchema ( String ref ) -> validate (value , refResolver .apply (ref ), pointer );
5053 case BooleanSchema _ -> validateBoolean (value , pointer );
5154 case NullSchema _ -> require (value == null , pointer , "type" , "expected null" );
5255 case StringSchema s -> validateString (value , s , pointer );
@@ -95,21 +98,21 @@ private void validateStringFormat(String str, String format, String pointer) {
9598 try {
9699 UUID .fromString (str );
97100 } catch (IllegalArgumentException _) {
98- fail (pointer , "format" , "not a valid uuid" , str );
101+ fail (pointer , FORMAT_KEYWORD , "not a valid uuid" , str );
99102 }
100103 }
101104 case "date" -> {
102105 try {
103106 LocalDate .parse (str );
104107 } catch (DateTimeParseException _) {
105- fail (pointer , "format" , "not a valid date" , str );
108+ fail (pointer , FORMAT_KEYWORD , "not a valid date" , str );
106109 }
107110 }
108111 case "date-time" -> {
109112 try {
110113 OffsetDateTime .parse (str );
111114 } catch (DateTimeParseException _) {
112- fail (pointer , "format" , "not a valid date-time" , str );
115+ fail (pointer , FORMAT_KEYWORD , "not a valid date-time" , str );
113116 }
114117 }
115118 default -> {
@@ -226,15 +229,17 @@ private void validateObject(Object value, ObjectSchema s, String pointer) {
226229 validate (entry .getValue (), propSchema , childPointer );
227230 } else {
228231 switch (s .additionalProperties ()) {
229- case AdditionalProperties .Allowed _ -> {}
232+ case AdditionalProperties .Allowed _ -> {
233+ /* no-op: additional properties are permitted by default */
234+ }
230235 case AdditionalProperties .Forbidden _ ->
231236 fail (
232237 childPointer ,
233238 "additionalProperties" ,
234239 "additional property not allowed" ,
235240 entry .getKey ());
236- case AdditionalProperties .SchemaConstraint sc ->
237- validate (entry .getValue (), sc . schema () , childPointer );
241+ case AdditionalProperties .SchemaConstraint ( Schema constraint ) ->
242+ validate (entry .getValue (), constraint , childPointer );
238243 }
239244 }
240245 }
0 commit comments