Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty extends field on node mapping #474

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import amf.core.internal.parser.YNodeLikeOps
import amf.core.internal.parser.domain.SearchScope.All
import amf.core.internal.parser.domain.{Annotations, ScalarNode, SearchScope, ValueNode}
import amf.core.internal.utils.AmfStrings
import amf.core.internal.validation.CoreValidations.SyamlError
import org.yaml.model._

import scala.collection.immutable
@@ -107,6 +108,12 @@ class NodeMappingParser(implicit ctx: DialectContext) extends NodeMappingLikePar
val references: Seq[YNode] = entry.value.tagType match {
case YType.Seq => entry.value.as[YSequence].nodes
case YType.Str => Seq(entry.value)
case tagType =>
ctx.eh.violation(SyamlError,
"",
s"${YType.Seq} or ${YType.Str} expected in 'extends', found [$tagType]",
entry.value.location)
Seq.empty
}
val parsed = references.map { node: YNode =>
val reference = node.toOption[YScalar]
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"@type": "http://www.w3.org/ns/shacl#ValidationReport",
"http://www.w3.org/ns/shacl#conforms": false,
"http://www.w3.org/ns/shacl#result": [
{
"@type": "http://www.w3.org/ns/shacl#ValidationResult",
"http://www.w3.org/ns/shacl#resultSeverity": {
"@id": "http://www.w3.org/ns/shacl#Violation"
},
"http://www.w3.org/ns/shacl#focusNode": {
"@id": "file://amf-aml/shared/src/test/resources/vocabularies2/dialects/empty-extends-on-node-mapping.yaml"
},
"http://www.w3.org/ns/shacl#resultMessage": "Property: 'dialect' mandatory in a dialect node",
"http://www.w3.org/ns/shacl#sourceShape": {
"@id": "http://a.ml/vocabularies/amf/aml#mandatory-property-shape"
},
"http://a.ml/vocabularies/amf/parser#lexicalPosition": {
"@type": "http://a.ml/vocabularies/amf/parser#Position",
"http://a.ml/vocabularies/amf/parser#start": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 3,
"http://a.ml/vocabularies/amf/parser#column": 0
},
"http://a.ml/vocabularies/amf/parser#end": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 11,
"http://a.ml/vocabularies/amf/parser#column": 12
}
}
},
{
"@type": "http://www.w3.org/ns/shacl#ValidationResult",
"http://www.w3.org/ns/shacl#resultSeverity": {
"@id": "http://www.w3.org/ns/shacl#Violation"
},
"http://www.w3.org/ns/shacl#focusNode": {
"@id": "file://amf-aml/shared/src/test/resources/vocabularies2/dialects/empty-extends-on-node-mapping.yaml"
},
"http://www.w3.org/ns/shacl#resultMessage": "Property: 'version' mandatory in a dialect node",
"http://www.w3.org/ns/shacl#sourceShape": {
"@id": "http://a.ml/vocabularies/amf/aml#mandatory-property-shape"
},
"http://a.ml/vocabularies/amf/parser#lexicalPosition": {
"@type": "http://a.ml/vocabularies/amf/parser#Position",
"http://a.ml/vocabularies/amf/parser#start": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 3,
"http://a.ml/vocabularies/amf/parser#column": 0
},
"http://a.ml/vocabularies/amf/parser#end": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 11,
"http://a.ml/vocabularies/amf/parser#column": 12
}
}
},
{
"@type": "http://www.w3.org/ns/shacl#ValidationResult",
"http://www.w3.org/ns/shacl#resultSeverity": {
"@id": "http://www.w3.org/ns/shacl#Violation"
},
"http://www.w3.org/ns/shacl#focusNode": {
"@id": "file://amf-aml/shared/src/test/resources/vocabularies2/dialects/empty-extends-on-node-mapping.yaml#/declarations/otherMapping"
},
"http://www.w3.org/ns/shacl#resultMessage": "Property: 'propertyTerm' not supported in a nodeMapping node",
"http://www.w3.org/ns/shacl#sourceShape": {
"@id": "http://a.ml/vocabularies/amf/aml#closed-shape"
},
"http://a.ml/vocabularies/amf/parser#lexicalPosition": {
"@type": "http://a.ml/vocabularies/amf/parser#Position",
"http://a.ml/vocabularies/amf/parser#start": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 8,
"http://a.ml/vocabularies/amf/parser#column": 0
},
"http://a.ml/vocabularies/amf/parser#end": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 9,
"http://a.ml/vocabularies/amf/parser#column": 0
}
}
},
{
"@type": "http://www.w3.org/ns/shacl#ValidationResult",
"http://www.w3.org/ns/shacl#resultSeverity": {
"@id": "http://www.w3.org/ns/shacl#Violation"
},
"http://www.w3.org/ns/shacl#focusNode": {
"@id": "file://amf-aml/shared/src/test/resources/vocabularies2/dialects/empty-extends-on-node-mapping.yaml#/declarations/myNodeMapping"
},
"http://www.w3.org/ns/shacl#resultMessage": "Property: 'propertyTerm' not supported in a nodeMapping node",
"http://www.w3.org/ns/shacl#sourceShape": {
"@id": "http://a.ml/vocabularies/amf/aml#closed-shape"
},
"http://a.ml/vocabularies/amf/parser#lexicalPosition": {
"@type": "http://a.ml/vocabularies/amf/parser#Position",
"http://a.ml/vocabularies/amf/parser#start": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 10,
"http://a.ml/vocabularies/amf/parser#column": 0
},
"http://a.ml/vocabularies/amf/parser#end": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 11,
"http://a.ml/vocabularies/amf/parser#column": 12
}
}
},
{
"@type": "http://www.w3.org/ns/shacl#ValidationResult",
"http://www.w3.org/ns/shacl#resultSeverity": {
"@id": "http://www.w3.org/ns/shacl#Violation"
},
"http://www.w3.org/ns/shacl#focusNode": {
"@id": ""
},
"http://www.w3.org/ns/shacl#resultMessage": "!!seq or !!str expected in 'extends', found [!!null]",
"http://www.w3.org/ns/shacl#sourceShape": {
"@id": "http://a.ml/vocabularies/amf/core#syaml-error"
},
"http://a.ml/vocabularies/amf/parser#lexicalPosition": {
"@type": "http://a.ml/vocabularies/amf/parser#Position",
"http://a.ml/vocabularies/amf/parser#start": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 11,
"http://a.ml/vocabularies/amf/parser#column": 12
},
"http://a.ml/vocabularies/amf/parser#end": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 11,
"http://a.ml/vocabularies/amf/parser#column": 12
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#%Dialect 1.0

external:
schema-org: http://schema-org.com

nodeMappings:
otherMapping:
propertyTerm: schema-org.other
myNodeMapping:
propertyTerm: schema-org.unreal
extends:
Original file line number Diff line number Diff line change
@@ -130,4 +130,10 @@ class DialectDefinitionValidationTest extends AsyncFunSuite with Matchers with D
test("JSON with-vocabulary should be valid") {
validate("../../../dialects/json/with-vocabulary/dialect.json", None)
}

test("Empty extends property on node mapping reports error") {
validate("../../../dialects/empty-extends-on-node-mapping.yaml",
Some("../../dialects/empty-extends-on-node-mapping.validation.jsonld"),
true)
}
}