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

Fix: fixed errorHandling usages in PropertyTermParser and ClassTermParser #473

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
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
Expand Up @@ -8,8 +8,11 @@ import amf.core.client.scala.model.domain.{AmfArray, AmfScalar}
import amf.core.internal.parser.domain.{Annotations, ValueNode}
import org.yaml.model.{YMap, YMapEntry, YScalar, YType}

object ClassTermParser extends SingleOrMultipleItems with IriReferenceParsing {
def parse(entry: YMapEntry, vocabulary: Vocabulary)(implicit ctx: VocabularyContext): ClassTerm = {
case class ClassTermParser()(implicit val ctx: VocabularyContext)
extends SingleOrMultipleItems
with IriReferenceParsing {

def parse(entry: YMapEntry, vocabulary: Vocabulary): ClassTerm = {
val classTerm = ClassTerm(Annotations(entry))
val classTermAlias = entry.key.as[YScalar].text
classTerm.withName(classTermAlias)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import amf.core.client.scala.vocabulary.Namespace
import amf.core.internal.parser.domain.{Annotations, DefaultArrayNode, ValueNode}
import org.yaml.model.{YMap, YMapEntry, YScalar, YType}

object PropertyTermParser extends SingleOrMultipleItems with IriReferenceParsing {
case class PropertyTermParser()(implicit val ctx: VocabularyContext)
extends SingleOrMultipleItems
with IriReferenceParsing {

def parse(entry: YMapEntry, vocabulary: Vocabulary)(implicit ctx: VocabularyContext): PropertyTerm = {
def parse(entry: YMapEntry, vocabulary: Vocabulary): PropertyTerm = {
val propertyTerm = createPropertyTerm(entry)
val propertyTermAlias = entry.key.as[YScalar].text
propertyTerm.withName(propertyTermAlias)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package amf.aml.internal.parse.vocabularies

import amf.core.client.scala.parse.document.SyamlBasedParserErrorHandler
import amf.core.internal.parser.domain.{DefaultArrayNode, ValueNode}
import org.yaml.model.{YMapEntry, YSequence, YType}

trait SingleOrMultipleItems {

implicit val ctx: SyamlBasedParserErrorHandler

protected def singleOrMultipleItemsAsString(entry: YMapEntry) = {
entry.value.tagType match {
case YType.Str => Seq(ValueNode(entry.value).text().toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class VocabulariesParser(root: Root)(implicit override val ctx: VocabularyContex
addDeclarationKey(DeclarationKey(entry))
val classDeclarations = entry.value.as[YMap]
classDeclarations.entries.foreach { classTermDeclaration =>
ClassTermParser.parse(classTermDeclaration, vocabulary)
ClassTermParser().parse(classTermDeclaration, vocabulary)
}
}
)
Expand All @@ -117,7 +117,7 @@ class VocabulariesParser(root: Root)(implicit override val ctx: VocabularyContex
addDeclarationKey(DeclarationKey(entry))
val classDeclarations = entry.value.as[YMap]
classDeclarations.entries.foreach { propertyTermDeclaration =>
PropertyTermParser.parse(propertyTermDeclaration, vocabulary)
PropertyTermParser().parse(propertyTermDeclaration, vocabulary)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"@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": ""
},
"http://www.w3.org/ns/shacl#resultMessage": "Expecting !!str, !!null provided",
"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": 6,
"http://a.ml/vocabularies/amf/parser#column": 16
},
"http://a.ml/vocabularies/amf/parser#end": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 6,
"http://a.ml/vocabularies/amf/parser#column": 16
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#%Vocabulary 1.0
vocabulary: Test Vocab
base: ftp://some-url
classTerms:
t:
description:
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"@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": ""
},
"http://www.w3.org/ns/shacl#resultMessage": "Expecting !!str, !!null provided",
"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": 6,
"http://a.ml/vocabularies/amf/parser#column": 16
},
"http://a.ml/vocabularies/amf/parser#end": {
"@type": "http://a.ml/vocabularies/amf/parser#Location",
"http://a.ml/vocabularies/amf/parser#line": 6,
"http://a.ml/vocabularies/amf/parser#column": 16
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#%Vocabulary 1.0
vocabulary: Test Vocab
base: ftp://some-url
propertyTerms:
prop1:
displayName:
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class VocabularyDefinitionValidationTest
validate("vocabulary.json", None, "../../dialects/json/with-vocabulary")
}

test("Property term parsing with null entries uses errorHandler") {
validate("property-term-with-null-entries.yaml", Some("property-term-with-null-entries.jsonld"), "parser-errors")
}

test("Class term parsing with null entries uses errorHandler") {
validate("class-term-with-null-entries.yaml", Some("class-term-with-null-entries.jsonld"), "parser-errors")
}

protected def validate(vocabulary: String,
goldenReport: Option[String] = None,
path: String): Future[scalatest.Assertion] = {
Expand Down