Skip to content

Commit

Permalink
Merge pull request #1336 from aml-org/rel-5.0.5-master
Browse files Browse the repository at this point in the history
Release 5.0.5
  • Loading branch information
looseale authored Mar 8, 2022
2 parents 814bdd0 + 33f9eba commit 5741f90
Show file tree
Hide file tree
Showing 1,009 changed files with 11,835 additions and 1,921 deletions.
55 changes: 39 additions & 16 deletions adhoc-cli/src/main/scala/amf/adhoc/cli/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package amf.adhoc.cli
import amf.aml.client.scala.AMLConfiguration
import amf.aml.client.scala.model.document.Dialect
import amf.apicontract.client.scala.APIConfiguration
import amf.core.client.common.remote.Content
import amf.core.client.common.transform.PipelineId
import amf.core.client.scala.AMFResult
import amf.core.client.scala.config.RenderOptions
import amf.core.client.scala.resource.{ClasspathResourceLoader, ResourceLoader}
import amf.core.internal.remote.Mimes
import org.apache.commons.io.IOUtils

import scala.concurrent.Await
import scala.concurrent.{Await, Future}
import scala.concurrent.duration.Duration
import scala.concurrent.ExecutionContext.Implicits.global

Expand All @@ -19,21 +23,7 @@ object Main {
apiParse(args)

case "validate" =>
val configFuture = AMLConfiguration
.predefined()
.withDialect(
"https://raw.githubusercontent.com/aml-org/models/master/src/main/dialects/validation-profile.yaml")
.flatMap(_.withDialect(
"https://raw.githubusercontent.com/aml-org/models/master/src/main/dialects/validation-report.yaml"))

val config = Await.result(configFuture, Duration.Inf)

val client = config.baseUnitClient()

val parsing = Await.result(client.parseDialectInstance(s"file://${args(1)}"), Duration.Inf)
val validation = Await.result(client.validate(parsing.baseUnit), Duration.Inf)

val merged = parsing.merge(validation)
val merged: AMFResult = validateInstance(args(1))
println(merged.toString)
if (merged.conforms) {
System.exit(0)
Expand Down Expand Up @@ -97,4 +87,37 @@ object Main {
.render(baseUnit, Mimes.`application/ld+json`)
}
}

def validateInstance(path: String): AMFResult = {
val configFuture = for {
jarConfig <- Future.successful(
AMLConfiguration.predefined().withResourceLoaders(List(AdaptedClassPathResourceLoader())))
profileDialect <- jarConfig.baseUnitClient().parseDialect("file:///dialects/validation-profile.yaml")
reportDialect <- jarConfig.baseUnitClient().parseDialect("file:///dialects/validation-report.yaml")
} yield {
AMLConfiguration.predefined().withDialect(profileDialect.dialect).withDialect(reportDialect.dialect)
}

val config = Await.result(configFuture, Duration.Inf)

val client = config.baseUnitClient()

val parsing = Await.result(client.parseDialectInstance(s"file://${path}"), Duration.Inf)
val validation = Await.result(client.validate(parsing.dialectInstance), Duration.Inf)

parsing.merge(validation)
}
}

case class AdaptedClassPathResourceLoader() extends ResourceLoader {

override def fetch(resource: String): Future[Content] = {
val strippedPrefix = resource.stripPrefix("file://")
val eventualContent = ClasspathResourceLoader.fetch(strippedPrefix)
eventualContent.map { c =>
c.copy(url = resource)
}
}

override def accepts(resource: String): Boolean = true
}
22 changes: 22 additions & 0 deletions adhoc-cli/src/test/resources/profile/invalid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#%Validation Profile 1.0

#profile: Test2

violation:
- scalar-parameters

validations:
scalar-parameters:
targetClass: apiContract.Request
message: Scalars in parameters must have minLength defined
propertyConstraints:
apiContract.parameter:
minCount: 1
nested:
propertyConstraints:
shapes.schema:
minCount: 1
nested:
propertyConstraints:
shacl.minLength:
minCount: 1
22 changes: 22 additions & 0 deletions adhoc-cli/src/test/resources/profile/valid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#%Validation Profile 1.0

profile: Test2

violation:
- scalar-parameters

