1616
1717package com .networknt .schema .keyword ;
1818
19- import java .util .*;
19+ import java .util .ArrayList ;
20+ import java .util .List ;
2021
2122import com .fasterxml .jackson .databind .JsonNode ;
22- import com .fasterxml .jackson .databind .node .ObjectNode ;
23- import com .networknt .schema .DiscriminatorContext ;
2423import com .networknt .schema .ExecutionContext ;
24+ import com .networknt .schema .JsonType ;
2525import com .networknt .schema .Schema ;
26+ import com .networknt .schema .SchemaContext ;
2627import com .networknt .schema .SchemaException ;
27- import com .networknt .schema .JsonType ;
2828import com .networknt .schema .SchemaLocation ;
2929import com .networknt .schema .TypeFactory ;
3030import com .networknt .schema .path .NodePath ;
31- import com .networknt .schema .SchemaContext ;
3231
3332/**
3433 * {@link KeywordValidator} for allOf.
3534 */
3635public class AllOfValidator extends BaseKeywordValidator {
3736 private final List <Schema > schemas ;
3837
39- public AllOfValidator (SchemaLocation schemaLocation , NodePath evaluationPath , JsonNode schemaNode , Schema parentSchema , SchemaContext schemaContext ) {
38+ public AllOfValidator (SchemaLocation schemaLocation , NodePath evaluationPath , JsonNode schemaNode ,
39+ Schema parentSchema , SchemaContext schemaContext ) {
4040 super (KeywordType .ALL_OF , schemaNode , schemaLocation , parentSchema , schemaContext , evaluationPath );
4141 if (!schemaNode .isArray ()) {
4242 JsonType nodeType = TypeFactory .getValueNodeType (schemaNode , this .schemaContext .getSchemaRegistryConfig ());
43- throw new SchemaException (error ().instanceNode (schemaNode )
44- .instanceLocation (schemaLocation .getFragment ())
45- .messageKey ("type" )
46- .arguments (nodeType .toString (), "array" )
47- .build ());
43+ throw new SchemaException (error ().instanceNode (schemaNode ).instanceLocation (schemaLocation .getFragment ())
44+ .messageKey ("type" ).arguments (nodeType .toString (), "array" ).build ());
4845 }
4946 int size = schemaNode .size ();
5047 this .schemas = new ArrayList <>(size );
@@ -55,50 +52,25 @@ public AllOfValidator(SchemaLocation schemaLocation, NodePath evaluationPath, Js
5552 }
5653
5754 @ Override
58- public void validate (ExecutionContext executionContext , JsonNode node , JsonNode rootNode , NodePath instanceLocation ) {
55+ public void validate (ExecutionContext executionContext , JsonNode node , JsonNode rootNode ,
56+ NodePath instanceLocation ) {
5957 validate (executionContext , node , rootNode , instanceLocation , false );
6058 }
6159
62- protected void validate (ExecutionContext executionContext , JsonNode node , JsonNode rootNode , NodePath instanceLocation , boolean walk ) {
60+ protected void validate (ExecutionContext executionContext , JsonNode node , JsonNode rootNode ,
61+ NodePath instanceLocation , boolean walk ) {
6362 for (Schema schema : this .schemas ) {
6463 if (!walk ) {
6564 schema .validate (executionContext , node , rootNode , instanceLocation );
6665 } else {
6766 schema .walk (executionContext , node , rootNode , instanceLocation , true );
6867 }
69- if (this .schemaContext .isDiscriminatorKeywordEnabled ()) {
70- final Iterator <JsonNode > arrayElements = this .schemaNode .elements ();
71- while (arrayElements .hasNext ()) {
72- final ObjectNode allOfEntry = (ObjectNode ) arrayElements .next ();
73- final JsonNode $ref = allOfEntry .get ("$ref" );
74- if (null != $ref ) {
75- final DiscriminatorContext currentDiscriminatorContext = executionContext
76- .getCurrentDiscriminatorContext ();
77- if (null != currentDiscriminatorContext ) {
78- final ObjectNode discriminator = currentDiscriminatorContext
79- .getDiscriminatorForPath (allOfEntry .get ("$ref" ).asText ());
80- if (null != discriminator ) {
81- DiscriminatorValidator .registerAndMergeDiscriminator (currentDiscriminatorContext , discriminator ,
82- this .parentSchema , instanceLocation );
83- // now we have to check whether we have hit the right target
84- final String discriminatorPropertyName = discriminator .get ("propertyName" ).asText ();
85- final JsonNode discriminatorNode = node .get (discriminatorPropertyName );
86- final String discriminatorPropertyValue = discriminatorNode == null ? null
87- : discriminatorNode .textValue ();
88-
89- final Schema jsonSchema = this .parentSchema ;
90- DiscriminatorValidator .checkDiscriminatorMatch (currentDiscriminatorContext , discriminator ,
91- discriminatorPropertyValue , jsonSchema );
92- }
93- }
94- }
95- }
96- }
9768 }
9869 }
9970
10071 @ Override
101- public void walk (ExecutionContext executionContext , JsonNode node , JsonNode rootNode , NodePath instanceLocation , boolean shouldValidateSchema ) {
72+ public void walk (ExecutionContext executionContext , JsonNode node , JsonNode rootNode , NodePath instanceLocation ,
73+ boolean shouldValidateSchema ) {
10274 if (shouldValidateSchema && node != null ) {
10375 validate (executionContext , node , rootNode , instanceLocation , true );
10476 return ;
@@ -107,7 +79,7 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
10779 // Walk through the schema
10880 schema .walk (executionContext , node , rootNode , instanceLocation , false );
10981 }
110- }
82+ }
11183
11284 @ Override
11385 public void preloadSchema () {
0 commit comments