Skip to content

Commit 9db1678

Browse files
authored
Merge pull request #148 from aml-org/release/1.5.0
W-13925189 Release/1.5.0
2 parents 6ad17de + c48e1d2 commit 9db1678

File tree

343 files changed

+3133
-7688
lines changed

Some content is hidden

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

343 files changed

+3133
-7688
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ RUN go mod tidy
1010
COPY . .
1111
RUN make ci-go
1212

13-
FROM openjdk:8u292-jre AS ci-java
14-
#FROM openjdk/8u292-jdk AS ci-java
13+
FROM eclipse-temurin:17-focal AS ci-java
14+
1515
# Copy content
1616
COPY . ./src
1717
WORKDIR ./src

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ To integrate with AMF, download an AMF CLI JAR with the following script:
142142

143143
## Obtaining semantic data from API specs with AMF
144144

145-
To parse API specification files with the CLI using Java (Java 8 required):
145+
To parse API specification files with the CLI using Java (Java 17 required):
146146

147147
```shell
148148
# Simple parse
@@ -168,4 +168,4 @@ java -jar amf.jar validate PROFILE
168168

169169
# Contributing
170170

171-
For details on how to develop and contribute, please refer to [contributing guide](docs/contributing.md)
171+
For details on how to develop and contribute, please refer to [contributing guide](docs/contributing.md)

docs/contributing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Development requirements
44

55
* Go 1.19
6-
* Java 8 (to validate validation profiles & reports only)
6+
* Java 17 (to validate validation profiles & reports only)
77
* Node 16
88
* Make
99

@@ -24,7 +24,7 @@ make test-js
2424
```
2525

2626
When writing new validation profiles or modifying validation reports you will need to validate both are correct. This
27-
requires Java 8 and an AMF CLI that can be downloaded with `./scripts/download-amf-cli.sh`
27+
requires Java 17 and an AMF CLI that can be downloaded with `./scripts/download-amf-cli.sh`
2828

2929
To find and validate all validation profiles and reports in the project run:
3030

@@ -161,4 +161,4 @@ Test cases extracted from the SHACL TCK
161161

162162
* `test/tck`
163163

164-
Proprietary TCK cases
164+
Proprietary TCK cases

