2424import com .reprezen .swagedit .core .json .references .JsonReferenceValidator ;
2525import com .reprezen .swagedit .core .model .AbstractNode ;
2626import com .reprezen .swagedit .core .model .ValueNode ;
27+ import com .reprezen .swagedit .core .schema .TypeDefinition ;
2728import com .reprezen .swagedit .core .validation .SwaggerError ;
2829
2930public class OpenApi3ReferenceValidator extends JsonReferenceValidator {
3031
31- private final JsonPointer schemaPointer = JsonPointer .compile ("/definitions/linkOrReference" );
32- private final JsonPointer operationPointer = JsonPointer .compile ("/definitions/operation" );
32+ private final JsonPointer linkTypePointer = JsonPointer .compile ("/definitions/linkOrReference" );
33+ private final JsonPointer operationTypePointer = JsonPointer .compile ("/definitions/operation" );
3334
3435 public OpenApi3ReferenceValidator () {
3536 super (new OpenApi3ReferenceFactory ());
@@ -43,10 +44,9 @@ public OpenApi3ReferenceValidator() {
4344 protected void validateType (JsonDocument doc , URI baseURI , AbstractNode node , JsonReference reference ,
4445 Set <SwaggerError > errors ) {
4546
46- if (schemaPointer .equals (node .getType ().getPointer ())) {
47+ if (linkTypePointer .equals (node .getType ().getPointer ())) {
4748 AbstractNode target = findTarget (doc , baseURI , reference );
48- boolean isValidType = target != null && target .getType () != null
49- && Objects .equals (operationPointer , target .getType ().getPointer ());
49+ boolean isValidType = isValidOperation (target );
5050
5151 if (!isValidType ) {
5252 errors .add (createReferenceError (SEVERITY_WARNING , error_invalid_operation_ref , reference ));
@@ -56,6 +56,12 @@ protected void validateType(JsonDocument doc, URI baseURI, AbstractNode node, Js
5656 }
5757 }
5858
59+ protected boolean isValidOperation (AbstractNode operation ) {
60+ TypeDefinition type = operation != null ? operation .getType () : null ;
61+
62+ return type != null && Objects .equals (operationTypePointer , type .getPointer ());
63+ }
64+
5965 public static class OpenApi3ReferenceFactory extends JsonReferenceFactory {
6066
6167 private static final String OPERATION_REF = "operationRef" ;
0 commit comments