Skip to content

Commit e52384c

Browse files
authored
Merge pull request #164 from aml-org/publish-1.7.0
W-13925199 Publish 1.7.0
2 parents 97edf7d + dbb803d commit e52384c

File tree

332 files changed

+1178
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

332 files changed

+1178
-365
lines changed

Jenkinsfile

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ pipeline {
114114
anyOf {
115115
branch 'develop'
116116
branch 'master'
117-
branch 'release/*'
118117
}
119118
}
120119
agent {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package config
2+
3+
type ReportConfiguration struct {
4+
IncludeReportCreationTime bool
5+
ReportSchemaIri string
6+
LexicalSchemaIri string
7+
}
8+
9+
func DefaultReportConfiguration() ReportConfiguration {
10+
return ReportConfiguration{
11+
IncludeReportCreationTime: true,
12+
ReportSchemaIri: "file:///dialects/validation-report.yaml",
13+
LexicalSchemaIri: "file:///dialects/lexical.yaml",
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package config
2+
3+
import "time"
4+
5+
type ValidationConfiguration interface {
6+
ReportCreationTime() time.Time
7+
}
8+
9+
type DefaultValidationConfiguration struct{}
10+
11+
func (d DefaultValidationConfiguration) ReportCreationTime() time.Time {
12+
return time.Now()
13+
}
14+
15+
type TestValidationConfiguration struct{}
16+
17+
func (d TestValidationConfiguration) ReportCreationTime() time.Time {
18+
return time.Date(2000, time.November, 28, 0, 0, 0, 0, time.UTC)
19+
}
+109-94
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package contexts
22

3-
import "github.com/aml-org/amf-custom-validator/internal/types"
3+
import (
4+
"fmt"
5+
"github.com/aml-org/amf-custom-validator/internal/types"
6+
"github.com/aml-org/amf-custom-validator/internal/validator/config"
7+
)
48

59
var ApiExtensionUri = "http://a.ml/vocabularies/api-extension#"
610
var DefaultAMFContext = types.ObjectMap{
@@ -24,100 +28,111 @@ var DefaultAMFContext = types.ObjectMap{
2428
"catalog": "http://anypoint.com/vocabs/digital-repository#",
2529
}
2630

27-
var DefaultValidationContext = types.ObjectMap{
28-
"actual": types.StringMap{
29-
"@id": "http://a.ml/vocabularies/validation#actual",
30-
},
31-
"condition": types.StringMap{
32-
"@id": "http://a.ml/vocabularies/validation#condition",
33-
},
34-
"expected": types.StringMap{
35-
"@id": "http://a.ml/vocabularies/validation#expected",
36-
},
37-
"negated": types.StringMap{
38-
"@id": "http://a.ml/vocabularies/validation#negated",
39-
},
40-
"argument": types.StringMap{
41-
"@id": "http://a.ml/vocabularies/validation#argument",
42-
},
43-
"focusNode": types.StringMap{
44-
"@id": "http://www.w3.org/ns/shacl#focusNode",
45-
},
46-
"trace": types.StringMap{
47-
"@id": "http://a.ml/vocabularies/validation#trace",
48-
},
49-
"component": types.StringMap{
50-
"@id": "http://a.ml/vocabularies/validation#component",
51-
},
52-
"resultPath": types.StringMap{
53-
"@id": "http://www.w3.org/ns/shacl#resultPath",
54-
},
55-
"traceValue": types.StringMap{
56-
"@id": "http://www.w3.org/ns/shacl#traceValue",
57-
},
58-
"location": types.StringMap{
59-
"@id": "http://a.ml/vocabularies/validation#location",
60-
},
61-
"uri": types.StringMap{
62-
"@id": "http://a.ml/vocabularies/lexical#uri",
63-
},
64-
"start": types.StringMap{
65-
"@id": "http://a.ml/vocabularies/lexical#start",
66-
},
67-
"end": types.StringMap{
68-
"@id": "http://a.ml/vocabularies/lexical#end",
69-
},
70-
"range": types.StringMap{
71-
"@id": "http://a.ml/vocabularies/lexical#range",
72-
},
73-
"line": types.StringMap{
74-
"@id": "http://a.ml/vocabularies/lexical#line",
75-
},
76-
"column": types.StringMap{
77-
"@id": "http://a.ml/vocabularies/lexical#column",
78-
},
79-
"sourceShapeName": types.StringMap{
80-
"@id": "http://a.ml/vocabularies/validation#sourceShapeName",
81-
},
82-
"conforms": types.StringMap{
83-
"@id": "http://www.w3.org/ns/shacl#conforms",
84-
},
85-
"dateCreated": types.StringMap{
86-
"@id": "http://a.ml/vocabularies/core##dateCreated",
87-
},
88-
"profileName": types.StringMap{
89-
"@id": "http://a.ml/vocabularies/validation#profileName",
90-
},
91-
"result": types.StringMap{
92-
"@id": "http://www.w3.org/ns/shacl#result",
93-
},
94-
"subResult": types.StringMap{
95-
"@id": "http://a.ml/vocabularies/validation#subResult",
96-
},
97-
"resultSeverity": types.StringMap{
98-
"@id": "http://www.w3.org/ns/shacl#resultSeverity",
99-
},
100-
"resultMessage": types.StringMap{
101-
"@id": "http://www.w3.org/ns/shacl#resultMessage",
102-
},
103-
"shacl": "http://www.w3.org/ns/shacl#",
104-
"doc": "http://a.ml/vocabularies/document#",
105-
"meta": "http://a.ml/vocabularies/meta#",
106-
"validation": "http://a.ml/vocabularies/validation#",
107-
"lexical": "http://a.ml/vocabularies/lexical#",
108-
"reportSchema": reportPath,
109-
"lexicalSchema": lexicalPath,
31+
func DefaultValidationContext(reportConfig config.ReportConfiguration) types.ObjectMap {
32+
return types.ObjectMap{
33+
"actual": types.StringMap{
34+
"@id": "http://a.ml/vocabularies/validation#actual",
35+
},
36+
"condition": types.StringMap{
37+
"@id": "http://a.ml/vocabularies/validation#condition",
38+
},
39+
"expected": types.StringMap{
40+
"@id": "http://a.ml/vocabularies/validation#expected",
41+
},
42+
"negated": types.StringMap{
43+
"@id": "http://a.ml/vocabularies/validation#negated",
44+
},
45+
"argument": types.StringMap{
46+
"@id": "http://a.ml/vocabularies/validation#argument",
47+
},
48+
"focusNode": types.StringMap{
49+
"@id": "http://www.w3.org/ns/shacl#focusNode",
50+
},
51+
"trace": types.StringMap{
52+
"@id": "http://a.ml/vocabularies/validation#trace",
53+
},
54+
"component": types.StringMap{
55+
"@id": "http://a.ml/vocabularies/validation#component",
56+
},
57+
"resultPath": types.StringMap{
58+
"@id": "http://www.w3.org/ns/shacl#resultPath",
59+
},
60+
"traceValue": types.StringMap{
61+
"@id": "http://www.w3.org/ns/shacl#traceValue",
62+
},
63+
"location": types.StringMap{
64+
"@id": "http://a.ml/vocabularies/validation#location",
65+
},
66+
"uri": types.StringMap{
67+
"@id": "http://a.ml/vocabularies/lexical#uri",
68+
},
69+
"start": types.StringMap{
70+
"@id": "http://a.ml/vocabularies/lexical#start",
71+
},
72+
"end": types.StringMap{
73+
"@id": "http://a.ml/vocabularies/lexical#end",
74+
},
75+
"range": types.StringMap{
76+
"@id": "http://a.ml/vocabularies/lexical#range",
77+
},
78+
"line": types.StringMap{
79+
"@id": "http://a.ml/vocabularies/lexical#line",
80+
},
81+
"column": types.StringMap{
82+
"@id": "http://a.ml/vocabularies/lexical#column",
83+
},
84+
"sourceShapeName": types.StringMap{
85+
"@id": "http://a.ml/vocabularies/validation#sourceShapeName",
86+
},
87+
"conforms": types.StringMap{
88+
"@id": "http://www.w3.org/ns/shacl#conforms",
89+
},
90+
"dateCreated": types.StringMap{
91+
"@id": "http://a.ml/vocabularies/core#dateCreated",
92+
},
93+
"profileName": types.StringMap{
94+
"@id": "http://a.ml/vocabularies/validation#profileName",
95+
},
96+
"result": types.StringMap{
97+
"@id": "http://www.w3.org/ns/shacl#result",
98+
},
99+
"subResult": types.StringMap{
100+
"@id": "http://a.ml/vocabularies/validation#subResult",
101+
},
102+
"resultSeverity": types.StringMap{
103+
"@id": "http://www.w3.org/ns/shacl#resultSeverity",
104+
},
105+
"resultMessage": types.StringMap{
106+
"@id": "http://www.w3.org/ns/shacl#resultMessage",
107+
},
108+
"shacl": "http://www.w3.org/ns/shacl#",
109+
"doc": "http://a.ml/vocabularies/document#",
110+
"meta": "http://a.ml/vocabularies/meta#",
111+
"validation": "http://a.ml/vocabularies/validation#",
112+
"lexical": "http://a.ml/vocabularies/lexical#",
113+
"reportSchema": DeclarationsFrom(reportConfig.ReportSchemaIri),
114+
"lexicalSchema": DeclarationsFrom(reportConfig.LexicalSchemaIri),
115+
}
110116
}
111117

112-
var reportPath = "file:///dialects/validation-report.yaml#/declarations/"
113-
var lexicalPath = "file:///dialects/lexical.yaml#/declarations/"
118+
func ConformsContext(reportConfig config.ReportConfiguration) types.ObjectMap {
119+
return types.ObjectMap{
120+
"conforms": types.StringMap{
121+
"@id": "http://www.w3.org/ns/shacl#conforms",
122+
},
123+
"shacl": "http://www.w3.org/ns/shacl#",
124+
"doc": "http://a.ml/vocabularies/document#",
125+
"reportSchema": DeclarationsFrom(reportConfig.ReportSchemaIri),
126+
"meta": "http://a.ml/vocabularies/meta#",
127+
"dateCreated": types.StringMap{
128+
"@id": "http://a.ml/vocabularies/core#dateCreated",
129+
},
130+
"profileName": types.StringMap{
131+
"@id": "http://a.ml/vocabularies/validation#profileName",
132+
},
133+
}
134+
}
114135

115-
var ConformsContext = types.ObjectMap{
116-
"conforms": types.StringMap{
117-
"@id": "http://www.w3.org/ns/shacl#conforms",
118-
},
119-
"shacl": "http://www.w3.org/ns/shacl#",
120-
"doc": "http://a.ml/vocabularies/document#",
121-
"reportSchema": reportPath,
122-
"meta": "http://a.ml/vocabularies/meta#",
136+
func DeclarationsFrom(schemaIri string) string {
137+
return fmt.Sprintf("%s#/declarations/", schemaIri)
123138
}

internal/validator/process_result.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package validator
22

33
import (
4+
"github.com/aml-org/amf-custom-validator/internal/validator/config"
45
e "github.com/aml-org/amf-custom-validator/pkg/events"
56
"github.com/open-policy-agent/opa/rego"
67
)
78

8-
func processResult(result *rego.ResultSet, eventChan *chan e.Event, configuration ValidationConfiguration) (string, error) {
9+
func processResult(result *rego.ResultSet, eventChan *chan e.Event, validationConfig config.ValidationConfiguration, reportConfig config.ReportConfiguration) (string, error) {
910
dispatchEvent(e.NewEvent(e.BuildReportStart), eventChan)
10-
report, err := BuildReport(result, configuration)
11+
report, err := BuildReport(result, validationConfig, reportConfig)
1112
dispatchEvent(e.NewEvent(e.BuildReportDone), eventChan)
1213
return report, err
1314
}

internal/validator/report.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import (
66
"errors"
77
"fmt"
88
"github.com/aml-org/amf-custom-validator/internal/types"
9+
"github.com/aml-org/amf-custom-validator/internal/validator/config"
910
"github.com/aml-org/amf-custom-validator/internal/validator/contexts"
1011
"github.com/open-policy-agent/opa/rego"
1112
"strconv"
1213
"strings"
1314
)
1415

15-
func BuildReport(resultPtr *rego.ResultSet, configuration ValidationConfiguration) (string, error) {
16+
func BuildReport(resultPtr *rego.ResultSet, validationConfig config.ValidationConfiguration, reportConfig config.ReportConfiguration) (string, error) {
1617
result := *resultPtr
1718
if len(result) == 0 {
1819
return "", errors.New("empty result from evaluation")
@@ -26,10 +27,9 @@ func BuildReport(resultPtr *rego.ResultSet, configuration ValidationConfiguratio
2627
infos := m["info"].([]any)
2728
results := buildResults(violations, warnings, infos)
2829
conforms := len(violations) == 0
29-
dateCreated := configuration.CurrentTime()
3030

31-
context := buildContext(len(results) == 0)
32-
reportNode := ValidationReportNode(profileName, results, conforms, dateCreated)
31+
context := buildContext(len(results) == 0, reportConfig)
32+
reportNode := ValidationReportNode(profileName, results, conforms, validationConfig, reportConfig)
3333
instance := DialectInstance(&reportNode, &context)
3434
return Encode(instance), nil
3535
}
@@ -74,11 +74,11 @@ func defineIdRecursively(node *types.ObjectMap, id string) {
7474
}
7575
}
7676

77-
func buildContext(emptyReport bool) types.ObjectMap {
77+
func buildContext(emptyReport bool, reportConfig config.ReportConfiguration) types.ObjectMap {
7878
if emptyReport {
79-
return contexts.ConformsContext
79+
return contexts.ConformsContext(reportConfig)
8080
} else {
81-
return contexts.DefaultValidationContext
81+
return contexts.DefaultValidationContext(reportConfig)
8282
}
8383
}
8484

internal/validator/report_nodes.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package validator
22

33
import (
44
"github.com/aml-org/amf-custom-validator/internal/types"
5+
"github.com/aml-org/amf-custom-validator/internal/validator/config"
56
"time"
67
)
78

@@ -16,14 +17,16 @@ func DialectInstance(report *types.ObjectMap, context *types.ObjectMap) []types.
1617
return []types.ObjectMap{dialectInstance}
1718
}
1819

19-
func ValidationReportNode(profileName string, results []any, conforms bool, dateCreated time.Time) types.ObjectMap {
20+
func ValidationReportNode(profileName string, results []any, conforms bool, validationConfig config.ValidationConfiguration, reportConfig config.ReportConfiguration) types.ObjectMap {
2021
reportTypes := []string{"reportSchema:ReportNode", "shacl:ValidationReport"}
2122
report := types.ObjectMap{
2223
"@id": "validation-report",
2324
"@type": reportTypes,
2425
"profileName": profileName,
2526
"conforms": conforms,
26-
"dateCreated": dateCreated.Format(time.RFC3339),
27+
}
28+
if reportConfig.IncludeReportCreationTime {
29+
report["dateCreated"] = validationConfig.ReportCreationTime().Format(time.RFC3339)
2730
}
2831
if len(results) != 0 {
2932
report["result"] = results

internal/validator/test_utils.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/aml-org/amf-custom-validator/internal/config"
66
p "github.com/aml-org/amf-custom-validator/internal/parser/profile"
7+
config2 "github.com/aml-org/amf-custom-validator/internal/validator/config"
78
"github.com/aml-org/amf-custom-validator/pkg/milestones"
89
"io/ioutil"
910
"strings"
@@ -28,7 +29,7 @@ func validate(profile relativePath, data relativePath) string {
2829
p.GenReset()
2930
profileText := read(profile)
3031
dataText := read(data)
31-
report, err := ValidateWithConfiguration(profileText, dataText, config.Debug, nil, TestConfiguration{})
32+
report, err := ValidateWithConfiguration(profileText, dataText, config.Debug, nil, config2.TestValidationConfiguration{}, config2.DefaultReportConfiguration())
3233
if err != nil {
3334
panic(err)
3435
}

0 commit comments

Comments
 (0)