internal/generator/generator.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,21 @@ func IriExpanderFrom(profile profile.Profile) *misc.IriExpander {
3333
// code to execute the profile.
3434
func Generate(profile profile.Profile) RegoUnit {
3535
iriExpander := IriExpanderFrom(profile)
36-
acc := []string{pkg(profile), profileName(profile), preamble(profile)}
36+
acc := []string{pkg(profile), profileName(profile), customRego(profile), preamble(profile)}
37+
3738
for _, r := range ruleSet(profile) {
3839
acc = append(acc, GenerateTopLevelExpression(r, iriExpander))
3940
}
41+
42+
n := 0
43+
for _, val := range acc {
44+
if val != "" {
45+
acc[n] = val
46+
n++
47+
}
48+
}
49+
acc = acc[:n]
50+
4051
return RegoUnit{
4152
Name: packageName(profile),
4253
Entrypoint: entrypoint(profile),
@@ -81,6 +92,16 @@ func entrypoint(profile profile.Profile) string {
8192
return "report"
8293
}
8394

95+
func customRego(profile profile.Profile) string {
96+
acc := make([]string, 0)
97+
if profile.CustomRego != nil {
98+
acc = append(acc, "# Custom rego extensions")
99+
acc = append(acc, *profile.CustomRego)
100+
}
101+
102+
return strings.Join(acc, "\n\n")
103+
}
104+
84105
func preamble(profile profile.Profile) string {
85106
acc := make([]string, 0)
86107
acc = append(acc, preambleRaw)
@@ -100,6 +121,12 @@ func preamble(profile profile.Profile) string {
100121
}
101122

102123
const preambleRaw = `
124+
# Import future keywords
125+
import future.keywords.in
126+
import future.keywords.every
127+
import future.keywords.if
128+
import future.keywords.contains
129+
103130
# Finds a node in the graph, following a link in the flatten JSON-LD node
104131
find = node {
105132
id := data.link["@id"]

internal/parser/parsing_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestParsed(t *testing.T) {
2222
}
2323

2424
if actual != expected {
25-
t.Errorf("%s> Actual did not match expected", fix.Profile)
25+
t.Errorf("%s> Actual did not match expected %s", fix.Profile, fix.Parsed)
2626
}
2727
}
2828
}

internal/parser/profile/parser.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ func Parse(doc *y.Yaml) (Profile, error) {
2020
profile.Description = &description
2121
}
2222

23+
customRego, err := doc.Get("rego_extensions").String()
24+
if err == nil {
25+
profile.CustomRego = &customRego
26+
}
27+
2328
prefixes := doc.Get("prefixes")
2429
if prefixes.IsFound() {
2530
context, err := ParsePrefixes(prefixes)

internal/parser/profile/rule.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type AtomicStatement struct {
4343
type Profile struct {
4444
Name string
4545
Description *string
46+
CustomRego *string
4647
Prefixes ProfileContext
4748
Violation []Rule
4849
Warning []Rule

internal/validator/contexts/contexts.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ var DefaultAMFContext = types.ObjectMap{
1818
"security": "http://a.ml/vocabularies/security#",
1919
"sourcemaps": "http://a.ml/vocabularies/document-source-maps#",
2020
"apiExt": ApiExtensionUri,
21+
"gcl": "http://anypoint.com/vocabs/gcl#",
22+
"management": "http://anypoint.com/vocabs/management#",
23+
"api": "http://anypoint.com/vocabs/api#",
24+
"catalog": "http://anypoint.com/vocabs/digital-repository#",
2125
}
2226

2327
var DefaultValidationContext = types.ObjectMap{
@@ -78,6 +82,9 @@ var DefaultValidationContext = types.ObjectMap{
7882
"conforms": types.StringMap{
7983
"@id": "http://www.w3.org/ns/shacl#conforms",
8084
},
85+
"dateCreated": types.StringMap{
86+
"@id": "http://a.ml/vocabularies/core##dateCreated",
87+
},
8188
"profileName": types.StringMap{
8289
"@id": "http://a.ml/vocabularies/validation#profileName",
8390
},

internal/validator/process_result.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"github.com/open-policy-agent/opa/rego"
66
)
77

8-
func processResult(result *rego.ResultSet, eventChan *chan e.Event) (string, error) {
8+
func processResult(result *rego.ResultSet, eventChan *chan e.Event, configuration ValidationConfiguration) (string, error) {
99
dispatchEvent(e.NewEvent(e.BuildReportStart), eventChan)
10-
report, err := BuildReport(result)
10+
report, err := BuildReport(result, configuration)
1111
dispatchEvent(e.NewEvent(e.BuildReportDone), eventChan)
1212
return report, err
1313
}

internal/validator/report.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313
)
1414

15-
func BuildReport(resultPtr *rego.ResultSet) (string, error) {
15+
func BuildReport(resultPtr *rego.ResultSet, configuration ValidationConfiguration) (string, error) {
1616
result := *resultPtr
1717
if len(result) == 0 {
1818
return "", errors.New("empty result from evaluation")
@@ -26,9 +26,10 @@ func BuildReport(resultPtr *rego.ResultSet) (string, error) {
2626
infos := m["info"].([]any)
2727
results := buildResults(violations, warnings, infos)
2828
conforms := len(violations) == 0
29+
dateCreated := configuration.CurrentTime()
2930

3031
context := buildContext(len(results) == 0)
31-
reportNode := ValidationReportNode(profileName, results, conforms)
32+
reportNode := ValidationReportNode(profileName, results, conforms, dateCreated)
3233
instance := DialectInstance(&reportNode, &context)
3334
return Encode(instance), nil
3435
}

0 commit comments

Comments
 (0)