2121import java .math .BigDecimal ;
2222import java .time .LocalDate ;
2323import java .time .OffsetDateTime ;
24+ import java .time .format .DateTimeParseException ;
2425import java .util .ArrayList ;
2526import java .util .HashSet ;
2627import java .util .List ;
@@ -46,21 +47,21 @@ public void validate(Object value, Schema schema, String pointer) {
4647
4748 switch (schema ) {
4849 case RefSchema r -> validate (value , refResolver .apply (r .pointer ()), pointer );
49- case BooleanSchema b -> validateBoolean (value , pointer );
50- case NullSchema n -> require (value == null , pointer , "type" , "expected null" );
50+ case BooleanSchema _ -> validateBoolean (value , pointer );
51+ case NullSchema _ -> require (value == null , pointer , "type" , "expected null" );
5152 case StringSchema s -> validateString (value , s , pointer );
5253 case IntegerSchema i -> validateInteger (value , i , pointer );
5354 case NumberSchema n -> validateNumber (value , n , pointer );
5455 case ObjectSchema o -> validateObject (value , o , pointer );
5556 case ArraySchema a -> validateArray (value , a , pointer );
56- case EnumSchema e ->
57- require (e . values () .contains (value ), pointer , "enum" , "value not in enum" );
58- case ConstSchema c ->
59- require (Objects .equals (c . value () , value ), pointer , "const" , "value does not equal const" );
60- case OneOfSchema o -> throw new UnsupportedOperationException ("oneOf not yet supported" );
61- case AnyOfSchema a -> throw new UnsupportedOperationException ("anyOf not yet supported" );
62- case AllOfSchema a -> throw new UnsupportedOperationException ("allOf not yet supported" );
63- case NotSchema n -> throw new UnsupportedOperationException ("not not yet supported" );
57+ case EnumSchema ( List < Object > values ) ->
58+ require (values .contains (value ), pointer , "enum" , "value not in enum" );
59+ case ConstSchema ( Object expected ) ->
60+ require (Objects .equals (expected , value ), pointer , "const" , "value does not equal const" );
61+ case OneOfSchema _ -> throw new UnsupportedOperationException ("oneOf not yet supported" );
62+ case AnyOfSchema _ -> throw new UnsupportedOperationException ("anyOf not yet supported" );
63+ case AllOfSchema _ -> throw new UnsupportedOperationException ("allOf not yet supported" );
64+ case NotSchema _ -> throw new UnsupportedOperationException ("not not yet supported" );
6465 }
6566 }
6667
@@ -93,42 +94,46 @@ private void validateStringFormat(String str, String format, String pointer) {
9394 case "uuid" -> {
9495 try {
9596 UUID .fromString (str );
96- } catch (IllegalArgumentException e ) {
97+ } catch (IllegalArgumentException _ ) {
9798 fail (pointer , "format" , "not a valid uuid" , str );
9899 }
99100 }
100101 case "date" -> {
101102 try {
102103 LocalDate .parse (str );
103- } catch (Exception e ) {
104+ } catch (DateTimeParseException _ ) {
104105 fail (pointer , "format" , "not a valid date" , str );
105106 }
106107 }
107108 case "date-time" -> {
108109 try {
109110 OffsetDateTime .parse (str );
110- } catch (Exception e ) {
111+ } catch (DateTimeParseException _ ) {
111112 fail (pointer , "format" , "not a valid date-time" , str );
112113 }
113114 }
114- default -> {}
115+ default -> {
116+ /* unknown format ignored — handled in 3.1 follow-up */
117+ }
115118 }
116119 }
117120
118121 private void validateInteger (Object value , IntegerSchema s , String pointer ) {
119122 long n ;
120- if (value instanceof Number num ) {
121- n = num .longValue ();
122- } else if (value instanceof String str ) {
123- try {
124- n = Long .parseLong (str );
125- } catch (NumberFormatException e ) {
123+ switch (value ) {
124+ case Number num -> n = num .longValue ();
125+ case String str -> {
126+ try {
127+ n = Long .parseLong (str );
128+ } catch (NumberFormatException _) {
129+ fail (pointer , "type" , "expected integer" , value );
130+ return ;
131+ }
132+ }
133+ case null , default -> {
126134 fail (pointer , "type" , "expected integer" , value );
127135 return ;
128136 }
129- } else {
130- fail (pointer , "type" , "expected integer" , value );
131- return ;
132137 }
133138
134139 if (s .minimum () != null && n < s .minimum ()) {
@@ -150,18 +155,20 @@ private void validateInteger(Object value, IntegerSchema s, String pointer) {
150155
151156 private void validateNumber (Object value , NumberSchema s , String pointer ) {
152157 double n ;
153- if (value instanceof Number num ) {
154- n = num .doubleValue ();
155- } else if (value instanceof String str ) {
156- try {
157- n = Double .parseDouble (str );
158- } catch (NumberFormatException e ) {
158+ switch (value ) {
159+ case Number num -> n = num .doubleValue ();
160+ case String str -> {
161+ try {
162+ n = Double .parseDouble (str );
163+ } catch (NumberFormatException _) {
164+ fail (pointer , "type" , "expected number" , value );
165+ return ;
166+ }
167+ }
168+ case null , default -> {
159169 fail (pointer , "type" , "expected number" , value );
160170 return ;
161171 }
162- } else {
163- fail (pointer , "type" , "expected number" , value );
164- return ;
165172 }
166173
167174 if (s .minimum () != null && n < s .minimum ().doubleValue ()) {
@@ -219,8 +226,8 @@ private void validateObject(Object value, ObjectSchema s, String pointer) {
219226 validate (entry .getValue (), propSchema , childPointer );
220227 } else {
221228 switch (s .additionalProperties ()) {
222- case AdditionalProperties .Allowed a -> {}
223- case AdditionalProperties .Forbidden f ->
229+ case AdditionalProperties .Allowed _ -> {}
230+ case AdditionalProperties .Forbidden _ ->
224231 fail (
225232 childPointer ,
226233 "additionalProperties" ,
0 commit comments