14
14
import java .util .ArrayList ;
15
15
import java .util .Collection ;
16
16
import java .util .HashMap ;
17
- import java .util .HashSet ;
18
17
import java .util .List ;
19
18
import java .util .Map ;
20
19
import java .util .Objects ;
21
20
import java .util .Optional ;
22
- import java .util .Set ;
23
21
import java .util .function .Supplier ;
24
22
25
23
import org .everit .json .schema .ArraySchema ;
28
26
import org .everit .json .schema .ConditionalSchema ;
29
27
import org .everit .json .schema .ConstSchema ;
30
28
import org .everit .json .schema .EmptySchema ;
31
- import org .everit .json .schema .EnumSchema ;
32
29
import org .everit .json .schema .FalseSchema ;
33
30
import org .everit .json .schema .FormatValidator ;
34
31
import org .everit .json .schema .NotSchema ;
@@ -356,14 +353,6 @@ private Schema.Builder buildConstSchema() {
356
353
.permittedValue (ls .schemaJson ().require ("const" ).unwrap ());
357
354
}
358
355
359
- private EnumSchema .Builder buildEnumSchema () {
360
- EnumSchema .Builder builder = EnumSchema .builder ();
361
- Set <Object > possibleValues = new HashSet <>();
362
- ls .schemaJson ().require ("enum" ).requireArray ().forEach ((i , item ) -> possibleValues .add (item .unwrap ()));
363
- builder .possibleValues (possibleValues );
364
- return builder ;
365
- }
366
-
367
356
private NotSchema .Builder buildNotSchema () {
368
357
Schema mustNotMatch = loadChild (ls .schemaJson ().require ("not" )).build ();
369
358
return NotSchema .builder ().mustNotMatch (mustNotMatch );
@@ -373,10 +362,6 @@ private Schema.Builder<?> buildSchemaWithoutExplicitType() {
373
362
if (ls .schemaJson ().isEmpty ()) {
374
363
return EmptySchema .builder ();
375
364
}
376
- if (ls .schemaJson ().containsKey ("$ref" )) {
377
- String ref = ls .schemaJson ().require ("$ref" ).requireString ();
378
- return new ReferenceLookup (ls ).lookup (ref , ls .schemaJson ());
379
- }
380
365
Schema .Builder <?> rval = sniffSchemaByProps ();
381
366
if (rval != null ) {
382
367
return rval ;
@@ -412,24 +397,14 @@ private Schema.Builder loadSchemaBoolean(Boolean rawBoolean) {
412
397
}
413
398
414
399
private Schema .Builder loadSchemaObject (JsonObject o ) {
415
- Collection <Schema .Builder <?>> extractedSchemas = new ArrayList <>(1 );
416
- List <SchemaExtractor > extractors = asList (new EnumSchemaExtractor (), new CombinedSchemaLoader (this ));
417
- // extractors.stream().map(extractor -> extractor.extract(o)).forEach(extractedSchemas::addAll);
418
-
419
- AdjacentSchemaExtractionState state = new AdjacentSchemaExtractionState (o );
420
- for (SchemaExtractor extractor : extractors ) {
421
- ExtractionResult result = extractor .extract (state .projectedSchemaJson ());
422
- state = state .reduce (result );
423
- }
424
- extractedSchemas = state .extractedSchemaBuilders ();
425
-
400
+ Collection <Schema .Builder <?>> extractedSchemas = runSchemaExtractors (o );
426
401
//////////////////////
427
402
Schema .Builder builder ;
428
403
if (ls .schemaJson ().containsKey ("const" ) && (config .specVersion != DRAFT_4 )) {
429
404
builder = buildConstSchema ();
430
405
} else {
431
406
Supplier <Schema .Builder > supplier = () -> {
432
- if (!ls .schemaJson ().containsKey ("type" ) || ls . schemaJson (). containsKey ( "$ref" ) ) {
407
+ if (!ls .schemaJson ().containsKey ("type" )) {
433
408
return buildSchemaWithoutExplicitType ();
434
409
} else {
435
410
return loadForType (ls .schemaJson ().require ("type" ));
@@ -460,6 +435,26 @@ private Schema.Builder loadSchemaObject(JsonObject o) {
460
435
// return builder;
461
436
}
462
437
438
+ private Collection <Schema .Builder <?>> runSchemaExtractors (JsonObject o ) {
439
+ if (o .containsKey ("$ref" )) {
440
+ return new ReferenceSchemaExtractor ().extract (o ).extractedSchemas ;
441
+ }
442
+ Collection <Schema .Builder <?>> extractedSchemas ;
443
+ List <SchemaExtractor > extractors = asList (
444
+ new EnumSchemaExtractor (),
445
+ new CombinedSchemaLoader (this )
446
+ );
447
+ // extractors.stream().map(extractor -> extractor.extract(o)).forEach(extractedSchemas::addAll);
448
+
449
+ AdjacentSchemaExtractionState state = new AdjacentSchemaExtractionState (o );
450
+ for (SchemaExtractor extractor : extractors ) {
451
+ ExtractionResult result = extractor .extract (state .projectedSchemaJson ());
452
+ state = state .reduce (result );
453
+ }
454
+ extractedSchemas = state .extractedSchemaBuilders ();
455
+ return extractedSchemas ;
456
+ }
457
+
463
458
private void loadCommonSchemaProperties (Schema .Builder builder ) {
464
459
ls .schemaJson ().maybe (config .specVersion .idKeyword ()).map (JsonValue ::requireString ).ifPresent (builder ::id );
465
460
ls .schemaJson ().maybe ("title" ).map (JsonValue ::requireString ).ifPresent (builder ::title );
0 commit comments