validations:
scalar-parameters:
targetClass: apiContract.Request
message: Scalars in parameters must have minLength defined
propertyConstraints:
apiContract.parameter:
minCount: 1
nested:
propertyConstraints:
shapes.schema:
minCount: 1
nested:
propertyConstraints:
shacl.minLength:
minCount: 1
210 changes: 210 additions & 0 deletions adhoc-cli/src/test/resources/report/invalid.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
[
{
"@context": {
"actual": {
"@id": "http://a.ml/vocabularies/validation#actual"
},
"argument": {
"@id": "http://a.ml/vocabularies/validation#argument"
},
"column": {
"@id": "http://a.ml/vocabularies/lexical#column"
},
"component": {
"@id": "http://a.ml/vocabularies/validation#component"
},
"condition": {
"@id": "http://a.ml/vocabularies/validation#condition"
},
"conforms": {
"@id": "http://www.w3.org/ns/shacl#conforms"
},
"doc": "http://a.ml/vocabularies/document#",
"end": {
"@id": "http://a.ml/vocabularies/lexical#end"
},
"expected": {
"@id": "http://a.ml/vocabularies/validation#expected"
},
"focusNode": {
"@id": "http://www.w3.org/ns/shacl#focusNode"
},
"lexical": "http://a.ml/vocabularies/lexical#",
"lexicalSchema": "file:///dialects/lexical.yaml#/declarations/",
"line": {
"@id": "http://a.ml/vocabularies/lexical#line"
},
"location": {
"@id": "http://a.ml/vocabularies/validation#location"
},
"meta": "http://a.ml/vocabularies/meta#",
"negated": {
"@id": "http://a.ml/vocabularies/validation#negated"
},
"range": {
"@id": "http://a.ml/vocabularies/lexical#range"
},
"reportSchema": "file:///dialects/validation-report.yaml#/declarations/",
"result": {
"@id": "http://www.w3.org/ns/shacl#result"
},
"resultMessage": {
"@id": "http://www.w3.org/ns/shacl#resultMessage"
},
"resultPath": {
"@id": "http://www.w3.org/ns/shacl#resultPath"
},
"resultSeverity": {
"@id": "http://www.w3.org/ns/shacl#resultSeverity"
},
"shacl": "http://www.w3.org/ns/shacl#",
"sourceShapeName": {
"@id": "http://a.ml/vocabularies/validation#sourceShapeName"
},
"start": {
"@id": "http://a.ml/vocabularies/lexical#start"
},
"subResult": {
"@id": "http://a.ml/vocabularies/validation#subResult"
},
"trace": {
"@id": "http://a.ml/vocabularies/validation#trace"
},
"traceValue": {
"@id": "http://www.w3.org/ns/shacl#traceValue"
},
"uri": {
"@id": "http://a.ml/vocabularies/lexical#uri"
},
"validation": "http://a.ml/vocabularies/validation#"
},
"@id": "dialect-instance",
"@type": [
"meta:DialectInstance",
"doc:Document",
"doc:Fragment",
"doc:Module",
"doc:Unit"
],
"doc:encodes": [
{
"@id": "validation-report",
"@type": [
"reportSchema:ReportNode",
"shacl:ValidationReport"
],
"profileName": "Test2",
"result": [
{
"@id": "violation_0",
"@type": [
"reportSchema:ValidationResultNode",
"shacl:ValidationResult"
],
"focusNode": "amf://id#5",
"resultMessage": "Scalars in parameters must have minLength defined",
"resultSeverity": "http://www.w3.org/ns/shacl#Violation",
"sourceShapeName": "scalar-parameters",
"trace": [
{
"@id": "violation_0_0",
"@type": [
"reportSchema:TraceMessageNode",
"validation:TraceMessage"
],
"component": "nested",
"resultPath": "http://a.ml/vocabularies/apiContract#parameter",
"traceValue": {
"@id": "violation_0_0_traceValue",
"@type": [
"reportSchema:TraceValueNode",
"validation:TraceValue"
],
"failedNodes": 1,
"negated": false,
"subResult": [
{
"@id": "violation_0_0_traceValue_0",
"@type": [
"reportSchema:ValidationResultNode",
"shacl:ValidationResult"
],
"focusNode": "amf://id#6",
"resultMessage": "error in nested nodes under http://a.ml/vocabularies/apiContract#parameter",
"sourceShapeName": "nested",
"trace": [
{
"@id": "violation_0_0_traceValue_0_0",
"@type": [
"reportSchema:TraceMessageNode",
"validation:TraceMessage"
],
"component": "nested",
"resultPath": "http://a.ml/vocabularies/shapes#schema",
"traceValue": {
"@id": "violation_0_0_traceValue_0_0_traceValue",
"@type": [
"reportSchema:TraceValueNode",
"validation:TraceValue"
],
"failedNodes": 1,
"negated": false,
"subResult": [
{
"@id": "violation_0_0_traceValue_0_0_traceValue_0",
"@type": [
"reportSchema:ValidationResultNode",
"shacl:ValidationResult"
],
"focusNode": "amf://id#7",
"resultMessage": "error in nested nodes under http://a.ml/vocabularies/shapes#schema",
"sourceShapeName": "nested",
"trace": [
{
"@id": "violation_0_0_traceValue_0_0_traceValue_0_0",
"@type": [
"reportSchema:TraceMessageNode",
"validation:TraceMessage"
],
"component": "minCount",
"resultPath": "http://www.w3.org/ns/shacl#minLength",
"traceValue": {
"@id": "violation_0_0_traceValue_0_0_traceValue_0_0_traceValue",
"@type": [
"reportSchema:TraceValueNode",
"validation:TraceValue"
],
"actual": 0,
"condition": ">=",
"expected": 1,
"negated": false
}
}
]
}
],
"successfulNodes": 0
}
}
]
}
],
"successfulNodes": 0
}
}
]
}
]
}
],
"doc:processingData": [
{
"@id": "processing-data",
"@type": [
"doc:DialectInstanceProcessingData"
],
"doc:sourceSpec": "Validation Report 1.0"
}
]
}
]
Loading

0 comments on commit 5741f90

Please sign in to comment.