Skip to content

Commit

Permalink
Add the spec-v0.4 submodule
Browse files Browse the repository at this point in the history
Add the new version of the spec and begin to address the various
issues encountered with mulitple versions.

In this commit, move all the schema definitions across specs
into a single schemas.go in the api package, and adapt the existing
events template to benefit from that.

The same DB of schema files is used by the generator to load all
schemas in the beginning and resolve references through a custom
resolver.

Move the example and factory tests into the spec specific
packages. The conformance tests do not pass yet as a few extra
fields need to be set which is not possible yet because changes to
the context (including links) have not been processed yet.

Signed-off-by: Andrea Frittoli <andrea.frittoli@gmail.com>
  • Loading branch information
afrittoli committed May 23, 2024
1 parent f8b8b91 commit 6deb676
Show file tree
Hide file tree
Showing 112 changed files with 23,632 additions and 877 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = pkg/api/spec-v0.3
url = https://github.com/cdevents/spec
branch = spec-v0.3
[submodule "pkg/api/spec-v0.4"]
path = pkg/api/spec-v0.4
url = https://github.com/cdevents/spec
branch = spec-v0.4
14 changes: 14 additions & 0 deletions pkg/api/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"net/url"
"regexp"

cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/go-playground/validator/v10"
Expand All @@ -30,11 +31,24 @@ import (
"golang.org/x/mod/semver"
)

const SCHEMA_ID_REGEX = `^https://cdevents.dev/([0-9]\.[0-9])\.[0-9]/schema/([^ ]*)$`

var (
// Validation helper as singleton
validate *validator.Validate
CDEventsSchemaIdRegex = regexp.MustCompile(SCHEMA_ID_REGEX)
)

// parts := CDEventsSchemaIdRegex.FindStringSubmatch(url)
// if len(parts) != 3 {
// return nil, fmt.Errorf("cannot parse schema Id %s", url)
// }
// schemaPath := filepath.Join("spec-v" + parts[1], "schemas", parts[2] + ".json")
// schemaFile, err := os.Open(schemaPath)
// if err != nil {
// return nil, fmt.Errorf("failed to load schema %s from %s: %s", url, schemaPath, err)
// }

func init() {
// Register custom validators
validate = validator.New()
Expand Down
Loading

0 comments on commit 6deb676

Please sign in to comment.