Skip to content

Commit

Permalink
Merge pull request #168 from aml-org/publish-1.7.1
Browse files Browse the repository at this point in the history
Publish 1.7.1
  • Loading branch information
looseale authored Feb 27, 2024
2 parents e52384c + aad8575 commit 8ed9f15
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 37 deletions.
2 changes: 1 addition & 1 deletion internal/validator/contexts/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package contexts
import (
"fmt"
"github.com/aml-org/amf-custom-validator/internal/types"
"github.com/aml-org/amf-custom-validator/internal/validator/config"
"github.com/aml-org/amf-custom-validator/pkg/config"
)

var ApiExtensionUri = "http://a.ml/vocabularies/api-extension#"
Expand Down
4 changes: 2 additions & 2 deletions internal/validator/process_result.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package validator

import (
"github.com/aml-org/amf-custom-validator/internal/validator/config"
c "github.com/aml-org/amf-custom-validator/pkg/config"
e "github.com/aml-org/amf-custom-validator/pkg/events"
"github.com/open-policy-agent/opa/rego"
)

func processResult(result *rego.ResultSet, eventChan *chan e.Event, validationConfig config.ValidationConfiguration, reportConfig config.ReportConfiguration) (string, error) {
func processResult(result *rego.ResultSet, eventChan *chan e.Event, validationConfig c.ValidationConfiguration, reportConfig c.ReportConfiguration) (string, error) {
dispatchEvent(e.NewEvent(e.BuildReportStart), eventChan)
report, err := BuildReport(result, validationConfig, reportConfig)
dispatchEvent(e.NewEvent(e.BuildReportDone), eventChan)
Expand Down
6 changes: 3 additions & 3 deletions internal/validator/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"errors"
"fmt"
"github.com/aml-org/amf-custom-validator/internal/types"
"github.com/aml-org/amf-custom-validator/internal/validator/config"
"github.com/aml-org/amf-custom-validator/internal/validator/contexts"
c "github.com/aml-org/amf-custom-validator/pkg/config"
"github.com/open-policy-agent/opa/rego"
"strconv"
"strings"
)

func BuildReport(resultPtr *rego.ResultSet, validationConfig config.ValidationConfiguration, reportConfig config.ReportConfiguration) (string, error) {
func BuildReport(resultPtr *rego.ResultSet, validationConfig c.ValidationConfiguration, reportConfig c.ReportConfiguration) (string, error) {
result := *resultPtr
if len(result) == 0 {
return "", errors.New("empty result from evaluation")
Expand Down Expand Up @@ -74,7 +74,7 @@ func defineIdRecursively(node *types.ObjectMap, id string) {
}
}

func buildContext(emptyReport bool, reportConfig config.ReportConfiguration) types.ObjectMap {
func buildContext(emptyReport bool, reportConfig c.ReportConfiguration) types.ObjectMap {
if emptyReport {
return contexts.ConformsContext(reportConfig)
} else {
Expand Down
4 changes: 2 additions & 2 deletions internal/validator/report_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package validator

import (
"github.com/aml-org/amf-custom-validator/internal/types"
"github.com/aml-org/amf-custom-validator/internal/validator/config"
c "github.com/aml-org/amf-custom-validator/pkg/config"
"time"
)

Expand All @@ -17,7 +17,7 @@ func DialectInstance(report *types.ObjectMap, context *types.ObjectMap) []types.
return []types.ObjectMap{dialectInstance}
}

func ValidationReportNode(profileName string, results []any, conforms bool, validationConfig config.ValidationConfiguration, reportConfig config.ReportConfiguration) types.ObjectMap {
func ValidationReportNode(profileName string, results []any, conforms bool, validationConfig c.ValidationConfiguration, reportConfig c.ReportConfiguration) types.ObjectMap {
reportTypes := []string{"reportSchema:ReportNode", "shacl:ValidationReport"}
report := types.ObjectMap{
"@id": "validation-report",
Expand Down
4 changes: 2 additions & 2 deletions internal/validator/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"github.com/aml-org/amf-custom-validator/internal/config"
p "github.com/aml-org/amf-custom-validator/internal/parser/profile"
config2 "github.com/aml-org/amf-custom-validator/internal/validator/config"
c "github.com/aml-org/amf-custom-validator/pkg/config"
"github.com/aml-org/amf-custom-validator/pkg/milestones"
"io/ioutil"
"strings"
Expand All @@ -29,7 +29,7 @@ func validate(profile relativePath, data relativePath) string {
p.GenReset()
profileText := read(profile)
dataText := read(data)
report, err := ValidateWithConfiguration(profileText, dataText, config.Debug, nil, config2.TestValidationConfiguration{}, config2.DefaultReportConfiguration())
report, err := ValidateWithConfiguration(profileText, dataText, config.Debug, nil, c.TestValidationConfiguration{}, c.DefaultReportConfiguration())
if err != nil {
panic(err)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/validator/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package validator

import (
"context"
"github.com/aml-org/amf-custom-validator/internal/validator/config"
c "github.com/aml-org/amf-custom-validator/pkg/config"
e "github.com/aml-org/amf-custom-validator/pkg/events"
"github.com/open-policy-agent/opa/rego"
)
Expand All @@ -12,14 +12,14 @@ import (
// directly to `internal.Validate` rather than `pkg.Validate`

func Validate(profileText string, jsonldText string, debug bool, eventChan *chan e.Event) (string, error) {
return ValidateWithConfiguration(profileText, jsonldText, debug, eventChan, config.DefaultValidationConfiguration{}, config.DefaultReportConfiguration())
return ValidateWithConfiguration(profileText, jsonldText, debug, eventChan, c.DefaultValidationConfiguration{}, c.DefaultReportConfiguration())
}

func ValidateCompiled(compiledRegoPtr *rego.PreparedEvalQuery, jsonldText string, debug bool, eventChan *chan e.Event) (string, error) {
return ValidateCompiledWithConfiguration(compiledRegoPtr, jsonldText, debug, eventChan, config.DefaultValidationConfiguration{}, config.DefaultReportConfiguration())
return ValidateCompiledWithConfiguration(compiledRegoPtr, jsonldText, debug, eventChan, c.DefaultValidationConfiguration{}, c.DefaultReportConfiguration())
}

func ValidateWithConfiguration(profileText string, jsonldText string, debug bool, eventChan *chan e.Event, validationConfig config.ValidationConfiguration, reportConfig config.ReportConfiguration) (string, error) {
func ValidateWithConfiguration(profileText string, jsonldText string, debug bool, eventChan *chan e.Event, validationConfig c.ValidationConfiguration, reportConfig c.ReportConfiguration) (string, error) {
// Generate and compile Rego code
compiledRego, err := ProcessProfile(profileText, debug, eventChan)

Expand All @@ -31,7 +31,7 @@ func ValidateWithConfiguration(profileText string, jsonldText string, debug bool
return ValidateCompiledWithConfiguration(compiledRego, jsonldText, debug, eventChan, validationConfig, reportConfig)
}

func ValidateCompiledWithConfiguration(compiledRegoPtr *rego.PreparedEvalQuery, jsonldText string, debug bool, eventChan *chan e.Event, validationConfig config.ValidationConfiguration, reportConfig config.ReportConfiguration) (string, error) {
func ValidateCompiledWithConfiguration(compiledRegoPtr *rego.PreparedEvalQuery, jsonldText string, debug bool, eventChan *chan e.Event, validationConfig c.ValidationConfiguration, reportConfig c.ReportConfiguration) (string, error) {
compiledRego := *compiledRegoPtr

// Normalize input
Expand Down
10 changes: 5 additions & 5 deletions internal/validator/validate_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package validator
import (
"encoding/json"
"github.com/aml-org/amf-custom-validator/internal/config"
config2 "github.com/aml-org/amf-custom-validator/internal/validator/config"
"github.com/aml-org/amf-custom-validator/internal/validator/contexts"
c "github.com/aml-org/amf-custom-validator/pkg/config"
"testing"
)

func TestNoDateCreated(t *testing.T) {
reportConfig := config2.ReportConfiguration{
reportConfig := c.ReportConfiguration{
IncludeReportCreationTime: false,
}

profile := read("../../test/data/integration/profile1/profile.yaml")
data := read("../../test/data/integration/profile1/negative.data.jsonld")

report, err := ValidateWithConfiguration(profile, data, config.Debug, nil, config2.TestValidationConfiguration{}, reportConfig)
report, err := ValidateWithConfiguration(profile, data, config.Debug, nil, c.TestValidationConfiguration{}, reportConfig)

if err != nil {
t.Errorf("Error during validation\n")
Expand All @@ -42,15 +42,15 @@ func TestAlternativeSchemas(t *testing.T) {
reportSchemaIri := "http://a.ml/report"
lexicalSchemaIri := "http://a.ml/lexical"

reportConfig := config2.ReportConfiguration{
reportConfig := c.ReportConfiguration{
ReportSchemaIri: reportSchemaIri,
LexicalSchemaIri: lexicalSchemaIri,
}

profile := read("../../test/data/integration/profile1/profile.yaml")
data := read("../../test/data/integration/profile1/negative.data.jsonld")

report, err := ValidateWithConfiguration(profile, data, config.Debug, nil, config2.TestValidationConfiguration{}, reportConfig)
report, err := ValidateWithConfiguration(profile, data, config.Debug, nil, c.TestValidationConfiguration{}, reportConfig)

if err != nil {
t.Errorf("Error during validation\n")
Expand Down
8 changes: 4 additions & 4 deletions internal/validator/validate_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package validator
import (
"github.com/aml-org/amf-custom-validator/internal/config"
"github.com/aml-org/amf-custom-validator/internal/parser/profile"
config2 "github.com/aml-org/amf-custom-validator/internal/validator/config"
c "github.com/aml-org/amf-custom-validator/pkg/config"
"github.com/aml-org/amf-custom-validator/test"
"strings"
"testing"
Expand All @@ -14,7 +14,7 @@ func TestIntegrationPositiveData(t *testing.T) {
for _, fixture := range test.IntegrationFixtures("../../test/data/integration", &filter) {
prof := fixture.ReadProfile()
profile.GenReset()
report, err := ValidateWithConfiguration(prof, fixture.ReadFixturePositiveData(), config.Debug, nil, config2.TestValidationConfiguration{}, config2.DefaultReportConfiguration())
report, err := ValidateWithConfiguration(prof, fixture.ReadFixturePositiveData(), config.Debug, nil, c.TestValidationConfiguration{}, c.DefaultReportConfiguration())

if err != nil {
t.Errorf("%s > Positive case > Failed with error %v", fixture, err)
Expand All @@ -36,7 +36,7 @@ func TestIntegrationNegativeData(t *testing.T) {
for _, fixture := range test.IntegrationFixtures("../../test/data/integration", &filter) {
prof := fixture.ReadProfile()
profile.GenReset()
report, err := ValidateWithConfiguration(prof, fixture.ReadFixtureNegativeData(), config.Debug, nil, config2.TestValidationConfiguration{}, config2.DefaultReportConfiguration())
report, err := ValidateWithConfiguration(prof, fixture.ReadFixtureNegativeData(), config.Debug, nil, c.TestValidationConfiguration{}, c.DefaultReportConfiguration())
if err != nil {
t.Errorf("%s > Negative case > Failed with error %v", fixture, err)
}
Expand All @@ -60,7 +60,7 @@ func TestIntegrationNegativeDataWithLexical(t *testing.T) {

lexicalFixture, fixtureError := fixture.ReadFixtureNegativeDataWithLexical()
if fixtureError == nil {
report, err := ValidateWithConfiguration(prof, lexicalFixture, config.Debug, nil, config2.TestValidationConfiguration{}, config2.DefaultReportConfiguration())
report, err := ValidateWithConfiguration(prof, lexicalFixture, config.Debug, nil, c.TestValidationConfiguration{}, c.DefaultReportConfiguration())
if err != nil {
t.Errorf("%s > Negative case with lexical > Failed with error %v", fixture, err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/validator/validate_production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"github.com/aml-org/amf-custom-validator/internal/config"
"github.com/aml-org/amf-custom-validator/internal/parser"
config2 "github.com/aml-org/amf-custom-validator/internal/validator/config"
c "github.com/aml-org/amf-custom-validator/pkg/config"
"github.com/aml-org/amf-custom-validator/test"
"strings"
"testing"
Expand All @@ -19,7 +19,7 @@ func TestProduction(t *testing.T) {
for _, example := range fixture.Examples() {
filter := "" // put the number of the text to filter here
if strings.Index(example.File, filter) > -1 {
report, err := ValidateWithConfiguration(profile, example.Text, config.Debug, nil, config2.TestValidationConfiguration{}, config2.DefaultReportConfiguration())
report, err := ValidateWithConfiguration(profile, example.Text, config.Debug, nil, c.TestValidationConfiguration{}, c.DefaultReportConfiguration())
if config.Debug {
generateDebugOutput(profile, example)
}
Expand Down
8 changes: 4 additions & 4 deletions js/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"bytes"
"encoding/json"
"github.com/aml-org/amf-custom-validator/internal/validator"
"github.com/aml-org/amf-custom-validator/internal/validator/config"
c "github.com/aml-org/amf-custom-validator/pkg/config"
"syscall/js"
)

Expand Down Expand Up @@ -39,7 +39,7 @@ func validateWithConfigurationWrapper() js.Func {
return "ValidationConfiguration not yet supported, please set this parameter as 'undefined'. ValidationConfiguration needs to import functions from JS which is not supported by Go 1.19"
}
reportConfig := buildReportConfiguration(args[4])
res, err := validator.ValidateWithConfiguration(profileString, dataString, debug, nil, config.DefaultValidationConfiguration{}, reportConfig)
res, err := validator.ValidateWithConfiguration(profileString, dataString, debug, nil, c.DefaultValidationConfiguration{}, reportConfig)
if err != nil {
return err.Error()
}
Expand All @@ -48,11 +48,11 @@ func validateWithConfigurationWrapper() js.Func {
return jsonFunc
}

func buildReportConfiguration(value js.Value) config.ReportConfiguration {
func buildReportConfiguration(value js.Value) c.ReportConfiguration {
includeReportCreationTime := value.Get("IncludeReportCreationTime").Bool()
reportSchemaIri := value.Get("ReportSchemaIri").String()
lexicalSchemaIri := value.Get("LexicalSchemaIri").String()
return config.ReportConfiguration{
return c.ReportConfiguration{
IncludeReportCreationTime: includeReportCreationTime,
ReportSchemaIri: reportSchemaIri,
LexicalSchemaIri: lexicalSchemaIri,
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 10 additions & 1 deletion pkg/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pkg

import (
internal "github.com/aml-org/amf-custom-validator/internal/validator"
c "github.com/aml-org/amf-custom-validator/pkg/config"
e "github.com/aml-org/amf-custom-validator/pkg/events"
"github.com/open-policy-agent/opa/rego"
)
Expand All @@ -12,4 +13,12 @@ func Validate(profileText string, jsonldText string, debug bool, eventChan *chan

func ValidateCompiled(compiledRegoPtr *rego.PreparedEvalQuery, jsonldText string, debug bool, eventChan *chan e.Event) (string, error) {
return internal.ValidateCompiled(compiledRegoPtr, jsonldText, debug, eventChan)
}
}

func ValidateWithConfiguration(profileText string, jsonldText string, debug bool, eventChan *chan e.Event, validationConfig c.ValidationConfiguration, reportConfig c.ReportConfiguration) (string, error) {
return internal.ValidateWithConfiguration(profileText, jsonldText, debug, eventChan, validationConfig, reportConfig)
}

func ValidateCompiledWithConfiguration(compiledRegoPtr *rego.PreparedEvalQuery, jsonldText string, debug bool, eventChan *chan e.Event, validationConfig c.ValidationConfiguration, reportConfig c.ReportConfiguration) (string, error) {
return internal.ValidateCompiledWithConfiguration(compiledRegoPtr, jsonldText, debug, eventChan, validationConfig, reportConfig)
}
4 changes: 2 additions & 2 deletions wrappers/js-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wrappers/js-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aml-org/amf-custom-validator-web",
"version": "1.7.0",
"version": "1.7.1",
"description": "AMF validator backed by OPA Rego",
"main": "dist/main.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions wrappers/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wrappers/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aml-org/amf-custom-validator",
"version": "1.7.0",
"version": "1.7.1",
"description": "AMF validator backed by OPA Rego",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 8ed9f15

Please sign in to comment.