@@ -368,15 +368,9 @@ private NumberSchema.Builder buildNumberSchema() {
368
368
369
369
private ConditionalSchema .Builder buildConditionalSchema () {
370
370
ConditionalSchema .Builder builder = ConditionalSchema .builder ();
371
- if (ls .schemaJson ().containsKey ("if" )) {
372
- builder .ifSchema (loadChild (ls .schemaJson ().require ("if" ).requireObject ()).build ());
373
- }
374
- if (ls .schemaJson ().containsKey ("then" )) {
375
- builder .thenSchema (loadChild (ls .schemaJson ().require ("then" ).requireObject ()).build ());
376
- }
377
- if (ls .schemaJson ().containsKey ("else" )) {
378
- builder .elseSchema (loadChild (ls .schemaJson ().require ("else" ).requireObject ()).build ());
379
- }
371
+ ls .schemaJson ().maybe ("if" ).map (this ::loadChild ).map (Schema .Builder ::build ).ifPresent (builder ::ifSchema );
372
+ ls .schemaJson ().maybe ("then" ).map (this ::loadChild ).map (Schema .Builder ::build ).ifPresent (builder ::thenSchema );
373
+ ls .schemaJson ().maybe ("else" ).map (this ::loadChild ).map (Schema .Builder ::build ).ifPresent (builder ::elseSchema );
380
374
return builder ;
381
375
}
382
376
@@ -390,8 +384,6 @@ private Schema.Builder loadSchemaObject(JsonObject o) {
390
384
builder = buildEnumSchema ();
391
385
} else if (ls .schemaJson ().containsKey ("const" ) && (config .specVersion != DRAFT_4 )) {
392
386
builder = buildConstSchema ();
393
- } else if (config .specVersion .compareTo (DRAFT_6 ) > 0 && schemaHasAnyOf (CONDITIONAL_SCHEMA_KEYWORDS )) {
394
- builder = buildConditionalSchema ();
395
387
} else {
396
388
builder = new CombinedSchemaLoader (ls , this ).load ()
397
389
.orElseGet (() -> {
@@ -492,6 +484,8 @@ Schema.Builder<?> sniffSchemaByProps() {
492
484
return buildNumberSchema ().requiresNumber (false );
493
485
} else if (schemaHasAnyOf (STRING_SCHEMA_PROPS )) {
494
486
return new StringSchemaLoader (ls , config .formatValidators ).load ().requiresString (false );
487
+ } else if (config .specVersion .compareTo (DRAFT_6 ) > 0 && schemaHasAnyOf (CONDITIONAL_SCHEMA_KEYWORDS )) {
488
+ return buildConditionalSchema ();
495
489
}
496
490
return null ;
497
491
}
0 commit comments