zazuko / rdf-validate-shacl

Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.
MIT License
95 stars 12 forks source link

maxErrors = 1 breaks sh:or constraint #88

Open tpluscode opened 2 years ago

tpluscode commented 2 years ago

From what we have in Cube Creator

<ObservationConstraintProperty> a sh:NodeShape;
  sh:property [
    sh:message "needs a schema:name" ;
    sh:or (
      [
        sh:path schema:name ;
        sh:minCount 1 ;
        sh:datatype xsd:string ;
      ]
      [
        sh:path schema:name ;
        sh:minCount 1 ;
        sh:datatype rdf:langString ;
      ]
      [
        sh:path sh:path ;
        sh:in (rdf:type cube:observedBy) ;
      ]
    ) ;
  ]

A property should pass validation if it satisfy any single one of these constraints. Right now, if one sets maxErrors = 1 (or at least a number lower than the "OR'ed" shapes) the validator will fail.

This happens because there is a single counter for the count of error encountered thus far. Each part of the sh:or list increases that counter, so when maxErrors === 1, the first failure will immediately break the validation.

I'm guessing that a false-negative would also be reported if there were violations found before the sh:or constraint. Thus, any dismissible error from one of the constituents will reach the allowed max and prevent remaining alternatives from being checked.