From 9ac1c5642fbe1a0812e2a1a929d7985d500cd0e3 Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Mon, 24 Jun 2024 11:39:22 +0100 Subject: [PATCH] Import spec v0.4 and add support for v0.4 Context (#83) * Add the spec-v0.4 submodule 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 * Support for v04 Context Add a new context type for new fields in the context introduced in v0.4. Create new interfaces to match the new fields as well and update the templates to use the new context and implement the new interfaces when the spec version is not 0.3.x. Add a new version of the test type that is used to test the generator code so that we can test generating for the new version. Updated the logic to generate the schema in a golang file to use it as a local schema database for the jsonschema library to validate documents. The schemas are precompiled at init time now, which simplifies the logic downstream in the code. Signed-off-by: Andrea Frittoli --------- Signed-off-by: Andrea Frittoli --- .github/workflows/ci.yml | 4 +- .github/workflows/coverage.yml | 2 +- .gitmodules | 4 + Makefile | 2 +- README.md | 6 +- go.mod | 11 +- go.sum | 25 +- pkg/api/bindings.go | 46 +- pkg/api/bindings_test.go | 128 +- pkg/api/schemas.go | 11692 ++++++++++++++++ pkg/api/spec-v0.4 | 1 + .../examples/future_event_major_version.json | 0 .../examples/future_event_minor_version.json | 0 .../examples/future_event_patch_version.json | 0 .../examples/implicit_json_custom_data.json | 0 .../examples/json_custom_data.json | 0 .../examples/non_json_custom_data.json | 0 .../examples/non_unmarshable.json | 0 .../examples/past_event_patch_version.json | 0 .../examples/past_spec_patch_version.json | 0 .../examples/unknown_type.json | 0 .../examples/unparsable_context.json | 0 .../examples/unparsable_type.json | 0 .../schemas/foosubjectbarpredicate.json | 0 .../examples/future_event_major_version.json | 62 + .../examples/future_event_minor_version.json | 72 + .../examples/future_event_patch_version.json | 69 + .../examples/implicit_json_custom_data.json | 31 + .../examples/json_custom_data.json | 65 + .../examples/non_json_custom_data.json | 60 + .../tests-v99.1/examples/non_unmarshable.json | 26 + .../examples/past_event_patch_version.json | 65 + .../examples/past_spec_patch_version.json | 65 + .../tests-v99.1/examples/unknown_type.json | 30 + .../examples/unparsable_context.json | 24 + .../tests-v99.1/examples/unparsable_type.json | 26 + .../schemas/foosubjectbarpredicate.json | 155 + pkg/api/types.go | 288 +- pkg/api/types_test.go | 37 +- pkg/api/v03/docs.go | 149 +- .../examples_test.go} | 103 +- pkg/api/{ => v03}/factory_test.go | 2 +- pkg/api/{ => v03}/zz_examples_test.go | 26 +- pkg/api/{ => v03}/zz_factory_test.go | 397 +- pkg/api/v03/zz_shared_test.go | 92 + pkg/api/v04/conformance_test.go | 552 + pkg/api/v04/docs.go | 485 + pkg/api/v04/factory_test.go | 137 + pkg/api/v04/types.go | 184 + pkg/api/v04/zz_examples_test.go | 370 + pkg/api/v04/zz_factory_test.go | 885 ++ pkg/api/v04/zz_shared_test.go | 92 + pkg/api/v990/docs.go | 12 +- pkg/api/v990/types.go | 6 +- pkg/api/v991/docs.go | 55 + pkg/api/v991/types.go | 54 + pkg/api/ztest_schemas.go | 371 + pkg/api/zz_artifactdeleted_0_1_0.go | 204 + pkg/api/zz_artifactdownloaded_0_1_0.go | 204 + pkg/api/zz_artifactpackaged_0_1_1.go | 23 +- pkg/api/zz_artifactpackaged_0_2_0.go | 215 + pkg/api/zz_artifactpublished_0_1_1.go | 23 +- pkg/api/zz_artifactpublished_0_2_0.go | 215 + pkg/api/zz_artifactsigned_0_1_0.go | 23 +- pkg/api/zz_artifactsigned_0_2_0.go | 204 + pkg/api/zz_branchcreated_0_1_2.go | 23 +- pkg/api/zz_branchcreated_0_2_0.go | 204 + pkg/api/zz_branchdeleted_0_1_2.go | 23 +- pkg/api/zz_branchdeleted_0_2_0.go | 204 + pkg/api/zz_buildfinished_0_1_1.go | 23 +- pkg/api/zz_buildfinished_0_2_0.go | 204 + pkg/api/zz_buildqueued_0_1_1.go | 23 +- pkg/api/zz_buildqueued_0_2_0.go | 199 + pkg/api/zz_buildstarted_0_1_1.go | 23 +- pkg/api/zz_buildstarted_0_2_0.go | 199 + pkg/api/zz_changeabandoned_0_1_2.go | 23 +- pkg/api/zz_changeabandoned_0_2_0.go | 204 + pkg/api/zz_changecreated_0_1_2.go | 23 +- pkg/api/zz_changecreated_0_3_0.go | 210 + pkg/api/zz_changemerged_0_1_2.go | 23 +- pkg/api/zz_changemerged_0_2_0.go | 204 + pkg/api/zz_changereviewed_0_1_2.go | 23 +- pkg/api/zz_changereviewed_0_2_0.go | 204 + pkg/api/zz_changeupdated_0_1_2.go | 23 +- pkg/api/zz_changeupdated_0_2_0.go | 204 + pkg/api/zz_environmentcreated_0_1_1.go | 23 +- pkg/api/zz_environmentcreated_0_2_0.go | 210 + pkg/api/zz_environmentdeleted_0_1_1.go | 23 +- pkg/api/zz_environmentdeleted_0_2_0.go | 204 + pkg/api/zz_environmentmodified_0_1_1.go | 23 +- pkg/api/zz_environmentmodified_0_2_0.go | 210 + pkg/api/zz_incidentdetected_0_1_0.go | 23 +- pkg/api/zz_incidentdetected_0_2_0.go | 222 + pkg/api/zz_incidentreported_0_1_0.go | 23 +- pkg/api/zz_incidentreported_0_2_0.go | 228 + pkg/api/zz_incidentresolved_0_1_0.go | 23 +- pkg/api/zz_incidentresolved_0_2_0.go | 222 + pkg/api/zz_pipelinerunfinished_0_1_1.go | 23 +- pkg/api/zz_pipelinerunfinished_0_2_0.go | 222 + pkg/api/zz_pipelinerunqueued_0_1_1.go | 23 +- pkg/api/zz_pipelinerunqueued_0_2_0.go | 210 + pkg/api/zz_pipelinerunstarted_0_1_1.go | 23 +- pkg/api/zz_pipelinerunstarted_0_2_0.go | 210 + pkg/api/zz_repositorycreated_0_1_1.go | 23 +- pkg/api/zz_repositorycreated_0_2_0.go | 222 + pkg/api/zz_repositorydeleted_0_1_1.go | 23 +- pkg/api/zz_repositorydeleted_0_2_0.go | 222 + pkg/api/zz_repositorymodified_0_1_1.go | 23 +- pkg/api/zz_repositorymodified_0_2_0.go | 222 + pkg/api/zz_servicedeployed_0_1_1.go | 23 +- pkg/api/zz_servicedeployed_0_2_0.go | 210 + pkg/api/zz_servicepublished_0_1_1.go | 23 +- pkg/api/zz_servicepublished_0_2_0.go | 204 + pkg/api/zz_serviceremoved_0_1_1.go | 23 +- pkg/api/zz_serviceremoved_0_2_0.go | 204 + pkg/api/zz_servicerolledback_0_1_1.go | 23 +- pkg/api/zz_servicerolledback_0_2_0.go | 210 + pkg/api/zz_serviceupgraded_0_1_1.go | 23 +- pkg/api/zz_serviceupgraded_0_2_0.go | 210 + pkg/api/zz_taskrunfinished_0_1_1.go | 23 +- pkg/api/zz_taskrunfinished_0_2_0.go | 228 + pkg/api/zz_taskrunstarted_0_1_1.go | 23 +- pkg/api/zz_taskrunstarted_0_2_0.go | 216 + pkg/api/zz_testcaserunfinished_0_1_0.go | 31 +- pkg/api/zz_testcaserunfinished_0_2_0.go | 247 + pkg/api/zz_testcaserunqueued_0_1_0.go | 39 +- pkg/api/zz_testcaserunqueued_0_2_0.go | 242 + pkg/api/zz_testcaserunskipped_0_1_0.go | 235 + pkg/api/zz_testcaserunstarted_0_1_0.go | 39 +- pkg/api/zz_testcaserunstarted_0_2_0.go | 242 + pkg/api/zz_testoutputpublished_0_1_0.go | 23 +- pkg/api/zz_testoutputpublished_0_2_0.go | 222 + pkg/api/zz_testsuiterunfinished_0_1_0.go | 31 +- pkg/api/zz_testsuiterunfinished_0_2_0.go | 239 + pkg/api/zz_testsuiterunqueued_0_1_0.go | 39 +- pkg/api/zz_testsuiterunqueued_0_2_0.go | 234 + pkg/api/zz_testsuiterunstarted_0_1_0.go | 39 +- pkg/api/zz_testsuiterunstarted_0_2_0.go | 234 + pkg/api/zz_ticketclosed_0_1_0.go | 264 + pkg/api/zz_ticketcreated_0_1_0.go | 252 + pkg/api/zz_ticketupdated_0_1_0.go | 258 + .../zz_ztest_foosubjectbarpredicate_1_2_3.go | 69 +- .../zz_ztest_foosubjectbarpredicate_2_2_3.go | 231 + tools/generator.go | 316 +- tools/generator_test.go | 161 +- tools/templates/docs.go.tmpl | 17 +- tools/templates/event.go.tmpl | 74 +- tools/templates/examples_test.go.tmpl | 30 +- tools/templates/factory_test.go.tmpl | 27 +- tools/templates/schemas.go.tmpl | 100 + tools/templates/shared_test.go.tmpl | 95 + tools/templates/types.go.tmpl | 6 +- 152 files changed, 27965 insertions(+), 939 deletions(-) create mode 100644 pkg/api/schemas.go create mode 160000 pkg/api/spec-v0.4 rename pkg/api/{tests => tests-v99.0}/examples/future_event_major_version.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/future_event_minor_version.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/future_event_patch_version.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/implicit_json_custom_data.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/json_custom_data.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/non_json_custom_data.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/non_unmarshable.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/past_event_patch_version.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/past_spec_patch_version.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/unknown_type.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/unparsable_context.json (100%) rename pkg/api/{tests => tests-v99.0}/examples/unparsable_type.json (100%) rename pkg/api/{tests => tests-v99.0}/schemas/foosubjectbarpredicate.json (100%) create mode 100644 pkg/api/tests-v99.1/examples/future_event_major_version.json create mode 100644 pkg/api/tests-v99.1/examples/future_event_minor_version.json create mode 100644 pkg/api/tests-v99.1/examples/future_event_patch_version.json create mode 100644 pkg/api/tests-v99.1/examples/implicit_json_custom_data.json create mode 100644 pkg/api/tests-v99.1/examples/json_custom_data.json create mode 100644 pkg/api/tests-v99.1/examples/non_json_custom_data.json create mode 100644 pkg/api/tests-v99.1/examples/non_unmarshable.json create mode 100644 pkg/api/tests-v99.1/examples/past_event_patch_version.json create mode 100644 pkg/api/tests-v99.1/examples/past_spec_patch_version.json create mode 100644 pkg/api/tests-v99.1/examples/unknown_type.json create mode 100644 pkg/api/tests-v99.1/examples/unparsable_context.json create mode 100644 pkg/api/tests-v99.1/examples/unparsable_type.json create mode 100644 pkg/api/tests-v99.1/schemas/foosubjectbarpredicate.json rename pkg/api/{examples_v0.3_test.go => v03/examples_test.go} (75%) rename pkg/api/{ => v03}/factory_test.go (99%) rename pkg/api/{ => v03}/zz_examples_test.go (95%) rename pkg/api/{ => v03}/zz_factory_test.go (51%) create mode 100644 pkg/api/v03/zz_shared_test.go create mode 100644 pkg/api/v04/conformance_test.go create mode 100644 pkg/api/v04/docs.go create mode 100644 pkg/api/v04/factory_test.go create mode 100644 pkg/api/v04/types.go create mode 100644 pkg/api/v04/zz_examples_test.go create mode 100644 pkg/api/v04/zz_factory_test.go create mode 100644 pkg/api/v04/zz_shared_test.go create mode 100644 pkg/api/v991/docs.go create mode 100644 pkg/api/v991/types.go create mode 100644 pkg/api/ztest_schemas.go create mode 100644 pkg/api/zz_artifactdeleted_0_1_0.go create mode 100644 pkg/api/zz_artifactdownloaded_0_1_0.go create mode 100644 pkg/api/zz_artifactpackaged_0_2_0.go create mode 100644 pkg/api/zz_artifactpublished_0_2_0.go create mode 100644 pkg/api/zz_artifactsigned_0_2_0.go create mode 100644 pkg/api/zz_branchcreated_0_2_0.go create mode 100644 pkg/api/zz_branchdeleted_0_2_0.go create mode 100644 pkg/api/zz_buildfinished_0_2_0.go create mode 100644 pkg/api/zz_buildqueued_0_2_0.go create mode 100644 pkg/api/zz_buildstarted_0_2_0.go create mode 100644 pkg/api/zz_changeabandoned_0_2_0.go create mode 100644 pkg/api/zz_changecreated_0_3_0.go create mode 100644 pkg/api/zz_changemerged_0_2_0.go create mode 100644 pkg/api/zz_changereviewed_0_2_0.go create mode 100644 pkg/api/zz_changeupdated_0_2_0.go create mode 100644 pkg/api/zz_environmentcreated_0_2_0.go create mode 100644 pkg/api/zz_environmentdeleted_0_2_0.go create mode 100644 pkg/api/zz_environmentmodified_0_2_0.go create mode 100644 pkg/api/zz_incidentdetected_0_2_0.go create mode 100644 pkg/api/zz_incidentreported_0_2_0.go create mode 100644 pkg/api/zz_incidentresolved_0_2_0.go create mode 100644 pkg/api/zz_pipelinerunfinished_0_2_0.go create mode 100644 pkg/api/zz_pipelinerunqueued_0_2_0.go create mode 100644 pkg/api/zz_pipelinerunstarted_0_2_0.go create mode 100644 pkg/api/zz_repositorycreated_0_2_0.go create mode 100644 pkg/api/zz_repositorydeleted_0_2_0.go create mode 100644 pkg/api/zz_repositorymodified_0_2_0.go create mode 100644 pkg/api/zz_servicedeployed_0_2_0.go create mode 100644 pkg/api/zz_servicepublished_0_2_0.go create mode 100644 pkg/api/zz_serviceremoved_0_2_0.go create mode 100644 pkg/api/zz_servicerolledback_0_2_0.go create mode 100644 pkg/api/zz_serviceupgraded_0_2_0.go create mode 100644 pkg/api/zz_taskrunfinished_0_2_0.go create mode 100644 pkg/api/zz_taskrunstarted_0_2_0.go create mode 100644 pkg/api/zz_testcaserunfinished_0_2_0.go create mode 100644 pkg/api/zz_testcaserunqueued_0_2_0.go create mode 100644 pkg/api/zz_testcaserunskipped_0_1_0.go create mode 100644 pkg/api/zz_testcaserunstarted_0_2_0.go create mode 100644 pkg/api/zz_testoutputpublished_0_2_0.go create mode 100644 pkg/api/zz_testsuiterunfinished_0_2_0.go create mode 100644 pkg/api/zz_testsuiterunqueued_0_2_0.go create mode 100644 pkg/api/zz_testsuiterunstarted_0_2_0.go create mode 100644 pkg/api/zz_ticketclosed_0_1_0.go create mode 100644 pkg/api/zz_ticketcreated_0_1_0.go create mode 100644 pkg/api/zz_ticketupdated_0_1_0.go create mode 100644 pkg/api/zz_ztest_foosubjectbarpredicate_2_2_3.go create mode 100644 tools/templates/schemas.go.tmpl create mode 100644 tools/templates/shared_test.go.tmpl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5318ae..ec633e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,13 +23,13 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.19 + go-version: 1.21 - name: Format check run: make fmt - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.52 + version: v1.59.1 args: --build-tags testonly - name: Check generated code run: make generate diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4d5ea3a..93e2c87 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -26,7 +26,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: 1.19 + go-version: 1.21 - name: Generate coverage report run: make test - name: Upload coverage reports to Codecov diff --git a/.gitmodules b/.gitmodules index 40ad4aa..04b9668 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/Makefile b/Makefile index 9fc5d83..ffe4064 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ importfmt: get-fmt-deps goimports -w $(GO_DEPENDENCIES) get-fmt-deps: ## Install test dependencies - $(GO_NOMOD) get golang.org/x/tools/cmd/goimports + $(GO) install golang.org/x/tools/cmd/goimports .PHONY: lint lint: ## Lint the code diff --git a/README.md b/README.md index b08eb2b..b3f953b 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ go get github.com/cdevents/sdk-go ``` And import the module in your code corresponding to the desired version of the specification. -For CDEvents v0.3.x, use: +For CDEvents v0.4.x, use: ```golang -import cdevents "github.com/cdevents/sdk-go/pkg/api/v03" +import cdeventsv04 "github.com/cdevents/sdk-go/pkg/api/v04" ``` ## Create your first CDEvent @@ -27,7 +27,7 @@ To create a CDEvent, for instance a [*pipelineRun queued*](https://cdevents.dev/ func main() { // Create the base event - event, err := cdevents.NewPipelineRunQueuedEvent() + event, err := cdeventsv04.NewPipelineRunQueuedEvent() if err != nil { log.Fatalf("could not create a cdevent, %v", err) } diff --git a/go.mod b/go.mod index b7c16db..7ecadbd 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module github.com/cdevents/sdk-go -go 1.18 +go 1.21 require ( github.com/cloudevents/sdk-go/v2 v2.15.2 - github.com/google/go-cmp v0.5.8 + github.com/google/go-cmp v0.6.0 github.com/google/uuid v1.1.2 github.com/package-url/packageurl-go v0.1.1 - github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 + github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 golang.org/x/text v0.14.0 ) @@ -16,7 +16,8 @@ require ( github.com/go-playground/universal-translator v0.18.0 // indirect github.com/leodido/go-urn v1.2.1 // indirect golang.org/x/crypto v0.17.0 // indirect - golang.org/x/sys v0.15.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/tools v0.22.0 // indirect ) require ( @@ -27,6 +28,6 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.17.0 // indirect - golang.org/x/mod v0.9.0 + golang.org/x/mod v0.18.0 gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 7fdc981..48f2634 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= +github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= @@ -12,8 +14,8 @@ github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/j github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -37,18 +39,21 @@ github.com/package-url/packageurl-go v0.1.1/go.mod h1:uQd4a7Rh3ZsVg5j0lNyAfyxIeG github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 h1:TToq11gyfNlrMFZiYujSekIsPd9AmsA2Bj/iv+s4JHE= -github.com/santhosh-tekuri/jsonschema/v5 v5.0.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= @@ -58,22 +63,25 @@ go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= -golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= -golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= +golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs= +golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= +golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= @@ -84,3 +92,4 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/api/bindings.go b/pkg/api/bindings.go index 44aa692..f56c743 100644 --- a/pkg/api/bindings.go +++ b/pkg/api/bindings.go @@ -22,28 +22,32 @@ import ( "encoding/json" "fmt" "net/url" + "regexp" cloudevents "github.com/cloudevents/sdk-go/v2" "github.com/go-playground/validator/v10" purl "github.com/package-url/packageurl-go" - jsonschema "github.com/santhosh-tekuri/jsonschema/v5" "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 + validate *validator.Validate + CDEventsSchemaIdRegex = regexp.MustCompile(SCHEMA_ID_REGEX) ) func init() { // Register custom validators validate = validator.New() - err := validate.RegisterValidation("event-type", ValidateEventType) - panicOnError(err) - err = validate.RegisterValidation("uri-reference", ValidateUriReference) + validate.RegisterStructValidation(ValidateEventType, CDEventType{}) + err := validate.RegisterValidation("uri-reference", ValidateUriReference) panicOnError(err) err = validate.RegisterValidation("purl", ValidatePurl) panicOnError(err) + err = validate.RegisterValidation("event-link-type", ValidateLinkType) + panicOnError(err) } func panicOnError(err error) { @@ -70,9 +74,11 @@ func ParseType(eventType string) (*CDEventType, error) { return t, nil } -func ValidateEventType(fl validator.FieldLevel) bool { - _, err := ParseType(fl.Field().String()) - return err == nil +func ValidateEventType(sl validator.StructLevel) { + _, err := ParseType(sl.Current().Interface().(CDEventType).String()) + if err != nil { + sl.ReportError(sl.Current().Interface(), "Type", "", "", "") + } } func ValidateUriReference(fl validator.FieldLevel) bool { @@ -85,6 +91,12 @@ func ValidatePurl(fl validator.FieldLevel) bool { return err == nil } +func ValidateLinkType(fl validator.FieldLevel) bool { + lt := LinkType(fl.Field().String()) + _, ok := LinkTypes[lt] + return ok +} + // AsCloudEvent renders a CDEvent as a CloudEvent func AsCloudEvent(event CDEventReader) (*cloudevents.Event, error) { if event == nil { @@ -127,10 +139,9 @@ func AsJsonString(event CDEventReader) (string, error) { // Validate checks the CDEvent against the JSON schema and validate constraints func Validate(event CDEventReader) error { - url, schema := event.GetSchema() - sch, err := jsonschema.CompileString(url, schema) + _, sch, err := event.GetSchema() if err != nil { - return fmt.Errorf("cannot compile jsonschema %s, %s", url, err) + return err } var v interface{} jsonString, err := AsJsonString(event) @@ -157,19 +168,20 @@ func Validate(event CDEventReader) error { // This works by unmarshalling the context first, extracting the event type and using // that to unmarshal the rest of the event into the correct object. // `ContextType` defines the type of Context that can be used to unmarshal the event. -func NewFromJsonBytesContext[ContextType BaseContextReader](event []byte, cdeventsMap map[string]CDEvent) (CDEvent, error) { +func NewFromJsonBytesContext[CDEventType CDEvent](event []byte, cdeventsMap map[string]CDEventType) (CDEventType, error) { eventAux := &struct { - Context ContextType `json:"context"` + Context Context `json:"context"` }{} + var nilReturn CDEventType err := json.Unmarshal(event, eventAux) if err != nil { - return nil, err + return nilReturn, err } eventType := eventAux.Context.GetType() receiver, ok := cdeventsMap[eventType.UnversionedString()] if !ok { // This should not happen as unmarshalling and validate checks if the type is known to the SDK - return nil, fmt.Errorf("unknown event type %s", eventAux.Context.GetType()) + return nilReturn, fmt.Errorf("unknown event type %s", eventAux.Context.GetType()) } // Check if the receiver is compatible. It must have the same subject and predicate // and share the same major version. @@ -177,11 +189,11 @@ func NewFromJsonBytesContext[ContextType BaseContextReader](event []byte, cdeven // greater than the SDK one, some fields may be lost, as newer versions may add new // fields to the event specification. if !eventType.IsCompatible(receiver.GetType()) { - return nil, fmt.Errorf("sdk event version %s not compatible with %s", receiver.GetType().Version, eventType.Version) + return nilReturn, fmt.Errorf("sdk event version %s not compatible with %s", receiver.GetType().Version, eventType.Version) } err = json.Unmarshal(event, receiver) if err != nil { - return nil, err + return nilReturn, err } return receiver, nil } diff --git a/pkg/api/bindings_test.go b/pkg/api/bindings_test.go index aeccd52..3ae6e11 100644 --- a/pkg/api/bindings_test.go +++ b/pkg/api/bindings_test.go @@ -24,14 +24,13 @@ import ( "testing" "github.com/cdevents/sdk-go/pkg/api" - testapi "github.com/cdevents/sdk-go/pkg/api/v990" + testapi "github.com/cdevents/sdk-go/pkg/api/v991" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - jsonschema "github.com/santhosh-tekuri/jsonschema/v5" ) -const testsFolder = "tests/examples" +const testsFolder = "tests-v99.1/examples" type testData struct { TestValues []map[string]string `json:"testValues"` @@ -50,6 +49,12 @@ var ( testDataXml = []byte("testData") testChangeId = "myChange123" + // V04+ Examples Data + testLinks api.EmbeddedLinksArray + testContextId = "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + testChainId = "4c8cb7dd-3448-41de-8768-eec704e2829b" + testSchemaUri = "https://myorg.com/schema/custom" + eventJsonCustomData *testapi.FooSubjectBarPredicateEvent eventNonJsonCustomData *testapi.FooSubjectBarPredicateEvent eventJsonCustomDataUnmarshalled *testapi.FooSubjectBarPredicateEvent @@ -57,6 +62,21 @@ var ( eventJsonCustomDataFile = "json_custom_data" eventImplicitJsonCustomDataFile = "implicit_json_custom_data" eventNonJsonCustomDataFile = "non_json_custom_data" + + eventInvalidType = &testapi.FooSubjectBarPredicateEvent{ + Context: api.ContextV04{ + api.Context{ + Type: api.CDEventType{ + Subject: "invalid", + Predicate: "invalid", + Version: "1.2.3", + }, + Version: "9.9.9", + }, + api.ContextLinks{}, + api.ContextCustom{}, + }, + } ) func panicOnError(err error) { @@ -70,31 +90,66 @@ func setContext(event api.CDEventWriter, subjectId string) { event.SetSubjectId(subjectId) } +func setContextV04(event api.CDEventWriterV04, chainId, schemaUri bool) { + if chainId { + event.SetChainId(testChainId) + } + if schemaUri { + event.SetSchemaUri(testSchemaUri) + } + event.SetLinks(testLinks) +} + func init() { + // Set up test links + tags := api.Tags{ + "foo1": "bar", + "foo2": "bar", + } + reference := api.EventReference{ + ContextId: testContextId, + } + elr := api.NewEmbeddedLinkRelation() + elr.SetTags(tags) + elr.SetLinkKind("TRIGGER") + elr.SetTarget(reference) + elp := api.NewEmbeddedLinkPath() + elp.SetTags(tags) + elp.SetFrom(reference) + ele := api.NewEmbeddedLinkEnd() + ele.SetTags(tags) + ele.SetFrom(reference) + testLinks = api.EmbeddedLinksArray{ + elr, elp, ele, + } + eventJsonCustomData, _ = testapi.NewFooSubjectBarPredicateEvent() setContext(eventJsonCustomData, testSubjectId) + setContextV04(eventJsonCustomData, true, true) eventJsonCustomData.SetSubjectReferenceField(&api.Reference{Id: testChangeId}) eventJsonCustomData.SetSubjectPlainField(testValue) eventJsonCustomData.SetSubjectArtifactId(testArtifactId) - eventJsonCustomData.SetSubjectObjectField(&api.FooSubjectBarPredicateSubjectContentObjectField{Required: testChangeId, Optional: testSource}) + eventJsonCustomData.SetSubjectObjectField(&testapi.FooSubjectBarPredicateSubjectContentObjectField{Required: testChangeId, Optional: testSource}) err := eventJsonCustomData.SetCustomData("application/json", testDataJson) panicOnError(err) eventJsonCustomDataUnmarshalled, _ = testapi.NewFooSubjectBarPredicateEvent() setContext(eventJsonCustomDataUnmarshalled, testSubjectId) + setContextV04(eventJsonCustomDataUnmarshalled, true, true) eventJsonCustomDataUnmarshalled.SetSubjectReferenceField(&api.Reference{Id: testChangeId}) eventJsonCustomDataUnmarshalled.SetSubjectPlainField(testValue) eventJsonCustomDataUnmarshalled.SetSubjectArtifactId(testArtifactId) - eventJsonCustomDataUnmarshalled.SetSubjectObjectField(&api.FooSubjectBarPredicateSubjectContentObjectField{Required: testChangeId, Optional: testSource}) + eventJsonCustomDataUnmarshalled.SetSubjectObjectField(&testapi.FooSubjectBarPredicateSubjectContentObjectField{Required: testChangeId, Optional: testSource}) err = eventJsonCustomDataUnmarshalled.SetCustomData("application/json", testDataJsonUnmarshalled) panicOnError(err) eventNonJsonCustomData, _ = testapi.NewFooSubjectBarPredicateEvent() setContext(eventNonJsonCustomData, testSubjectId) + setContextV04(eventNonJsonCustomData, true, true) eventNonJsonCustomData.SetSubjectReferenceField(&api.Reference{Id: testChangeId}) eventNonJsonCustomData.SetSubjectPlainField(testValue) eventNonJsonCustomData.SetSubjectArtifactId(testArtifactId) - eventNonJsonCustomData.SetSubjectObjectField(&api.FooSubjectBarPredicateSubjectContentObjectField{Required: testChangeId, Optional: testSource}) + eventNonJsonCustomData.SetSubjectObjectField(&testapi.FooSubjectBarPredicateSubjectContentObjectField{Required: testChangeId, Optional: testSource}) err = eventNonJsonCustomData.SetCustomData("application/xml", testDataXml) panicOnError(err) } @@ -172,9 +227,24 @@ func TestAsCloudEvent(t *testing.T) { } func TestAsCloudEventInvalid(t *testing.T) { - _, err := api.AsCloudEvent(nil) - if err == nil { - t.Fatalf("expected it to fail, but it didn't") + + tests := []struct { + name string + event api.CDEventReader + }{{ + name: "nil event", + event: nil, + }, { + name: "event with invalid type", + event: eventInvalidType, + }} + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + _, err := api.AsCloudEvent(tc.event) + if err == nil { + t.Fatalf("expected it to fail, but it didn't") + } + }) } } @@ -206,10 +276,9 @@ func TestAsJsonBytes(t *testing.T) { t.Fatalf("didn't expected it to fail, but it did: %v", err) } // First validate that the test JSON compiles against the schema - schema, url := tc.event.GetSchema() - sch, err := jsonschema.CompileString(schema, url) + url, sch, err := tc.event.GetSchema() if err != nil { - t.Fatalf("Cannot compile jsonschema %s: %v", url, err) + t.Fatalf("Cannot find jsonschema %s: %v", url, err) } var v interface{} if err := json.Unmarshal(eventBytes, &v); err != nil { @@ -274,11 +343,13 @@ func TestInvalidEvent(t *testing.T) { // invalid event type eventInvalidType := &testapi.FooSubjectBarPredicateEvent{ - Context: api.Context{ - Type: api.CDEventType{Subject: "not-a-valid-type"}, - Version: api.CDEventsSpecVersion, + Context: api.ContextV04{ + Context: api.Context{ + Type: api.CDEventType{Subject: "not-a-valid-type"}, + Version: api.CDEventsSpecVersion, + }, }, - Subject: api.FooSubjectBarPredicateSubject{ + Subject: testapi.FooSubjectBarPredicateSubject{ SubjectBase: api.SubjectBase{ Type: "notAValidSubjectType", }, @@ -338,7 +409,7 @@ func TestNewFromJsonString(t *testing.T) { tests := []struct { name string - event api.CDEvent + event api.CDEventV04 fileName string }{{ name: "json custom data", @@ -380,6 +451,16 @@ func TestNewFromJsonString(t *testing.T) { if d := cmp.Diff(tc.event.GetType(), obtainedEvent.GetType()); d != "" { t.Errorf("args: diff(-want,+got):\n%s", d) } + // Check V04 context + if d := cmp.Diff(tc.event.GetChainId(), obtainedEvent.GetChainId()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + if d := cmp.Diff(tc.event.GetSchemaUri(), obtainedEvent.GetSchemaUri()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + if d := cmp.Diff(tc.event.GetLinks(), obtainedEvent.GetLinks()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } // Check the subject if d := cmp.Diff(tc.event.GetSubject(), obtainedEvent.GetSubject()); d != "" { t.Errorf("args: diff(-want,+got):\n%s", d) @@ -474,10 +555,11 @@ func TestParseType(t *testing.T) { func testEventWithVersion(eventVersion string, specVersion string) *testapi.FooSubjectBarPredicateEvent { event, _ := testapi.NewFooSubjectBarPredicateEvent() setContext(event, testSubjectId) + setContextV04(event, true, true) event.SetSubjectReferenceField(&api.Reference{Id: testChangeId}) event.SetSubjectPlainField(testValue) event.SetSubjectArtifactId(testArtifactId) - event.SetSubjectObjectField(&api.FooSubjectBarPredicateSubjectContentObjectField{Required: testChangeId, Optional: testSource}) + event.SetSubjectObjectField(&testapi.FooSubjectBarPredicateSubjectContentObjectField{Required: testChangeId, Optional: testSource}) err := event.SetCustomData("application/json", testDataJsonUnmarshalled) panicOnError(err) event.Context.Type.Version = eventVersion @@ -487,10 +569,10 @@ func testEventWithVersion(eventVersion string, specVersion string) *testapi.FooS func TestNewFromJsonBytes(t *testing.T) { - minorVersion := testEventWithVersion("1.999.0", testapi.SpecVersion) - patchVersion := testEventWithVersion("1.2.999", testapi.SpecVersion) - pastPatchVersion := testEventWithVersion("1.2.0", testapi.SpecVersion) - pastSpecVersion := testEventWithVersion("1.2.3", "0.1.0") + minorVersion := testEventWithVersion("2.999.1", testapi.SpecVersion) + patchVersion := testEventWithVersion("2.2.999", testapi.SpecVersion) + pastPatchVersion := testEventWithVersion("2.2.0", testapi.SpecVersion) + pastSpecVersion := testEventWithVersion("2.2.3", "0.1.0") tests := []struct { testFile string @@ -500,7 +582,7 @@ func TestNewFromJsonBytes(t *testing.T) { }{{ testFile: "future_event_major_version", description: "A newer major version in the event is backward incompatible and cannot be parsed", - wantError: "sdk event version 1.2.3 not compatible with 999.0.0", + wantError: "sdk event version 2.2.3 not compatible with 999.1.0", }, { testFile: "future_event_minor_version", description: "A newer minor version in the event is compatible and can be parsed, data is lost", diff --git a/pkg/api/schemas.go b/pkg/api/schemas.go new file mode 100644 index 0000000..601ecdc --- /dev/null +++ b/pkg/api/schemas.go @@ -0,0 +1,11692 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2024 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "encoding/json" + "fmt" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +type SchemaDB map[string]*jsonschema.Schema + +var ( + // All compiled schemas by Id + CompiledSchemas SchemaDB + + // All schemas as string by Id + SchemasById = map[string]string{ + "https://cdevents.dev/0.3.0/schema/artifact-packaged-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/artifact-packaged-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.artifact.packaged.0.1.1" + ], + "default": "dev.cdevents.artifact.packaged.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "artifact" + ], + "default": "artifact" + }, + "content": { + "properties": { + "change": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "change" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/artifact-published-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/artifact-published-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.artifact.published.0.1.1" + ], + "default": "dev.cdevents.artifact.published.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "artifact" + ], + "default": "artifact" + }, + "content": { + "properties": {}, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/artifact-signed-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/artifact-signed-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.artifact.signed.0.1.0" + ], + "default": "dev.cdevents.artifact.signed.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "artifact" + ], + "default": "artifact" + }, + "content": { + "properties": { + "signature": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "signature" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/branch-created-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/branch-created-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.branch.created.0.1.2" + ], + "default": "dev.cdevents.branch.created.0.1.2" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "branch" + ], + "default": "branch" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/branch-deleted-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/branch-deleted-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.branch.deleted.0.1.2" + ], + "default": "dev.cdevents.branch.deleted.0.1.2" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "branch" + ], + "default": "branch" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/build-finished-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/build-finished-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.build.finished.0.1.1" + ], + "default": "dev.cdevents.build.finished.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "build" + ], + "default": "build" + }, + "content": { + "properties": { + "artifactId": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/build-queued-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/build-queued-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.build.queued.0.1.1" + ], + "default": "dev.cdevents.build.queued.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "build" + ], + "default": "build" + }, + "content": { + "properties": {}, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/build-started-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/build-started-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.build.started.0.1.1" + ], + "default": "dev.cdevents.build.started.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "build" + ], + "default": "build" + }, + "content": { + "properties": {}, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/change-abandoned-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/change-abandoned-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.change.abandoned.0.1.2" + ], + "default": "dev.cdevents.change.abandoned.0.1.2" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "change" + ], + "default": "change" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/change-created-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/change-created-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.change.created.0.1.2" + ], + "default": "dev.cdevents.change.created.0.1.2" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "change" + ], + "default": "change" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/change-merged-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/change-merged-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.change.merged.0.1.2" + ], + "default": "dev.cdevents.change.merged.0.1.2" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "change" + ], + "default": "change" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/change-reviewed-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/change-reviewed-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.change.reviewed.0.1.2" + ], + "default": "dev.cdevents.change.reviewed.0.1.2" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "change" + ], + "default": "change" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/change-updated-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/change-updated-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.change.updated.0.1.2" + ], + "default": "dev.cdevents.change.updated.0.1.2" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "change" + ], + "default": "change" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/environment-created-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/environment-created-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.environment.created.0.1.1" + ], + "default": "dev.cdevents.environment.created.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "environment" + ], + "default": "environment" + }, + "content": { + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/environment-deleted-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/environment-deleted-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.environment.deleted.0.1.1" + ], + "default": "dev.cdevents.environment.deleted.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "environment" + ], + "default": "environment" + }, + "content": { + "properties": { + "name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/environment-modified-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/environment-modified-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.environment.modified.0.1.1" + ], + "default": "dev.cdevents.environment.modified.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "environment" + ], + "default": "environment" + }, + "content": { + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/incident-detected-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/incident-detected-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.incident.detected.0.1.0" + ], + "default": "dev.cdevents.incident.detected.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "incident" + ], + "default": "incident" + }, + "content": { + "properties": { + "description": { + "type": "string" + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "service": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/incident-reported-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/incident-reported-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.incident.reported.0.1.0" + ], + "default": "dev.cdevents.incident.reported.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "incident" + ], + "default": "incident" + }, + "content": { + "properties": { + "description": { + "type": "string" + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "ticketURI": { + "type": "string", + "format": "uri", + "minLength": 1 + }, + "service": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment", + "ticketURI" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/incident-resolved-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/incident-resolved-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.incident.resolved.0.1.0" + ], + "default": "dev.cdevents.incident.resolved.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "incident" + ], + "default": "incident" + }, + "content": { + "properties": { + "description": { + "type": "string" + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "service": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/pipelinerun-finished-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/pipeline-run-finished-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.pipelinerun.finished.0.1.1" + ], + "default": "dev.cdevents.pipelinerun.finished.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "pipelineRun" + ], + "default": "pipelineRun" + }, + "content": { + "properties": { + "pipelineName": { + "type": "string" + }, + "url": { + "type": "string" + }, + "outcome": { + "type": "string" + }, + "errors": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/pipelinerun-queued-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/pipeline-run-queued-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.pipelinerun.queued.0.1.1" + ], + "default": "dev.cdevents.pipelinerun.queued.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "pipelineRun" + ], + "default": "pipelineRun" + }, + "content": { + "properties": { + "pipelineName": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/pipelinerun-started-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/pipeline-run-started-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.pipelinerun.started.0.1.1" + ], + "default": "dev.cdevents.pipelinerun.started.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "pipelineRun" + ], + "default": "pipelineRun" + }, + "content": { + "properties": { + "pipelineName": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "pipelineName", + "url" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/repository-created-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/repository-created-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.repository.created.0.1.1" + ], + "default": "dev.cdevents.repository.created.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "repository" + ], + "default": "repository" + }, + "content": { + "properties": { + "name": { + "type": "string", + "minLength": 1 + }, + "owner": { + "type": "string" + }, + "url": { + "type": "string", + "minLength": 1 + }, + "viewUrl": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "url" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/repository-deleted-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/repository-deleted-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.repository.deleted.0.1.1" + ], + "default": "dev.cdevents.repository.deleted.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "repository" + ], + "default": "repository" + }, + "content": { + "properties": { + "name": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "url": { + "type": "string" + }, + "viewUrl": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/repository-modified-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/repository-modified-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.repository.modified.0.1.1" + ], + "default": "dev.cdevents.repository.modified.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "repository" + ], + "default": "repository" + }, + "content": { + "properties": { + "name": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "url": { + "type": "string" + }, + "viewUrl": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/service-deployed-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/service-deployed-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.service.deployed.0.1.1" + ], + "default": "dev.cdevents.service.deployed.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "service" + ], + "default": "service" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment", + "artifactId" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/service-published-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/service-published-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.service.published.0.1.1" + ], + "default": "dev.cdevents.service.published.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "service" + ], + "default": "service" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/service-removed-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/service-removed-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.service.removed.0.1.1" + ], + "default": "dev.cdevents.service.removed.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "service" + ], + "default": "service" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/service-rolledback-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/service-rolledback-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.service.rolledback.0.1.1" + ], + "default": "dev.cdevents.service.rolledback.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "service" + ], + "default": "service" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment", + "artifactId" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/service-upgraded-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/service-upgraded-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.service.upgraded.0.1.1" + ], + "default": "dev.cdevents.service.upgraded.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "service" + ], + "default": "service" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment", + "artifactId" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/taskrun-finished-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/task-run-finished-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.taskrun.finished.0.1.1" + ], + "default": "dev.cdevents.taskrun.finished.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "taskRun" + ], + "default": "taskRun" + }, + "content": { + "properties": { + "taskName": { + "type": "string" + }, + "url": { + "type": "string" + }, + "pipelineRun": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "outcome": { + "type": "string" + }, + "errors": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/taskrun-started-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/task-run-started-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.taskrun.started.0.1.1" + ], + "default": "dev.cdevents.taskrun.started.0.1.1" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "taskRun" + ], + "default": "taskRun" + }, + "content": { + "properties": { + "taskName": { + "type": "string" + }, + "url": { + "type": "string" + }, + "pipelineRun": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.3.0/schema/testcaserun-finished-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/test-case-run-finished-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testcaserun.finished.0.1.0" + ], + "default": "dev.cdevents.testcaserun.finished.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testCaseRun" + ], + "default": "testCaseRun" + }, + "content": { + "properties": { + "outcome": { + "type": "string", + "enum": [ + "pass", + "fail", + "cancel", + "error" + ] + }, + "severity": { + "type": "string", + "enum": [ + "low", + "medium", + "high", + "critical" + ] + }, + "reason": { + "type": "string" + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuiteRun": { + "type": "object", + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "id" + ] + }, + "testCase": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "performance", + "functional", + "unit", + "security", + "compliance", + "integration", + "e2e", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "outcome", + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.3.0/schema/testcaserun-queued-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/test-case-run-queued-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testcaserun.queued.0.1.0" + ], + "default": "dev.cdevents.testcaserun.queued.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testCaseRun" + ], + "default": "testCaseRun" + }, + "content": { + "properties": { + "trigger": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "manual", + "pipeline", + "event", + "schedule", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuiteRun": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testCase": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "performance", + "functional", + "unit", + "security", + "compliance", + "integration", + "e2e", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.3.0/schema/testcaserun-started-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/test-case-run-started-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testcaserun.started.0.1.0" + ], + "default": "dev.cdevents.testcaserun.started.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testCaseRun" + ], + "default": "testCaseRun" + }, + "content": { + "properties": { + "trigger": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "manual", + "pipeline", + "event", + "schedule", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuiteRun": { + "type": "object", + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "id" + ] + }, + "testCase": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "performance", + "functional", + "unit", + "security", + "compliance", + "integration", + "e2e", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.3.0/schema/testoutput-published-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/test-output-published-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testoutput.published.0.1.0" + ], + "default": "dev.cdevents.testoutput.published.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testOutput" + ], + "default": "testOutput" + }, + "content": { + "properties": { + "outputType": { + "type": "string", + "enum": [ + "report", + "video", + "image", + "log", + "other" + ] + }, + "format": { + "type": "string", + "example": "application/pdf" + }, + "uri": { + "type": "string", + "format": "uri" + }, + "testCaseRun": { + "type": "object", + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "outputType", + "format" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.3.0/schema/testsuiterun-finished-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/test-suite-finished-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testsuiterun.finished.0.1.0" + ], + "default": "dev.cdevents.testsuiterun.finished.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testSuiteRun" + ], + "default": "testSuiteRun" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuite": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "uri": { + "type": "string", + "format": "uri" + } + } + }, + "outcome": { + "type": "string", + "enum": [ + "pass", + "fail", + "cancel", + "error" + ] + }, + "severity": { + "type": "string", + "enum": [ + "low", + "medium", + "high", + "critical" + ] + }, + "reason": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "outcome", + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.3.0/schema/testsuiterun-queued-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/test-suite-run-queued-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testsuiterun.queued.0.1.0" + ], + "default": "dev.cdevents.testsuiterun.queued.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testSuiteRun" + ], + "default": "testSuiteRun" + }, + "content": { + "properties": { + "trigger": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "manual", + "pipeline", + "event", + "schedule", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuite": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri" + } + } + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.3.0/schema/testsuiterun-started-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.3.0/schema/test-suite-run-started-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testsuiterun.started.0.1.0" + ], + "default": "dev.cdevents.testsuiterun.started.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testSuiteRun" + ], + "default": "testSuiteRun" + }, + "content": { + "properties": { + "trigger": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "manual", + "pipeline", + "event", + "schedule", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuite": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "uri": { + "type": "string", + "format": "uri" + } + } + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/artifact-deleted-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/artifact-deleted-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.artifact.deleted.0.1.0" + ], + "default": "dev.cdevents.artifact.deleted.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "artifact" + ], + "default": "artifact" + }, + "content": { + "properties": { + "user": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/artifact-downloaded-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/artifact-downloaded-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.artifact.downloaded.0.1.0" + ], + "default": "dev.cdevents.artifact.downloaded.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "artifact" + ], + "default": "artifact" + }, + "content": { + "properties": { + "user": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/artifact-packaged-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/artifact-packaged-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.artifact.packaged.0.2.0" + ], + "default": "dev.cdevents.artifact.packaged.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "artifact" + ], + "default": "artifact" + }, + "content": { + "properties": { + "change": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "sbom": { + "properties": { + "uri": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "uri" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "change" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/artifact-published-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/artifact-published-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.artifact.published.0.2.0" + ], + "default": "dev.cdevents.artifact.published.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "artifact" + ], + "default": "artifact" + }, + "content": { + "properties": { + "sbom": { + "properties": { + "uri": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "uri" + ] + }, + "user": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/artifact-signed-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/artifact-signed-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.artifact.signed.0.2.0" + ], + "default": "dev.cdevents.artifact.signed.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "artifact" + ], + "default": "artifact" + }, + "content": { + "properties": { + "signature": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "signature" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/branch-created-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/branch-created-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.branch.created.0.2.0" + ], + "default": "dev.cdevents.branch.created.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "branch" + ], + "default": "branch" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/branch-deleted-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/branch-deleted-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.branch.deleted.0.2.0" + ], + "default": "dev.cdevents.branch.deleted.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "branch" + ], + "default": "branch" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/build-finished-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/build-finished-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.build.finished.0.2.0" + ], + "default": "dev.cdevents.build.finished.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "build" + ], + "default": "build" + }, + "content": { + "properties": { + "artifactId": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/build-queued-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/build-queued-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.build.queued.0.2.0" + ], + "default": "dev.cdevents.build.queued.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "build" + ], + "default": "build" + }, + "content": { + "properties": {}, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/build-started-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/build-started-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.build.started.0.2.0" + ], + "default": "dev.cdevents.build.started.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "build" + ], + "default": "build" + }, + "content": { + "properties": {}, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/change-abandoned-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/change-abandoned-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.change.abandoned.0.2.0" + ], + "default": "dev.cdevents.change.abandoned.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "change" + ], + "default": "change" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/change-created-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/change-created-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.change.created.0.3.0" + ], + "default": "dev.cdevents.change.created.0.3.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "change" + ], + "default": "change" + }, + "content": { + "properties": { + "description": { + "type": "string", + "minLength": 1 + }, + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/change-merged-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/change-merged-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.change.merged.0.2.0" + ], + "default": "dev.cdevents.change.merged.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "change" + ], + "default": "change" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/change-reviewed-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/change-reviewed-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.change.reviewed.0.2.0" + ], + "default": "dev.cdevents.change.reviewed.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "change" + ], + "default": "change" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/change-updated-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/change-updated-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.change.updated.0.2.0" + ], + "default": "dev.cdevents.change.updated.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "change" + ], + "default": "change" + }, + "content": { + "properties": { + "repository": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/custom": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/custom", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "pattern": "^dev\\.cdeventsx\\.[a-zA-Z0-9]+-[a-zA-Z]+\\.[a-zA-Z]+\\.[0-9]\\.[0-9]\\.[0-9]$" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "pattern": "^[a-zA-Z0-9]+-[a-zA-Z]+$" + }, + "content": { + "type": "object", + "additionalProperties": true + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.4.1/schema/environment-created-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/environment-created-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.environment.created.0.2.0" + ], + "default": "dev.cdevents.environment.created.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "environment" + ], + "default": "environment" + }, + "content": { + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/environment-deleted-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/environment-deleted-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.environment.deleted.0.2.0" + ], + "default": "dev.cdevents.environment.deleted.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "environment" + ], + "default": "environment" + }, + "content": { + "properties": { + "name": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/environment-modified-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/environment-modified-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.environment.modified.0.2.0" + ], + "default": "dev.cdevents.environment.modified.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "environment" + ], + "default": "environment" + }, + "content": { + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/incident-detected-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/incident-detected-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.incident.detected.0.2.0" + ], + "default": "dev.cdevents.incident.detected.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "incident" + ], + "default": "incident" + }, + "content": { + "properties": { + "description": { + "type": "string" + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "service": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/incident-reported-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/incident-reported-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.incident.reported.0.2.0" + ], + "default": "dev.cdevents.incident.reported.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "incident" + ], + "default": "incident" + }, + "content": { + "properties": { + "description": { + "type": "string" + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "ticketURI": { + "type": "string", + "format": "uri", + "minLength": 1 + }, + "service": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment", + "ticketURI" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/incident-resolved-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/incident-resolved-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.incident.resolved.0.2.0" + ], + "default": "dev.cdevents.incident.resolved.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "incident" + ], + "default": "incident" + }, + "content": { + "properties": { + "description": { + "type": "string" + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "service": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/links/embeddedlinkend": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/links/embeddedlinkend", + "properties": { + "linkType": { + "type": "string", + "enum": [ + "END" + ] + }, + "from": { + "description": "When consuming a CDEvent, you are consuming a parent event. So, when looking at the 'from' key, this is the parent's parent.", + "type": "object", + "properties": { + "contextId": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "contextId" + ] + }, + "tags": { + "type": "object", + "additionalProperties": true + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "linkType" + ] +} + +`, + "https://cdevents.dev/0.4.1/schema/links/embeddedlinkpath": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/links/embeddedlinkpath", + "properties": { + "linkType": { + "type": "string", + "enum": [ + "PATH" + ] + }, + "from": { + "description": "When consuming a CDEvent, you are consuming a parent event. So, when looking at the 'from' key, this is the parent's parent.", + "type": "object", + "properties": { + "contextId": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "contextId" + ] + }, + "tags": { + "type": "object", + "additionalProperties": true + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "linkType", + "from" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/links/embeddedlinkrelation": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/links/embeddedlinkrelation", + "properties": { + "linkType": { + "type": "string", + "enum": [ + "RELATION" + ] + }, + "linkKind": { + "type": "string", + "minLength": 1 + }, + "target": { + "description": "", + "type": "object", + "properties": { + "contextId": { + "type": "string", + "minLength": 1 + } + } + }, + "tags": { + "type": "object", + "additionalProperties": true + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "linkType", + "linkKind", + "target" + ] +} + +`, + "https://cdevents.dev/0.4.1/schema/links/embeddedlinksarray": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/links/embeddedlinksarray", + "type": "array", + "items": { + "anyOf": [ + { + "type": "object", + "$ref": "embeddedlinkend" + }, + { + "type": "object", + "$ref": "embeddedlinkpath" + }, + { + "type": "object", + "$ref": "embeddedlinkrelation" + } + ] + } +} +`, + "https://cdevents.dev/0.4.1/schema/links/linkend": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/links/linkend", + "properties": { + "chainId": { + "description": "This represents the full lifecycles of a series of events in CDEvents", + "type": "string", + "minLength": 1 + }, + "linkType": { + "description": "The type associated with the link. In this case, 'END', suggesting the end of some CI/CD lifecycle", + "type": "string", + "enum": [ + "END" + ] + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "from": { + "description": "This is the context ID of the producing CDEvent.", + "type": "object", + "properties": { + "contextId": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "contextId" + ] + }, + "end": { + "description": "This is the context ID of the final CDEvent in the chain", + "type": "object", + "properties": { + "contextId": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "contextId" + ] + }, + "tags": { + "type": "object", + "additionalProperties": true + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "chainId", + "linkType", + "timestamp", + "from", + "end" + ] +} + +`, + "https://cdevents.dev/0.4.1/schema/links/linkpath": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/links/linkpath", + "properties": { + "chainId": { + "type": "string", + "minLength": 1 + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "linkType": { + "type": "string", + "enum": [ + "PATH" + ] + }, + "from": { + "type": "object", + "properties": { + "contextId": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "contextId" + ] + }, + "to": { + "type": "object", + "properties": { + "contextId": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "contextId" + ] + }, + "tags": { + "type": "object", + "additionalProperties": true + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "chainId", + "linkType", + "timestamp", + "from", + "to" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/links/linkrelation": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/links/linkrelation", + "properties": { + "chainId": { + "description": "This represents the full lifecycles of a series of events in CDEvents", + "type": "string", + "minLength": 1 + }, + "linkType": { + "type": "string", + "enum": [ + "RELATION" + ] + }, + "linkKind": { + "type": "string", + "minLength": 1 + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "source": { + "description": "", + "type": "object", + "properties": { + "contextId": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "contextId" + ] + }, + "target": { + "description": "", + "type": "object", + "properties": { + "contextId": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "contextId" + ] + }, + "tags": { + "type": "object", + "additionalProperties": true + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "chainId", + "linkType", + "timestamp", + "source", + "target" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/links/linkstart": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/links/linkstart", + "properties": { + "chainId": { + "description": "This represents the full lifecycles of a series of events in CDEvents", + "type": "string", + "minLength": 1 + }, + "linkType": { + "description": "The type associated with the link. In this case, 'START', suggesting the start of some CI/CD lifecycle", + "type": "string", + "enum": [ + "START" + ] + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "start": { + "description": "This is the context ID of the starting CDEvent in the chain.", + "type": "object", + "properties": { + "contextId": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "contextId" + ] + }, + "tags": { + "type": "object", + "additionalProperties": true + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "chainId", + "linkType", + "timestamp", + "start" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/pipelinerun-finished-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/pipeline-run-finished-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.pipelinerun.finished.0.2.0" + ], + "default": "dev.cdevents.pipelinerun.finished.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "pipelineRun" + ], + "default": "pipelineRun" + }, + "content": { + "properties": { + "pipelineName": { + "type": "string" + }, + "url": { + "type": "string" + }, + "outcome": { + "type": "string" + }, + "errors": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/pipelinerun-queued-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/pipeline-run-queued-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.pipelinerun.queued.0.2.0" + ], + "default": "dev.cdevents.pipelinerun.queued.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "pipelineRun" + ], + "default": "pipelineRun" + }, + "content": { + "properties": { + "pipelineName": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/pipelinerun-started-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/pipeline-run-started-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.pipelinerun.started.0.2.0" + ], + "default": "dev.cdevents.pipelinerun.started.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "pipelineRun" + ], + "default": "pipelineRun" + }, + "content": { + "properties": { + "pipelineName": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "pipelineName", + "url" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/repository-created-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/repository-created-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.repository.created.0.2.0" + ], + "default": "dev.cdevents.repository.created.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "repository" + ], + "default": "repository" + }, + "content": { + "properties": { + "name": { + "type": "string", + "minLength": 1 + }, + "owner": { + "type": "string" + }, + "url": { + "type": "string", + "minLength": 1 + }, + "viewUrl": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "url" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/repository-deleted-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/repository-deleted-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.repository.deleted.0.2.0" + ], + "default": "dev.cdevents.repository.deleted.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "repository" + ], + "default": "repository" + }, + "content": { + "properties": { + "name": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "url": { + "type": "string" + }, + "viewUrl": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/repository-modified-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/repository-modified-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.repository.modified.0.2.0" + ], + "default": "dev.cdevents.repository.modified.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "repository" + ], + "default": "repository" + }, + "content": { + "properties": { + "name": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "url": { + "type": "string" + }, + "viewUrl": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/service-deployed-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/service-deployed-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.service.deployed.0.2.0" + ], + "default": "dev.cdevents.service.deployed.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "service" + ], + "default": "service" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment", + "artifactId" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/service-published-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/service-published-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.service.published.0.2.0" + ], + "default": "dev.cdevents.service.published.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "service" + ], + "default": "service" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/service-removed-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/service-removed-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.service.removed.0.2.0" + ], + "default": "dev.cdevents.service.removed.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "service" + ], + "default": "service" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/service-rolledback-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/service-rolledback-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.service.rolledback.0.2.0" + ], + "default": "dev.cdevents.service.rolledback.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "service" + ], + "default": "service" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment", + "artifactId" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/service-upgraded-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/service-upgraded-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.service.upgraded.0.2.0" + ], + "default": "dev.cdevents.service.upgraded.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "service" + ], + "default": "service" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string", + "minLength": 1 + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment", + "artifactId" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/taskrun-finished-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/task-run-finished-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.taskrun.finished.0.2.0" + ], + "default": "dev.cdevents.taskrun.finished.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "taskRun" + ], + "default": "taskRun" + }, + "content": { + "properties": { + "taskName": { + "type": "string" + }, + "url": { + "type": "string" + }, + "pipelineRun": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "outcome": { + "type": "string" + }, + "errors": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/taskrun-started-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/task-run-started-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.taskrun.started.0.2.0" + ], + "default": "dev.cdevents.taskrun.started.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "taskRun" + ], + "default": "taskRun" + }, + "content": { + "properties": { + "taskName": { + "type": "string" + }, + "url": { + "type": "string" + }, + "pipelineRun": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/testcaserun-finished-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/test-case-run-finished-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testcaserun.finished.0.2.0" + ], + "default": "dev.cdevents.testcaserun.finished.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testCaseRun" + ], + "default": "testCaseRun" + }, + "content": { + "properties": { + "outcome": { + "type": "string", + "enum": [ + "pass", + "fail", + "cancel", + "error" + ] + }, + "severity": { + "type": "string", + "enum": [ + "low", + "medium", + "high", + "critical" + ] + }, + "reason": { + "type": "string" + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuiteRun": { + "type": "object", + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "id" + ] + }, + "testCase": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "performance", + "functional", + "unit", + "security", + "compliance", + "integration", + "e2e", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "outcome", + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/testcaserun-queued-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/test-case-run-queued-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testcaserun.queued.0.2.0" + ], + "default": "dev.cdevents.testcaserun.queued.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testCaseRun" + ], + "default": "testCaseRun" + }, + "content": { + "properties": { + "trigger": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "manual", + "pipeline", + "event", + "schedule", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuiteRun": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testCase": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "performance", + "functional", + "unit", + "security", + "compliance", + "integration", + "e2e", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/testcaserun-skipped-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/test-case-run-skipped-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testcaserun.skipped.0.1.0" + ], + "default": "dev.cdevents.testcaserun.skipped.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testCaseRun" + ], + "default": "testCaseRun" + }, + "content": { + "properties": { + "reason": { + "type": "string" + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuiteRun": { + "type": "object", + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "id" + ] + }, + "testCase": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "performance", + "functional", + "unit", + "security", + "compliance", + "integration", + "e2e", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + } + }, + "additionalProperties": false, + "type": "object", + "required": [] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/0.4.1/schema/testcaserun-started-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/test-case-run-started-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testcaserun.started.0.2.0" + ], + "default": "dev.cdevents.testcaserun.started.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testCaseRun" + ], + "default": "testCaseRun" + }, + "content": { + "properties": { + "trigger": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "manual", + "pipeline", + "event", + "schedule", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuiteRun": { + "type": "object", + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "id" + ] + }, + "testCase": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "performance", + "functional", + "unit", + "security", + "compliance", + "integration", + "e2e", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/testoutput-published-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/test-output-published-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testoutput.published.0.2.0" + ], + "default": "dev.cdevents.testoutput.published.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testOutput" + ], + "default": "testOutput" + }, + "content": { + "properties": { + "outputType": { + "type": "string", + "enum": [ + "report", + "video", + "image", + "log", + "other" + ] + }, + "format": { + "type": "string", + "example": "application/pdf" + }, + "uri": { + "type": "string", + "format": "uri" + }, + "testCaseRun": { + "type": "object", + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "id" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "outputType", + "format" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/testsuiterun-finished-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/test-suite-run-finished-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testsuiterun.finished.0.2.0" + ], + "default": "dev.cdevents.testsuiterun.finished.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testSuiteRun" + ], + "default": "testSuiteRun" + }, + "content": { + "properties": { + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuite": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "uri": { + "type": "string", + "format": "uri" + } + } + }, + "outcome": { + "type": "string", + "enum": [ + "pass", + "fail", + "cancel", + "error" + ] + }, + "severity": { + "type": "string", + "enum": [ + "low", + "medium", + "high", + "critical" + ] + }, + "reason": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "outcome", + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/testsuiterun-queued-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/test-suite-run-queued-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testsuiterun.queued.0.2.0" + ], + "default": "dev.cdevents.testsuiterun.queued.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testSuiteRun" + ], + "default": "testSuiteRun" + }, + "content": { + "properties": { + "trigger": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "manual", + "pipeline", + "event", + "schedule", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuite": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri" + } + } + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/testsuiterun-started-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/test-suite-run-started-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.testsuiterun.started.0.2.0" + ], + "default": "dev.cdevents.testsuiterun.started.0.2.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "testSuiteRun" + ], + "default": "testSuiteRun" + }, + "content": { + "properties": { + "trigger": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "manual", + "pipeline", + "event", + "schedule", + "other" + ] + }, + "uri": { + "type": "string", + "format": "uri" + } + } + }, + "environment": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "testSuite": { + "type": "object", + "additionalProperties": false, + "required": [ + "id" + ], + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "uri": { + "type": "string", + "format": "uri" + } + } + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "environment" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/ticket-closed-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/ticket-closed-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.ticket.closed.0.1.0" + ], + "default": "dev.cdevents.ticket.closed.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "ticket" + ], + "default": "ticket" + }, + "content": { + "properties": { + "summary": { + "type": "string" + }, + "ticketType": { + "anyOf": [ + { + "type": "string", + "enum": [ + "bug", + "enhancement", + "incident", + "task", + "question" + ] + }, + { + "type": "string" + } + ] + }, + "group": { + "type": "string" + }, + "creator": { + "type": "string", + "minLength": 1 + }, + "assignees": { + "type": "array", + "items": { + "type": "string" + } + }, + "priority": { + "anyOf": [ + { + "type": "string", + "enum": [ + "low", + "medium", + "high" + ] + }, + { + "type": "string" + } + ] + }, + "labels": { + "type": "array", + "items": { + "type": "string" + } + }, + "milestone": { + "type": "string" + }, + "uri": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "resolution": { + "anyOf": [ + { + "type": "string", + "enum": [ + "completed", + "withdrawn", + "duplicate" + ] + }, + { + "type": "string", + "minLength": 1 + } + ] + }, + "updatedBy": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "uri", + "resolution" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/ticket-created-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/ticket-created-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.ticket.created.0.1.0" + ], + "default": "dev.cdevents.ticket.created.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "ticket" + ], + "default": "ticket" + }, + "content": { + "properties": { + "summary": { + "type": "string" + }, + "ticketType": { + "anyOf": [ + { + "type": "string", + "enum": [ + "bug", + "enhancement", + "incident", + "task", + "question" + ] + }, + { + "type": "string" + } + ] + }, + "group": { + "type": "string" + }, + "creator": { + "type": "string", + "minLength": 1 + }, + "assignees": { + "type": "array", + "items": { + "type": "string" + } + }, + "priority": { + "anyOf": [ + { + "type": "string", + "enum": [ + "low", + "medium", + "high" + ] + }, + { + "type": "string" + } + ] + }, + "labels": { + "type": "array", + "items": { + "type": "string" + } + }, + "milestone": { + "type": "string" + }, + "uri": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "summary", + "creator", + "uri" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + "https://cdevents.dev/0.4.1/schema/ticket-updated-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/0.4.1/schema/ticket-updated-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.ticket.updated.0.1.0" + ], + "default": "dev.cdevents.ticket.updated.0.1.0" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "ticket" + ], + "default": "ticket" + }, + "content": { + "properties": { + "summary": { + "type": "string" + }, + "ticketType": { + "anyOf": [ + { + "type": "string", + "enum": [ + "bug", + "enhancement", + "incident", + "task", + "question" + ] + }, + { + "type": "string" + } + ] + }, + "group": { + "type": "string" + }, + "creator": { + "type": "string", + "minLength": 1 + }, + "assignees": { + "type": "array", + "items": { + "type": "string" + } + }, + "priority": { + "anyOf": [ + { + "type": "string", + "enum": [ + "low", + "medium", + "high" + ] + }, + { + "type": "string" + } + ] + }, + "labels": { + "type": "array", + "items": { + "type": "string" + } + }, + "milestone": { + "type": "string" + }, + "updatedBy": { + "type": "string" + }, + "uri": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "uri" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} +`, + } +) + +func init() { + compiler, err := newJsonSchemaCompiler() + panicOnError(err) + CompiledSchemas = make(map[string]*jsonschema.Schema) + for url, _ := range SchemasById { + sch, err := compiler.Compile(url) + panicOnError(err) + CompiledSchemas[url] = sch + } +} +func (db SchemaDB) GetBySpecSubjectPredicate(specVersion, subject, predicate string) (string, *jsonschema.Schema, error) { + id := fmt.Sprintf(CDEventsSchemaURLTemplate, specVersion, subject, predicate) + if schemaString, found := db[id]; found { + return id, schemaString, nil + } + return "", nil, fmt.Errorf("event %s/%s not found for spec %s in local schema DB", specVersion, subject, predicate) +} + +func newJsonSchemaCompiler() (*jsonschema.Compiler, error) { + c := jsonschema.NewCompiler() + for url, content := range SchemasById { + var loaded map[string]interface{} + err := json.Unmarshal([]byte(content), &loaded) + if err != nil { + return nil, err + } + if err := c.AddResource(url, loaded); err != nil { + return nil, err + } + } + return c, nil +} diff --git a/pkg/api/spec-v0.4 b/pkg/api/spec-v0.4 new file mode 160000 index 0000000..f95df21 --- /dev/null +++ b/pkg/api/spec-v0.4 @@ -0,0 +1 @@ +Subproject commit f95df21d7e3045a37d2c85e07f90805130fd65be diff --git a/pkg/api/tests/examples/future_event_major_version.json b/pkg/api/tests-v99.0/examples/future_event_major_version.json similarity index 100% rename from pkg/api/tests/examples/future_event_major_version.json rename to pkg/api/tests-v99.0/examples/future_event_major_version.json diff --git a/pkg/api/tests/examples/future_event_minor_version.json b/pkg/api/tests-v99.0/examples/future_event_minor_version.json similarity index 100% rename from pkg/api/tests/examples/future_event_minor_version.json rename to pkg/api/tests-v99.0/examples/future_event_minor_version.json diff --git a/pkg/api/tests/examples/future_event_patch_version.json b/pkg/api/tests-v99.0/examples/future_event_patch_version.json similarity index 100% rename from pkg/api/tests/examples/future_event_patch_version.json rename to pkg/api/tests-v99.0/examples/future_event_patch_version.json diff --git a/pkg/api/tests/examples/implicit_json_custom_data.json b/pkg/api/tests-v99.0/examples/implicit_json_custom_data.json similarity index 100% rename from pkg/api/tests/examples/implicit_json_custom_data.json rename to pkg/api/tests-v99.0/examples/implicit_json_custom_data.json diff --git a/pkg/api/tests/examples/json_custom_data.json b/pkg/api/tests-v99.0/examples/json_custom_data.json similarity index 100% rename from pkg/api/tests/examples/json_custom_data.json rename to pkg/api/tests-v99.0/examples/json_custom_data.json diff --git a/pkg/api/tests/examples/non_json_custom_data.json b/pkg/api/tests-v99.0/examples/non_json_custom_data.json similarity index 100% rename from pkg/api/tests/examples/non_json_custom_data.json rename to pkg/api/tests-v99.0/examples/non_json_custom_data.json diff --git a/pkg/api/tests/examples/non_unmarshable.json b/pkg/api/tests-v99.0/examples/non_unmarshable.json similarity index 100% rename from pkg/api/tests/examples/non_unmarshable.json rename to pkg/api/tests-v99.0/examples/non_unmarshable.json diff --git a/pkg/api/tests/examples/past_event_patch_version.json b/pkg/api/tests-v99.0/examples/past_event_patch_version.json similarity index 100% rename from pkg/api/tests/examples/past_event_patch_version.json rename to pkg/api/tests-v99.0/examples/past_event_patch_version.json diff --git a/pkg/api/tests/examples/past_spec_patch_version.json b/pkg/api/tests-v99.0/examples/past_spec_patch_version.json similarity index 100% rename from pkg/api/tests/examples/past_spec_patch_version.json rename to pkg/api/tests-v99.0/examples/past_spec_patch_version.json diff --git a/pkg/api/tests/examples/unknown_type.json b/pkg/api/tests-v99.0/examples/unknown_type.json similarity index 100% rename from pkg/api/tests/examples/unknown_type.json rename to pkg/api/tests-v99.0/examples/unknown_type.json diff --git a/pkg/api/tests/examples/unparsable_context.json b/pkg/api/tests-v99.0/examples/unparsable_context.json similarity index 100% rename from pkg/api/tests/examples/unparsable_context.json rename to pkg/api/tests-v99.0/examples/unparsable_context.json diff --git a/pkg/api/tests/examples/unparsable_type.json b/pkg/api/tests-v99.0/examples/unparsable_type.json similarity index 100% rename from pkg/api/tests/examples/unparsable_type.json rename to pkg/api/tests-v99.0/examples/unparsable_type.json diff --git a/pkg/api/tests/schemas/foosubjectbarpredicate.json b/pkg/api/tests-v99.0/schemas/foosubjectbarpredicate.json similarity index 100% rename from pkg/api/tests/schemas/foosubjectbarpredicate.json rename to pkg/api/tests-v99.0/schemas/foosubjectbarpredicate.json diff --git a/pkg/api/tests-v99.1/examples/future_event_major_version.json b/pkg/api/tests-v99.1/examples/future_event_major_version.json new file mode 100644 index 0000000..4a0b84b --- /dev/null +++ b/pkg/api/tests-v99.1/examples/future_event_major_version.json @@ -0,0 +1,62 @@ +{ + "context": { + "version": "99.1.0", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject.barpredicate.999.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z", + "chainId": "4c8cb7dd-3448-41de-8768-eec704e2829b", + "schemaUri": "https://myorg.com/schema/custom", + "links": [ + { + "linkType": "RELATION", + "linkKind": "TRIGGER", + "target": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "PATH", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "END", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + } + ] + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "contentRenamed": { + "referenceField": { + "id": "myChange123" + } + } + }, + "customData": { + "testValues": [ + { + "k1": "v1" + }, + { + "k2": "v2" + } + ] + }, + "customDataContentType": "application/json" +} diff --git a/pkg/api/tests-v99.1/examples/future_event_minor_version.json b/pkg/api/tests-v99.1/examples/future_event_minor_version.json new file mode 100644 index 0000000..f398a80 --- /dev/null +++ b/pkg/api/tests-v99.1/examples/future_event_minor_version.json @@ -0,0 +1,72 @@ +{ + "context": { + "version": "99.1.0", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject.barpredicate.2.999.1", + "timestamp": "2023-03-20T14:27:05.315384Z", + "newContextField": "ignored", + "chainId": "4c8cb7dd-3448-41de-8768-eec704e2829b", + "schemaUri": "https://myorg.com/schema/custom", + "links": [ + { + "linkType": "RELATION", + "linkKind": "TRIGGER", + "target": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "PATH", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "END", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + } + ] + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "type": "fooSubject", + "content": { + "plainField": "testValue", + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427", + "referenceField": { + "id": "myChange123" + }, + "objectField": { + "required": "myChange123", + "optional": "/event/source/123" + } + }, + "newSubjectField": "ignored" + }, + "customData": { + "testValues": [ + { + "k1": "v1" + }, + { + "k2": "v2" + } + ] + }, + "customDataContentType": "application/json", + "newRootField": "ignored" +} diff --git a/pkg/api/tests-v99.1/examples/future_event_patch_version.json b/pkg/api/tests-v99.1/examples/future_event_patch_version.json new file mode 100644 index 0000000..c3b3b85 --- /dev/null +++ b/pkg/api/tests-v99.1/examples/future_event_patch_version.json @@ -0,0 +1,69 @@ +{ + "context": { + "version": "99.1.0", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject.barpredicate.2.2.999", + "timestamp": "2023-03-20T14:27:05.315384Z", + "chainId": "4c8cb7dd-3448-41de-8768-eec704e2829b", + "schemaUri": "https://myorg.com/schema/custom", + "links": [ + { + "linkType": "RELATION", + "linkKind": "TRIGGER", + "target": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "PATH", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "END", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + } + ] + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "type": "fooSubject", + "content": { + "plainField": "testValue", + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427", + "referenceField": { + "id": "myChange123" + }, + "objectField": { + "required": "myChange123", + "optional": "/event/source/123" + } + } + }, + "customData": { + "testValues": [ + { + "k1": "v1" + }, + { + "k2": "v2" + } + ] + }, + "customDataContentType": "application/json" +} diff --git a/pkg/api/tests-v99.1/examples/implicit_json_custom_data.json b/pkg/api/tests-v99.1/examples/implicit_json_custom_data.json new file mode 100644 index 0000000..c0164b9 --- /dev/null +++ b/pkg/api/tests-v99.1/examples/implicit_json_custom_data.json @@ -0,0 +1,31 @@ +{ + "context": { + "version": "99.1.0", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject.barpredicate.2.2.3", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "type": "fooSubject", + "content": { + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427", + "plainField": "testValue", + "referenceField": { + "id": "myChange123" + }, + "objectField": { + "required": "myChange123", + "optional": "/event/source/123" + } + } + }, + "customData": { + "testValues": [ + {"k1": "v1"}, + {"k2": "v2"} + ] + } +} \ No newline at end of file diff --git a/pkg/api/tests-v99.1/examples/json_custom_data.json b/pkg/api/tests-v99.1/examples/json_custom_data.json new file mode 100644 index 0000000..df0d95a --- /dev/null +++ b/pkg/api/tests-v99.1/examples/json_custom_data.json @@ -0,0 +1,65 @@ +{ + "context": { + "version": "99.1.0", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject.barpredicate.2.2.3", + "timestamp": "2023-03-20T14:27:05.315384Z", + "chainId": "4c8cb7dd-3448-41de-8768-eec704e2829b", + "schemaUri": "https://myorg.com/schema/custom", + "links": [ + { + "linkType": "RELATION", + "linkKind": "TRIGGER", + "target": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "PATH", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "END", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + } + ] + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "type": "fooSubject", + "content": { + "referenceField": { + "id": "myChange123" + }, + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427", + "plainField": "testValue", + "objectField": { + "required": "myChange123", + "optional": "/event/source/123" + } + } + }, + "customData": { + "testValues": [ + {"k1": "v1"}, + {"k2": "v2"} + ] + }, + "customDataContentType": "application/json" +} \ No newline at end of file diff --git a/pkg/api/tests-v99.1/examples/non_json_custom_data.json b/pkg/api/tests-v99.1/examples/non_json_custom_data.json new file mode 100644 index 0000000..6bf0081 --- /dev/null +++ b/pkg/api/tests-v99.1/examples/non_json_custom_data.json @@ -0,0 +1,60 @@ +{ + "context": { + "version": "99.1.0", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject.barpredicate.2.2.3", + "timestamp": "2023-03-20T14:27:05.315384Z", + "chainId": "4c8cb7dd-3448-41de-8768-eec704e2829b", + "schemaUri": "https://myorg.com/schema/custom", + "links": [ + { + "linkType": "RELATION", + "linkKind": "TRIGGER", + "target": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "PATH", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "END", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + } + ] + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "type": "fooSubject", + "content": { + "referenceField": { + "id": "myChange123" + }, + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427", + "plainField": "testValue", + "objectField": { + "required": "myChange123", + "optional": "/event/source/123" + } + } + }, + "customData": "PHhtbD50ZXN0RGF0YTwveG1sPg==", + "customDataContentType": "application/xml" +} \ No newline at end of file diff --git a/pkg/api/tests-v99.1/examples/non_unmarshable.json b/pkg/api/tests-v99.1/examples/non_unmarshable.json new file mode 100644 index 0000000..99e586c --- /dev/null +++ b/pkg/api/tests-v99.1/examples/non_unmarshable.json @@ -0,0 +1,26 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject.barpredicate.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123"@, + "source": "/event/source/123", + "type": "artifact", + "content": { + "change": { + "id": "myChange123" + } + } + }, + "customData": { + "testValues": [ + {"k1": "v1"}, + {"k2": "v2"} + ] + }, + "customDataContentType": "application/json" +} \ No newline at end of file diff --git a/pkg/api/tests-v99.1/examples/past_event_patch_version.json b/pkg/api/tests-v99.1/examples/past_event_patch_version.json new file mode 100644 index 0000000..8192baa --- /dev/null +++ b/pkg/api/tests-v99.1/examples/past_event_patch_version.json @@ -0,0 +1,65 @@ +{ + "context": { + "version": "99.1.0", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject.barpredicate.2.2.0", + "timestamp": "2023-03-20T14:27:05.315384Z", + "chainId": "4c8cb7dd-3448-41de-8768-eec704e2829b", + "schemaUri": "https://myorg.com/schema/custom", + "links": [ + { + "linkType": "RELATION", + "linkKind": "TRIGGER", + "target": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "PATH", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "END", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + } + ] + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "type": "fooSubject", + "content": { + "plainField": "testValue", + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427", + "referenceField": { + "id": "myChange123" + } + } + }, + "customData": { + "testValues": [ + { + "k1": "v1" + }, + { + "k2": "v2" + } + ] + }, + "customDataContentType": "application/json" +} diff --git a/pkg/api/tests-v99.1/examples/past_spec_patch_version.json b/pkg/api/tests-v99.1/examples/past_spec_patch_version.json new file mode 100644 index 0000000..5064e9b --- /dev/null +++ b/pkg/api/tests-v99.1/examples/past_spec_patch_version.json @@ -0,0 +1,65 @@ +{ + "context": { + "version": "0.1.0", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject.barpredicate.2.2.3", + "timestamp": "2023-03-20T14:27:05.315384Z", + "chainId": "4c8cb7dd-3448-41de-8768-eec704e2829b", + "schemaUri": "https://myorg.com/schema/custom", + "links": [ + { + "linkType": "RELATION", + "linkKind": "TRIGGER", + "target": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "PATH", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + }, { + "linkType": "END", + "from": { + "contextId": "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + }, + "tags": { + "foo1": "bar", + "foo2": "bar" + } + } + ] + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "type": "fooSubject", + "content": { + "plainField": "testValue", + "artifactId": "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427", + "referenceField": { + "id": "myChange123" + } + } + }, + "customData": { + "testValues": [ + { + "k1": "v1" + }, + { + "k2": "v2" + } + ] + }, + "customDataContentType": "application/json" +} diff --git a/pkg/api/tests-v99.1/examples/unknown_type.json b/pkg/api/tests-v99.1/examples/unknown_type.json new file mode 100644 index 0000000..30c753f --- /dev/null +++ b/pkg/api/tests-v99.1/examples/unknown_type.json @@ -0,0 +1,30 @@ +{ + "context": { + "version": "0.1.2", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject.gazumped.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "type": "fooSubject", + "content": { + "change": { + "id": "myChange123" + } + } + }, + "customData": { + "testValues": [ + { + "k1": "v1" + }, + { + "k2": "v2" + } + ] + }, + "customDataContentType": "application/json" +} diff --git a/pkg/api/tests-v99.1/examples/unparsable_context.json b/pkg/api/tests-v99.1/examples/unparsable_context.json new file mode 100644 index 0000000..6248a13 --- /dev/null +++ b/pkg/api/tests-v99.1/examples/unparsable_context.json @@ -0,0 +1,24 @@ +{ + "context": { + "version": "0.1.0"&, + "source": "/event/source/123", + "type": "dev.cdevents.artifact.packaged.0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "contentRenamed": { + "change": { + "id": "myChange123" + } + } + }, + "customData": { + "testValues": [ + {"k1": "v1"}, + {"k2": "v2"} + ] + }, + "customDataContentType": "application/json" +} \ No newline at end of file diff --git a/pkg/api/tests-v99.1/examples/unparsable_type.json b/pkg/api/tests-v99.1/examples/unparsable_type.json new file mode 100644 index 0000000..b267e40 --- /dev/null +++ b/pkg/api/tests-v99.1/examples/unparsable_type.json @@ -0,0 +1,26 @@ +{ + "context": { + "version": "0.1.1", + "id": "271069a8-fc18-44f1-b38f-9d70a1695819", + "source": "/event/source/123", + "type": "dev.cdevents.foosubject_barpredicate_0.1.0", + "timestamp": "2023-03-20T14:27:05.315384Z" + }, + "subject": { + "id": "mySubject123", + "source": "/event/source/123", + "type": "fooSubject", + "content": { + "change": { + "id": "myChange123" + } + } + }, + "customData": { + "testValues": [ + {"k1": "v1"}, + {"k2": "v2"} + ] + }, + "customDataContentType": "application/json" +} \ No newline at end of file diff --git a/pkg/api/tests-v99.1/schemas/foosubjectbarpredicate.json b/pkg/api/tests-v99.1/schemas/foosubjectbarpredicate.json new file mode 100644 index 0000000..d678264 --- /dev/null +++ b/pkg/api/tests-v99.1/schemas/foosubjectbarpredicate.json @@ -0,0 +1,155 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/99.1.0/schema/foosubject-barpredicate-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.foosubject.barpredicate.2.2.3" + ], + "default": "dev.cdevents.foosubject.barpredicate.2.2.3" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "https://cdevents.dev/0.4.1/schema/links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "fooSubject" + ], + "default": "fooSubject" + }, + "content": { + "properties": { + "plainField": { + "type": "string", + "minLength": 1 + }, + "referenceField": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string" + }, + "objectField": { + "properties": { + "required": { + "type": "string", + "minLength": 1 + }, + "optional": { + "type": "string", + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "required" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "plainField", + "referenceField" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} \ No newline at end of file diff --git a/pkg/api/types.go b/pkg/api/types.go index 6b86e2b..b68bfdb 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -26,6 +26,7 @@ import ( "strings" "time" + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" "golang.org/x/mod/semver" ) @@ -34,9 +35,20 @@ const ( CDEventsSpecVersion = "0.3.0" CDEventsSchemaURLTemplate = "https://cdevents.dev/%s/schema/%s-%s-event" CDEventsTypeRegex = "^dev\\.cdevents\\.(?P[a-z]+)\\.(?P[a-z]+)\\.(?P.*)$" + + LinkTypePath LinkType = "PATH" + LinkTypeEnd LinkType = "END" + LinkTypeRelation LinkType = "RELATION" ) -var CDEventsTypeCRegex = regexp.MustCompile(CDEventsTypeRegex) +var ( + CDEventsTypeCRegex = regexp.MustCompile(CDEventsTypeRegex) + LinkTypes = map[LinkType]interface{}{ + LinkTypePath: "", + LinkTypeEnd: "", + LinkTypeRelation: "", + } +) type BaseContextReader interface { @@ -83,10 +95,10 @@ type Context struct { // types should be prefixed with dev.cdevents. // One occurrence may have multiple events associated, as long as they have // different event types - Type CDEventType `json:"type" jsonschema:"required,minLength=1" validate:"event-type"` + Type CDEventType `json:"type" jsonschema:"required,minLength=1" validate:"required,structonly"` // Spec: https://cdevents.dev/docs/spec/#timestamp - // Description: Description: defines the time of the occurrence. When the + // Description: defines the time of the occurrence. When the // time of the occurrence is not available, the time when the event was // produced MAY be used. In case the transport layer should require a // re-transmission of the event, the timestamp SHOULD NOT be updated, i.e. @@ -94,6 +106,243 @@ type Context struct { Timestamp time.Time `json:"timestamp" jsonschema:"required"` } +type Tags map[string]interface{} + +type LinkType string + +type EmbeddedLink interface { + // GetLinkType returns the content of the jsonschema "linkType" + GetLinkType() LinkType +} + +type EmbeddedLinkWithTags interface { + EmbeddedLink + + // GetTags returns the content of the jsonschema "tags" object field + // which defines no property and allows for additional ones + GetTags() Tags + + // SetTags sets the content of the jsonschema "tags" object field + SetTags(tags Tags) +} + +type EmbeddedLinkWithTagsAndSource interface { + EmbeddedLinkWithTags + + // GetFrom returns the source of the link, in the "from" field + GetFrom() EventReference + + // SetFrom sets the source of the link, in the "from" field + SetFrom(reference EventReference) +} + +type EmbeddedLinkWithTagsAndRelation interface { + EmbeddedLinkWithTags + + // GetTarget returns the target of the link, in the "target" field + GetTarget() EventReference + + // SetTarget sets the target of the link, in the "target" field + SetTarget(reference EventReference) + + // GetLinkKind returns the link kind, in the "linkKind" field + GetLinkKind() string + + // SetLinkKind sets the kind of the link, in the "linkKind" field + SetLinkKind(kind string) +} + +// EventReference contains the ID of a linked event +type EventReference struct { + // ContextId is the ID of the linked event + ContextId string `json:"contextId" jsonschema:"required,minLength=1"` +} + +// embeddedLinkPath is private so that NewEmbeddedLinkPath must be used +// to create an object with correct defaults +type embeddedLinkPath struct { + LinkType LinkType `json:"linkType" jsonschema:"required,minLength=1" validate:"event-link-type"` + From EventReference `json:"from" jsonschema:"required,minLength=1"` + Tags Tags `json:"tags"` +} + +func (l embeddedLinkPath) GetLinkType() LinkType { + return l.LinkType +} + +func (l embeddedLinkPath) GetTags() Tags { + return l.Tags +} + +func (l embeddedLinkPath) GetFrom() EventReference { + return l.From +} + +func (l *embeddedLinkPath) SetTags(tags Tags) { + l.Tags = tags +} + +func (l *embeddedLinkPath) SetFrom(from EventReference) { + l.From = from +} + +func NewEmbeddedLinkPath() EmbeddedLinkWithTagsAndSource { + return &embeddedLinkPath{ + LinkType: LinkTypePath, + } +} + +// embeddedLinkPath is private so that NewEmbeddedLinkPath must be used +// to create an object with correct defaults +type embeddedLinkEnd struct { + LinkType LinkType `json:"linkType" jsonschema:"required,minLength=1" validate:"event-link-type"` + From EventReference `json:"from" jsonschema:"required,minLength=1"` + Tags Tags `json:"tags"` +} + +func (l embeddedLinkEnd) GetLinkType() LinkType { + return l.LinkType +} + +func (l embeddedLinkEnd) GetTags() Tags { + return l.Tags +} + +func (l embeddedLinkEnd) GetFrom() EventReference { + return l.From +} + +func (l *embeddedLinkEnd) SetTags(tags Tags) { + l.Tags = tags +} + +func (l *embeddedLinkEnd) SetFrom(from EventReference) { + l.From = from +} + +func NewEmbeddedLinkEnd() EmbeddedLinkWithTagsAndSource { + return &embeddedLinkEnd{ + LinkType: LinkTypeEnd, + } +} + +// embeddedLinkPath is private so that NewEmbeddedLinkPath must be used +// to create an object with correct defaults +type embeddedLinkRelation struct { + LinkType LinkType `json:"linkType" jsonschema:"required,minLength=1" validate:"event-link-type"` + LinkKind string `json:"linkKind" jsonschema:"required,minLength=1"` + Target EventReference `json:"target" jsonschema:"required,minLength=1"` + Tags Tags `json:"tags"` +} + +func (l embeddedLinkRelation) GetLinkType() LinkType { + return l.LinkType +} + +func (l embeddedLinkRelation) GetLinkKind() string { + return l.LinkKind +} + +func (l embeddedLinkRelation) GetTags() Tags { + return l.Tags +} + +func (l embeddedLinkRelation) GetTarget() EventReference { + return l.Target +} + +func (l *embeddedLinkRelation) SetLinkKind(linkKind string) { + l.LinkKind = linkKind +} + +func (l *embeddedLinkRelation) SetTags(tags Tags) { + l.Tags = tags +} + +func (l *embeddedLinkRelation) SetTarget(target EventReference) { + l.Target = target +} + +func NewEmbeddedLinkRelation() EmbeddedLinkWithTagsAndRelation { + return &embeddedLinkRelation{ + LinkType: LinkTypeRelation, + } +} + +type EmbeddedLinksArray []EmbeddedLinkWithTags + +func (ela *EmbeddedLinksArray) UnmarshalJSON(b []byte) error { + var rawEmbeddedLinks []*json.RawMessage + err := json.Unmarshal(b, &rawEmbeddedLinks) + if err != nil { + return err + } + + m := &struct { + LinkType LinkType `json:"linkType"` + }{} + receiver := make([]EmbeddedLinkWithTags, len(rawEmbeddedLinks)) + for index, rawEmbeddedLink := range rawEmbeddedLinks { + err = json.Unmarshal(*rawEmbeddedLink, &m) + if err != nil { + return err + } + if m.LinkType == LinkTypeEnd { + var e embeddedLinkEnd + err = json.Unmarshal(*rawEmbeddedLink, &e) + if err != nil { + return err + } + receiver[index] = &e + } else if m.LinkType == LinkTypePath { + var e embeddedLinkPath + err = json.Unmarshal(*rawEmbeddedLink, &e) + if err != nil { + return err + } + receiver[index] = &e + } else if m.LinkType == LinkTypeRelation { + var e embeddedLinkRelation + err = json.Unmarshal(*rawEmbeddedLink, &e) + if err != nil { + return err + } + receiver[index] = &e + } else { + return fmt.Errorf("unsupported link type %s found", m.LinkType) + } + } + *ela = receiver + return nil +} + +type ContextLinks struct { + // Spec: https://cdevents.dev/docs/spec/#chain_id + // Description: Identifier for a chain as defined in the links spec + // https://github.com/cdevents/spec/blob/v0.4.1/links.md + ChainId string `json:"chainId,omitempty"` + + // Spec: https://cdevents.dev/docs/spec/#links + // Description: Identifier for an event. Subsequent delivery attempts of the + // same event MAY share the same id. This attribute matches the syntax and + // semantics of the id attribute of CloudEvents: + // https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md#id + Links EmbeddedLinksArray `json:"links,omitempty" validate:"dive"` +} + +type ContextCustom struct { + // Spec: https://cdevents.dev/docs/spec/#schemauri + // Description: ink to a jsonschema schema that further refines + // the event schema as defined by CDEvents. + SchemaUri string `json:"schemaUri,omitempty"` +} + +type ContextV04 struct { + Context + ContextLinks + ContextCustom +} + type Reference struct { // Spec: https://cdevents.dev/docs/spec/#format-of-subjects @@ -211,7 +460,7 @@ type CDEventReader interface { GetSubject() Subject // The URL and content of the schema file associated to the event type - GetSchema() (string, string) + GetSchema() (string, *jsonschema.Schema, error) // The custom data attached to the event // Depends on GetCustomDataContentType() @@ -256,6 +505,32 @@ type CDEventWriter interface { SetCustomData(contentType string, data interface{}) error } +type CDEventReaderV04 interface { + CDEventReader + + // The ChainId for the event + GetChainId() string + + // The links array for the event + GetLinks() EmbeddedLinksArray + + // The custom schema URI + GetSchemaUri() string +} + +type CDEventWriterV04 interface { + CDEventWriter + + // The ChainId for the event + SetChainId(chainId string) + + // The links array for the event + SetLinks(links EmbeddedLinksArray) + + // The custom schema URI + SetSchemaUri(schema string) +} + type CDEventCustomDataEncoding string func (t CDEventCustomDataEncoding) String() string { @@ -300,6 +575,11 @@ type CDEvent interface { CDEventWriter } +type CDEventV04 interface { + CDEventReaderV04 + CDEventWriterV04 +} + // Used to implement type specific GetCustomDataRaw() func GetCustomDataRaw(contentType string, data interface{}) ([]byte, error) { switch data := data.(type) { diff --git a/pkg/api/types_test.go b/pkg/api/types_test.go index dbca3cb..b9bb644 100644 --- a/pkg/api/types_test.go +++ b/pkg/api/types_test.go @@ -22,7 +22,8 @@ import ( "encoding/json" "testing" - "github.com/cdevents/sdk-go/pkg/api" + api "github.com/cdevents/sdk-go/pkg/api" + testapi "github.com/cdevents/sdk-go/pkg/api/v990" "github.com/google/go-cmp/cmp" ) @@ -33,11 +34,11 @@ const ( var ( testObject = testType{TestData: "testValue"} testJsonString []byte - eventWithNonJsonCustomData *api.ArtifactPackagedEventV0_1_1 - eventWithInterfaceJsonCustomData *api.ArtifactPackagedEventV0_1_1 - eventWithInterfaceJsonImplicitCustomData *api.ArtifactPackagedEventV0_1_1 - eventWithJsonCustomData *api.ArtifactPackagedEventV0_1_1 - eventWithJsonImplicitCustomData *api.ArtifactPackagedEventV0_1_1 + eventWithNonJsonCustomData *testapi.FooSubjectBarPredicateEvent + eventWithInterfaceJsonCustomData *testapi.FooSubjectBarPredicateEvent + eventWithInterfaceJsonImplicitCustomData *testapi.FooSubjectBarPredicateEvent + eventWithJsonCustomData *testapi.FooSubjectBarPredicateEvent + eventWithJsonImplicitCustomData *testapi.FooSubjectBarPredicateEvent ) func init() { @@ -45,23 +46,23 @@ func init() { testJsonString, err = json.Marshal(testObject) panicOnError(err) - eventWithNonJsonCustomData, _ = api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + eventWithNonJsonCustomData, _ = testapi.NewFooSubjectBarPredicateEvent() eventWithNonJsonCustomData.CustomDataContentType = "application/xml" eventWithNonJsonCustomData.CustomData = []byte(testXmlString) - eventWithJsonCustomData, _ = api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + eventWithJsonCustomData, _ = testapi.NewFooSubjectBarPredicateEvent() eventWithJsonCustomData.CustomDataContentType = "application/json" eventWithJsonCustomData.CustomData = testJsonString - eventWithJsonImplicitCustomData, _ = api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + eventWithJsonImplicitCustomData, _ = testapi.NewFooSubjectBarPredicateEvent() eventWithJsonImplicitCustomData.CustomDataContentType = "" eventWithJsonImplicitCustomData.CustomData = testJsonString - eventWithInterfaceJsonCustomData, _ = api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + eventWithInterfaceJsonCustomData, _ = testapi.NewFooSubjectBarPredicateEvent() eventWithInterfaceJsonCustomData.CustomDataContentType = "application/json" eventWithInterfaceJsonCustomData.CustomData = testObject - eventWithInterfaceJsonImplicitCustomData, _ = api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + eventWithInterfaceJsonImplicitCustomData, _ = testapi.NewFooSubjectBarPredicateEvent() eventWithInterfaceJsonImplicitCustomData.CustomDataContentType = "" eventWithInterfaceJsonImplicitCustomData.CustomData = testObject } @@ -192,7 +193,7 @@ func TestSetCustomData(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - e, _ := api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + e, _ := testapi.NewFooSubjectBarPredicateEvent() err := e.SetCustomData(tc.contentType, tc.data) if err != nil { t.Fatalf("expected to set the custom data, but got %v", err) @@ -206,7 +207,7 @@ func TestSetCustomData(t *testing.T) { } func TestSetCustomDataInvalid(t *testing.T) { - e, _ := api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + e, _ := testapi.NewFooSubjectBarPredicateEvent() err := e.SetCustomData("application/xml", testType{TestData: "testValue"}) if err == nil { t.Fatalf("did not expect this to work, but it did") @@ -249,7 +250,7 @@ func TestGetCustomData(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - e, _ := api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + e, _ := testapi.NewFooSubjectBarPredicateEvent() err := e.SetCustomData(tc.contentType, tc.data) if err != nil { t.Fatalf("expected to set the custom data, but got %v", err) @@ -267,7 +268,7 @@ func TestGetCustomData(t *testing.T) { } func TestGetCustomDataInvalidJson(t *testing.T) { - e, _ := api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + e, _ := testapi.NewFooSubjectBarPredicateEvent() data := testType{TestData: "testValue"} dataBytes, err := json.Marshal(data) if err != nil { @@ -284,7 +285,7 @@ func TestGetCustomDataInvalidJson(t *testing.T) { } func TestGetCustomDataXmlNotBytes(t *testing.T) { - e, _ := api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + e, _ := testapi.NewFooSubjectBarPredicateEvent() data := testType{TestData: "testValue"} // Set using "application/json", else it won't be allowed err := e.SetCustomData("application/json", data) @@ -331,7 +332,7 @@ func TestGetCustomDataRaw(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - e, _ := api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + e, _ := testapi.NewFooSubjectBarPredicateEvent() err := e.SetCustomData(tc.contentType, tc.data) if err != nil { t.Fatalf("expected to set the custom data, but got %v", err) @@ -349,7 +350,7 @@ func TestGetCustomDataRaw(t *testing.T) { } func TestGetCustomDataRawXmlNotBytes(t *testing.T) { - e, _ := api.NewArtifactPackagedEventV0_1_1(testSpecVersion) + e, _ := testapi.NewFooSubjectBarPredicateEvent() data := testType{TestData: "testValue"} // Set using "application/json", else it won't be allowed err := e.SetCustomData("application/json", data) diff --git a/pkg/api/v03/docs.go b/pkg/api/v03/docs.go index 3d35c7a..5ae4183 100644 --- a/pkg/api/v03/docs.go +++ b/pkg/api/v03/docs.go @@ -28,245 +28,392 @@ import "github.com/cdevents/sdk-go/pkg/api" var SpecVersion = "0.3.0" type ArtifactPackagedEvent = api.ArtifactPackagedEventV0_1_1 +type ArtifactPackagedSubject = api.ArtifactPackagedSubjectV0_1_1 func NewArtifactPackagedEvent() (*ArtifactPackagedEvent, error) { return api.NewArtifactPackagedEventV0_1_1(SpecVersion) } +var ArtifactPackagedEventType = api.ArtifactPackagedEventTypeV0_1_1 + type ArtifactPublishedEvent = api.ArtifactPublishedEventV0_1_1 +type ArtifactPublishedSubject = api.ArtifactPublishedSubjectV0_1_1 func NewArtifactPublishedEvent() (*ArtifactPublishedEvent, error) { return api.NewArtifactPublishedEventV0_1_1(SpecVersion) } +var ArtifactPublishedEventType = api.ArtifactPublishedEventTypeV0_1_1 + type ArtifactSignedEvent = api.ArtifactSignedEventV0_1_0 +type ArtifactSignedSubject = api.ArtifactSignedSubjectV0_1_0 func NewArtifactSignedEvent() (*ArtifactSignedEvent, error) { return api.NewArtifactSignedEventV0_1_0(SpecVersion) } +var ArtifactSignedEventType = api.ArtifactSignedEventTypeV0_1_0 + type BranchCreatedEvent = api.BranchCreatedEventV0_1_2 +type BranchCreatedSubject = api.BranchCreatedSubjectV0_1_2 func NewBranchCreatedEvent() (*BranchCreatedEvent, error) { return api.NewBranchCreatedEventV0_1_2(SpecVersion) } +var BranchCreatedEventType = api.BranchCreatedEventTypeV0_1_2 + type BranchDeletedEvent = api.BranchDeletedEventV0_1_2 +type BranchDeletedSubject = api.BranchDeletedSubjectV0_1_2 func NewBranchDeletedEvent() (*BranchDeletedEvent, error) { return api.NewBranchDeletedEventV0_1_2(SpecVersion) } +var BranchDeletedEventType = api.BranchDeletedEventTypeV0_1_2 + type BuildFinishedEvent = api.BuildFinishedEventV0_1_1 +type BuildFinishedSubject = api.BuildFinishedSubjectV0_1_1 func NewBuildFinishedEvent() (*BuildFinishedEvent, error) { return api.NewBuildFinishedEventV0_1_1(SpecVersion) } +var BuildFinishedEventType = api.BuildFinishedEventTypeV0_1_1 + type BuildQueuedEvent = api.BuildQueuedEventV0_1_1 +type BuildQueuedSubject = api.BuildQueuedSubjectV0_1_1 func NewBuildQueuedEvent() (*BuildQueuedEvent, error) { return api.NewBuildQueuedEventV0_1_1(SpecVersion) } +var BuildQueuedEventType = api.BuildQueuedEventTypeV0_1_1 + type BuildStartedEvent = api.BuildStartedEventV0_1_1 +type BuildStartedSubject = api.BuildStartedSubjectV0_1_1 func NewBuildStartedEvent() (*BuildStartedEvent, error) { return api.NewBuildStartedEventV0_1_1(SpecVersion) } +var BuildStartedEventType = api.BuildStartedEventTypeV0_1_1 + type ChangeAbandonedEvent = api.ChangeAbandonedEventV0_1_2 +type ChangeAbandonedSubject = api.ChangeAbandonedSubjectV0_1_2 func NewChangeAbandonedEvent() (*ChangeAbandonedEvent, error) { return api.NewChangeAbandonedEventV0_1_2(SpecVersion) } +var ChangeAbandonedEventType = api.ChangeAbandonedEventTypeV0_1_2 + type ChangeCreatedEvent = api.ChangeCreatedEventV0_1_2 +type ChangeCreatedSubject = api.ChangeCreatedSubjectV0_1_2 func NewChangeCreatedEvent() (*ChangeCreatedEvent, error) { return api.NewChangeCreatedEventV0_1_2(SpecVersion) } +var ChangeCreatedEventType = api.ChangeCreatedEventTypeV0_1_2 + type ChangeMergedEvent = api.ChangeMergedEventV0_1_2 +type ChangeMergedSubject = api.ChangeMergedSubjectV0_1_2 func NewChangeMergedEvent() (*ChangeMergedEvent, error) { return api.NewChangeMergedEventV0_1_2(SpecVersion) } +var ChangeMergedEventType = api.ChangeMergedEventTypeV0_1_2 + type ChangeReviewedEvent = api.ChangeReviewedEventV0_1_2 +type ChangeReviewedSubject = api.ChangeReviewedSubjectV0_1_2 func NewChangeReviewedEvent() (*ChangeReviewedEvent, error) { return api.NewChangeReviewedEventV0_1_2(SpecVersion) } +var ChangeReviewedEventType = api.ChangeReviewedEventTypeV0_1_2 + type ChangeUpdatedEvent = api.ChangeUpdatedEventV0_1_2 +type ChangeUpdatedSubject = api.ChangeUpdatedSubjectV0_1_2 func NewChangeUpdatedEvent() (*ChangeUpdatedEvent, error) { return api.NewChangeUpdatedEventV0_1_2(SpecVersion) } +var ChangeUpdatedEventType = api.ChangeUpdatedEventTypeV0_1_2 + type EnvironmentCreatedEvent = api.EnvironmentCreatedEventV0_1_1 +type EnvironmentCreatedSubject = api.EnvironmentCreatedSubjectV0_1_1 func NewEnvironmentCreatedEvent() (*EnvironmentCreatedEvent, error) { return api.NewEnvironmentCreatedEventV0_1_1(SpecVersion) } +var EnvironmentCreatedEventType = api.EnvironmentCreatedEventTypeV0_1_1 + type EnvironmentDeletedEvent = api.EnvironmentDeletedEventV0_1_1 +type EnvironmentDeletedSubject = api.EnvironmentDeletedSubjectV0_1_1 func NewEnvironmentDeletedEvent() (*EnvironmentDeletedEvent, error) { return api.NewEnvironmentDeletedEventV0_1_1(SpecVersion) } +var EnvironmentDeletedEventType = api.EnvironmentDeletedEventTypeV0_1_1 + type EnvironmentModifiedEvent = api.EnvironmentModifiedEventV0_1_1 +type EnvironmentModifiedSubject = api.EnvironmentModifiedSubjectV0_1_1 func NewEnvironmentModifiedEvent() (*EnvironmentModifiedEvent, error) { return api.NewEnvironmentModifiedEventV0_1_1(SpecVersion) } +var EnvironmentModifiedEventType = api.EnvironmentModifiedEventTypeV0_1_1 + type IncidentDetectedEvent = api.IncidentDetectedEventV0_1_0 +type IncidentDetectedSubject = api.IncidentDetectedSubjectV0_1_0 func NewIncidentDetectedEvent() (*IncidentDetectedEvent, error) { return api.NewIncidentDetectedEventV0_1_0(SpecVersion) } +var IncidentDetectedEventType = api.IncidentDetectedEventTypeV0_1_0 + type IncidentReportedEvent = api.IncidentReportedEventV0_1_0 +type IncidentReportedSubject = api.IncidentReportedSubjectV0_1_0 func NewIncidentReportedEvent() (*IncidentReportedEvent, error) { return api.NewIncidentReportedEventV0_1_0(SpecVersion) } +var IncidentReportedEventType = api.IncidentReportedEventTypeV0_1_0 + type IncidentResolvedEvent = api.IncidentResolvedEventV0_1_0 +type IncidentResolvedSubject = api.IncidentResolvedSubjectV0_1_0 func NewIncidentResolvedEvent() (*IncidentResolvedEvent, error) { return api.NewIncidentResolvedEventV0_1_0(SpecVersion) } +var IncidentResolvedEventType = api.IncidentResolvedEventTypeV0_1_0 + type PipelineRunFinishedEvent = api.PipelineRunFinishedEventV0_1_1 +type PipelineRunFinishedSubject = api.PipelineRunFinishedSubjectV0_1_1 func NewPipelineRunFinishedEvent() (*PipelineRunFinishedEvent, error) { return api.NewPipelineRunFinishedEventV0_1_1(SpecVersion) } +var PipelineRunFinishedEventType = api.PipelineRunFinishedEventTypeV0_1_1 + type PipelineRunQueuedEvent = api.PipelineRunQueuedEventV0_1_1 +type PipelineRunQueuedSubject = api.PipelineRunQueuedSubjectV0_1_1 func NewPipelineRunQueuedEvent() (*PipelineRunQueuedEvent, error) { return api.NewPipelineRunQueuedEventV0_1_1(SpecVersion) } +var PipelineRunQueuedEventType = api.PipelineRunQueuedEventTypeV0_1_1 + type PipelineRunStartedEvent = api.PipelineRunStartedEventV0_1_1 +type PipelineRunStartedSubject = api.PipelineRunStartedSubjectV0_1_1 func NewPipelineRunStartedEvent() (*PipelineRunStartedEvent, error) { return api.NewPipelineRunStartedEventV0_1_1(SpecVersion) } +var PipelineRunStartedEventType = api.PipelineRunStartedEventTypeV0_1_1 + type RepositoryCreatedEvent = api.RepositoryCreatedEventV0_1_1 +type RepositoryCreatedSubject = api.RepositoryCreatedSubjectV0_1_1 func NewRepositoryCreatedEvent() (*RepositoryCreatedEvent, error) { return api.NewRepositoryCreatedEventV0_1_1(SpecVersion) } +var RepositoryCreatedEventType = api.RepositoryCreatedEventTypeV0_1_1 + type RepositoryDeletedEvent = api.RepositoryDeletedEventV0_1_1 +type RepositoryDeletedSubject = api.RepositoryDeletedSubjectV0_1_1 func NewRepositoryDeletedEvent() (*RepositoryDeletedEvent, error) { return api.NewRepositoryDeletedEventV0_1_1(SpecVersion) } +var RepositoryDeletedEventType = api.RepositoryDeletedEventTypeV0_1_1 + type RepositoryModifiedEvent = api.RepositoryModifiedEventV0_1_1 +type RepositoryModifiedSubject = api.RepositoryModifiedSubjectV0_1_1 func NewRepositoryModifiedEvent() (*RepositoryModifiedEvent, error) { return api.NewRepositoryModifiedEventV0_1_1(SpecVersion) } +var RepositoryModifiedEventType = api.RepositoryModifiedEventTypeV0_1_1 + type ServiceDeployedEvent = api.ServiceDeployedEventV0_1_1 +type ServiceDeployedSubject = api.ServiceDeployedSubjectV0_1_1 func NewServiceDeployedEvent() (*ServiceDeployedEvent, error) { return api.NewServiceDeployedEventV0_1_1(SpecVersion) } +var ServiceDeployedEventType = api.ServiceDeployedEventTypeV0_1_1 + type ServicePublishedEvent = api.ServicePublishedEventV0_1_1 +type ServicePublishedSubject = api.ServicePublishedSubjectV0_1_1 func NewServicePublishedEvent() (*ServicePublishedEvent, error) { return api.NewServicePublishedEventV0_1_1(SpecVersion) } +var ServicePublishedEventType = api.ServicePublishedEventTypeV0_1_1 + type ServiceRemovedEvent = api.ServiceRemovedEventV0_1_1 +type ServiceRemovedSubject = api.ServiceRemovedSubjectV0_1_1 func NewServiceRemovedEvent() (*ServiceRemovedEvent, error) { return api.NewServiceRemovedEventV0_1_1(SpecVersion) } +var ServiceRemovedEventType = api.ServiceRemovedEventTypeV0_1_1 + type ServiceRolledbackEvent = api.ServiceRolledbackEventV0_1_1 +type ServiceRolledbackSubject = api.ServiceRolledbackSubjectV0_1_1 func NewServiceRolledbackEvent() (*ServiceRolledbackEvent, error) { return api.NewServiceRolledbackEventV0_1_1(SpecVersion) } +var ServiceRolledbackEventType = api.ServiceRolledbackEventTypeV0_1_1 + type ServiceUpgradedEvent = api.ServiceUpgradedEventV0_1_1 +type ServiceUpgradedSubject = api.ServiceUpgradedSubjectV0_1_1 func NewServiceUpgradedEvent() (*ServiceUpgradedEvent, error) { return api.NewServiceUpgradedEventV0_1_1(SpecVersion) } +var ServiceUpgradedEventType = api.ServiceUpgradedEventTypeV0_1_1 + type TaskRunFinishedEvent = api.TaskRunFinishedEventV0_1_1 +type TaskRunFinishedSubject = api.TaskRunFinishedSubjectV0_1_1 func NewTaskRunFinishedEvent() (*TaskRunFinishedEvent, error) { return api.NewTaskRunFinishedEventV0_1_1(SpecVersion) } +var TaskRunFinishedEventType = api.TaskRunFinishedEventTypeV0_1_1 + type TaskRunStartedEvent = api.TaskRunStartedEventV0_1_1 +type TaskRunStartedSubject = api.TaskRunStartedSubjectV0_1_1 func NewTaskRunStartedEvent() (*TaskRunStartedEvent, error) { return api.NewTaskRunStartedEventV0_1_1(SpecVersion) } +var TaskRunStartedEventType = api.TaskRunStartedEventTypeV0_1_1 + type TestCaseRunFinishedEvent = api.TestCaseRunFinishedEventV0_1_0 +type TestCaseRunFinishedSubject = api.TestCaseRunFinishedSubjectV0_1_0 + +// TestCaseRunTestCaseRunSubjectContentTestCaseV0_1_0 holds the content of a TestCase field in the content +type TestCaseRunFinishedSubjectContentTestCase = api.TestCaseRunFinishedSubjectContentTestCaseV0_1_0 func NewTestCaseRunFinishedEvent() (*TestCaseRunFinishedEvent, error) { return api.NewTestCaseRunFinishedEventV0_1_0(SpecVersion) } +var TestCaseRunFinishedEventType = api.TestCaseRunFinishedEventTypeV0_1_0 + type TestCaseRunQueuedEvent = api.TestCaseRunQueuedEventV0_1_0 +type TestCaseRunQueuedSubject = api.TestCaseRunQueuedSubjectV0_1_0 + +// TestCaseRunTestCaseRunSubjectContentTestCaseV0_1_0 holds the content of a TestCase field in the content +type TestCaseRunQueuedSubjectContentTestCase = api.TestCaseRunQueuedSubjectContentTestCaseV0_1_0 + +// TestCaseRunTestCaseRunSubjectContentTriggerV0_1_0 holds the content of a Trigger field in the content +type TestCaseRunQueuedSubjectContentTrigger = api.TestCaseRunQueuedSubjectContentTriggerV0_1_0 func NewTestCaseRunQueuedEvent() (*TestCaseRunQueuedEvent, error) { return api.NewTestCaseRunQueuedEventV0_1_0(SpecVersion) } +var TestCaseRunQueuedEventType = api.TestCaseRunQueuedEventTypeV0_1_0 + type TestCaseRunStartedEvent = api.TestCaseRunStartedEventV0_1_0 +type TestCaseRunStartedSubject = api.TestCaseRunStartedSubjectV0_1_0 + +// TestCaseRunTestCaseRunSubjectContentTestCaseV0_1_0 holds the content of a TestCase field in the content +type TestCaseRunStartedSubjectContentTestCase = api.TestCaseRunStartedSubjectContentTestCaseV0_1_0 + +// TestCaseRunTestCaseRunSubjectContentTriggerV0_1_0 holds the content of a Trigger field in the content +type TestCaseRunStartedSubjectContentTrigger = api.TestCaseRunStartedSubjectContentTriggerV0_1_0 func NewTestCaseRunStartedEvent() (*TestCaseRunStartedEvent, error) { return api.NewTestCaseRunStartedEventV0_1_0(SpecVersion) } +var TestCaseRunStartedEventType = api.TestCaseRunStartedEventTypeV0_1_0 + type TestOutputPublishedEvent = api.TestOutputPublishedEventV0_1_0 +type TestOutputPublishedSubject = api.TestOutputPublishedSubjectV0_1_0 func NewTestOutputPublishedEvent() (*TestOutputPublishedEvent, error) { return api.NewTestOutputPublishedEventV0_1_0(SpecVersion) } +var TestOutputPublishedEventType = api.TestOutputPublishedEventTypeV0_1_0 + type TestSuiteRunFinishedEvent = api.TestSuiteRunFinishedEventV0_1_0 +type TestSuiteRunFinishedSubject = api.TestSuiteRunFinishedSubjectV0_1_0 + +// TestSuiteRunTestSuiteRunSubjectContentTestSuiteV0_1_0 holds the content of a TestSuite field in the content +type TestSuiteRunFinishedSubjectContentTestSuite = api.TestSuiteRunFinishedSubjectContentTestSuiteV0_1_0 func NewTestSuiteRunFinishedEvent() (*TestSuiteRunFinishedEvent, error) { return api.NewTestSuiteRunFinishedEventV0_1_0(SpecVersion) } +var TestSuiteRunFinishedEventType = api.TestSuiteRunFinishedEventTypeV0_1_0 + type TestSuiteRunQueuedEvent = api.TestSuiteRunQueuedEventV0_1_0 +type TestSuiteRunQueuedSubject = api.TestSuiteRunQueuedSubjectV0_1_0 + +// TestSuiteRunTestSuiteRunSubjectContentTestSuiteV0_1_0 holds the content of a TestSuite field in the content +type TestSuiteRunQueuedSubjectContentTestSuite = api.TestSuiteRunQueuedSubjectContentTestSuiteV0_1_0 + +// TestSuiteRunTestSuiteRunSubjectContentTriggerV0_1_0 holds the content of a Trigger field in the content +type TestSuiteRunQueuedSubjectContentTrigger = api.TestSuiteRunQueuedSubjectContentTriggerV0_1_0 func NewTestSuiteRunQueuedEvent() (*TestSuiteRunQueuedEvent, error) { return api.NewTestSuiteRunQueuedEventV0_1_0(SpecVersion) } +var TestSuiteRunQueuedEventType = api.TestSuiteRunQueuedEventTypeV0_1_0 + type TestSuiteRunStartedEvent = api.TestSuiteRunStartedEventV0_1_0 +type TestSuiteRunStartedSubject = api.TestSuiteRunStartedSubjectV0_1_0 + +// TestSuiteRunTestSuiteRunSubjectContentTestSuiteV0_1_0 holds the content of a TestSuite field in the content +type TestSuiteRunStartedSubjectContentTestSuite = api.TestSuiteRunStartedSubjectContentTestSuiteV0_1_0 + +// TestSuiteRunTestSuiteRunSubjectContentTriggerV0_1_0 holds the content of a Trigger field in the content +type TestSuiteRunStartedSubjectContentTrigger = api.TestSuiteRunStartedSubjectContentTriggerV0_1_0 func NewTestSuiteRunStartedEvent() (*TestSuiteRunStartedEvent, error) { return api.NewTestSuiteRunStartedEventV0_1_0(SpecVersion) } +var TestSuiteRunStartedEventType = api.TestSuiteRunStartedEventTypeV0_1_0 + // NewFromJsonBytes builds a new CDEventReader from a JSON string as []bytes // This works by unmarshalling the context first, extracting the event type and using // that to unmarshal the rest of the event into the correct object. // It assumes the context can be unmarshalled in a `Context` object. func NewFromJsonBytes(event []byte) (api.CDEvent, error) { - return api.NewFromJsonBytesContext[api.Context](event, CDEventsByUnversionedTypes) + return api.NewFromJsonBytesContext[api.CDEvent](event, CDEventsByUnversionedTypes) } // Build a new CDEventReader from a JSON string diff --git a/pkg/api/examples_v0.3_test.go b/pkg/api/v03/examples_test.go similarity index 75% rename from pkg/api/examples_v0.3_test.go rename to pkg/api/v03/examples_test.go index 604ab4f..27435da 100644 --- a/pkg/api/examples_v0.3_test.go +++ b/pkg/api/v03/examples_test.go @@ -16,10 +16,11 @@ limitations under the License. SPDX-License-Identifier: Apache-2.0 */ -package api_test +package v03_test import ( "os" + "path/filepath" "testing" "time" @@ -61,15 +62,15 @@ var ( testSignature = "MEYCIQCBT8U5ypDXWCjlNKfzTV4KH516/SK13NZSh8znnSMNkQIhAJ3XiQlc9PM1KyjITcZXHotdMB+J3NGua5T/yshmiPmp" testTestEnvironment = &api.Reference{ Id: "dev", Source: "testkube-dev-123"} - testTestCaseStarted = &api.TestCaseRunStartedSubjectContentTestCase{ + testTestCaseStarted = &apiv03.TestCaseRunStartedSubjectContentTestCase{ Id: "92834723894", Name: "Login Test", Type: "integration", Version: "1.0"} - testTestCaseFinished = &api.TestCaseRunFinishedSubjectContentTestCase{ + testTestCaseFinished = &apiv03.TestCaseRunFinishedSubjectContentTestCase{ Id: "92834723894", Name: "Login Test", Type: "integration", Version: "1.0"} - testTestCaseQueued = &api.TestCaseRunQueuedSubjectContentTestCase{ + testTestCaseQueued = &apiv03.TestCaseRunQueuedSubjectContentTestCase{ Id: "92834723894", Name: "Login Test", Type: "integration", Version: "1.0"} - testTestTriggerQueued = &api.TestCaseRunQueuedSubjectContentTrigger{ + testTestTriggerQueued = &apiv03.TestCaseRunQueuedSubjectContentTrigger{ Type: "schedule"} - testTestTriggerStarted = &api.TestCaseRunStartedSubjectContentTrigger{ + testTestTriggerStarted = &apiv03.TestCaseRunStartedSubjectContentTrigger{ Type: "schedule"} testTestOutcome = "pass" testTestOutputSubjectId = "testrunreport-12123" @@ -78,17 +79,17 @@ var ( testTestOutputOutputType = "video" testTestCaseRun = &api.Reference{Id: testTestRunId, Source: "testkube-dev-123"} testTestSuiteRunId = "myTestSuiteRun123" - testTestSuiteStarted = &api.TestSuiteRunStartedSubjectContentTestSuite{ + testTestSuiteStarted = &apiv03.TestSuiteRunStartedSubjectContentTestSuite{ Id: "92834723894", Name: "Auth TestSuite", Version: "1.0"} - testTestSuiteQueued = &api.TestSuiteRunQueuedSubjectContentTestSuite{ + testTestSuiteQueued = &apiv03.TestSuiteRunQueuedSubjectContentTestSuite{ Id: "92834723894", Name: "Auth TestSuite", Version: "1.0"} - testTestSuiteFinished = &api.TestSuiteRunFinishedSubjectContentTestSuite{ + testTestSuiteFinished = &apiv03.TestSuiteRunFinishedSubjectContentTestSuite{ Id: "92834723894", Name: "Auth TestSuite", Version: "1.0"} testTestSuiteOutcome = "fail" testTestSuiteReason = "Host 123.34.23.32 not found" testTestSuiteSeverity = "critical" - testTestSuiteTriggerQueued = &api.TestSuiteRunQueuedSubjectContentTrigger{Type: "pipeline"} - testTestSuiteTriggerStarted = &api.TestSuiteRunStartedSubjectContentTrigger{Type: "pipeline"} + testTestSuiteTriggerQueued = &apiv03.TestSuiteRunQueuedSubjectContentTrigger{Type: "pipeline"} + testTestSuiteTriggerStarted = &apiv03.TestSuiteRunStartedSubjectContentTrigger{Type: "pipeline"} examplesConsumed map[string][]byte examplesProduced map[string]api.CDEvent @@ -109,89 +110,89 @@ func init() { } } -func exampleArtifactPackagedEvent(e *api.ArtifactPackagedEventV0_1_1) { +func exampleArtifactPackagedEvent(e *apiv03.ArtifactPackagedEvent) { // Set example specific fields setContext(e, testArtifactSubjectId) e.SetSubjectChange(&api.Reference{Id: testChangeId, Source: testChangeSource}) } -func exampleArtifactPublishedEvent(e *api.ArtifactPublishedEventV0_1_1) { +func exampleArtifactPublishedEvent(e *apiv03.ArtifactPublishedEvent) { // Set example specific fields setContext(e, testArtifactSubjectId) } -func exampleArtifactSignedEvent(e *api.ArtifactSignedEventV0_1_0) { +func exampleArtifactSignedEvent(e *apiv03.ArtifactSignedEvent) { // Set example specific fields setContext(e, testArtifactSubjectId) e.SetSubjectSignature(testSignature) } -func exampleBranchCreatedEvent(e *api.BranchCreatedEventV0_1_2) { +func exampleBranchCreatedEvent(e *apiv03.BranchCreatedEvent) { // Set example specific fields e.SetSubjectRepository(testRepoReference) } -func exampleBranchDeletedEvent(e *api.BranchDeletedEventV0_1_2) { +func exampleBranchDeletedEvent(e *apiv03.BranchDeletedEvent) { // Set example specific fields e.SetSubjectRepository(testRepoReference) } -func exampleBuildFinishedEvent(e *api.BuildFinishedEventV0_1_1) { +func exampleBuildFinishedEvent(e *apiv03.BuildFinishedEvent) { // Set example specific fields e.SetSubjectArtifactId(testArtifactId) } -func exampleBuildQueuedEvent(e *api.BuildQueuedEventV0_1_1) { +func exampleBuildQueuedEvent(e *apiv03.BuildQueuedEvent) { // Set example specific fields } -func exampleBuildStartedEvent(e *api.BuildStartedEventV0_1_1) { +func exampleBuildStartedEvent(e *apiv03.BuildStartedEvent) { // Set example specific fields } -func exampleChangeAbandonedEvent(e *api.ChangeAbandonedEventV0_1_2) { +func exampleChangeAbandonedEvent(e *apiv03.ChangeAbandonedEvent) { // Set example specific fields e.SetSubjectRepository(testRepoReference) } -func exampleChangeCreatedEvent(e *api.ChangeCreatedEventV0_1_2) { +func exampleChangeCreatedEvent(e *apiv03.ChangeCreatedEvent) { // Set example specific fields e.SetSubjectRepository(testRepoReference) } -func exampleChangeMergedEvent(e *api.ChangeMergedEventV0_1_2) { +func exampleChangeMergedEvent(e *apiv03.ChangeMergedEvent) { // Set example specific fields e.SetSubjectRepository(testRepoReference) } -func exampleChangeReviewedEvent(e *api.ChangeReviewedEventV0_1_2) { +func exampleChangeReviewedEvent(e *apiv03.ChangeReviewedEvent) { // Set example specific fields e.SetSubjectRepository(testRepoReference) } -func exampleChangeUpdatedEvent(e *api.ChangeUpdatedEventV0_1_2) { +func exampleChangeUpdatedEvent(e *apiv03.ChangeUpdatedEvent) { // Set example specific fields e.SetSubjectRepository(testRepoReference) } -func exampleEnvironmentCreatedEvent(e *api.EnvironmentCreatedEventV0_1_1) { +func exampleEnvironmentCreatedEvent(e *apiv03.EnvironmentCreatedEvent) { // Set example specific fields e.SetSubjectName(testEnvironmentName) e.SetSubjectUrl(testEnvironmentUrl) } -func exampleEnvironmentDeletedEvent(e *api.EnvironmentDeletedEventV0_1_1) { +func exampleEnvironmentDeletedEvent(e *apiv03.EnvironmentDeletedEvent) { // Set example specific fields e.SetSubjectName(testEnvironmentName) } -func exampleEnvironmentModifiedEvent(e *api.EnvironmentModifiedEventV0_1_1) { +func exampleEnvironmentModifiedEvent(e *apiv03.EnvironmentModifiedEvent) { // Set example specific fields e.SetSubjectName(testEnvironmentName) e.SetSubjectUrl(testEnvironmentUrl) } -func exampleIncidentDetectedEvent(e *api.IncidentDetectedEventV0_1_0) { +func exampleIncidentDetectedEvent(e *apiv03.IncidentDetectedEvent) { // Set example specific fields e.SetSubjectId(testIncidentSubjectId) e.SetSource(testIncidentSource) @@ -202,7 +203,7 @@ func exampleIncidentDetectedEvent(e *api.IncidentDetectedEventV0_1_0) { e.SetSubjectDescription("Response time above threshold of 100ms") } -func exampleIncidentReportedEvent(e *api.IncidentReportedEventV0_1_0) { +func exampleIncidentReportedEvent(e *apiv03.IncidentReportedEvent) { // Set example specific fields e.SetSubjectId(testIncidentSubjectId) e.SetSource(testIncidentSource) @@ -214,7 +215,7 @@ func exampleIncidentReportedEvent(e *api.IncidentReportedEventV0_1_0) { e.SetSubjectTicketURI("https://my-issues.example/incidents/ticket-345") } -func exampleIncidentResolvedEvent(e *api.IncidentResolvedEventV0_1_0) { +func exampleIncidentResolvedEvent(e *apiv03.IncidentResolvedEvent) { // Set example specific fields e.SetSubjectId(testIncidentSubjectId) e.SetSource(testIncidentSource) @@ -225,7 +226,7 @@ func exampleIncidentResolvedEvent(e *api.IncidentResolvedEventV0_1_0) { e.SetSubjectDescription("Response time restored below 100ms") } -func examplePipelineRunFinishedEvent(e *api.PipelineRunFinishedEventV0_1_1) { +func examplePipelineRunFinishedEvent(e *apiv03.PipelineRunFinishedEvent) { // Set example specific fields e.SetSubjectPipelineName(testPipeline) e.SetSubjectUrl(testSubjecturl) @@ -233,19 +234,19 @@ func examplePipelineRunFinishedEvent(e *api.PipelineRunFinishedEventV0_1_1) { e.SetSubjectErrors(testPipelineErrors) } -func examplePipelineRunQueuedEvent(e *api.PipelineRunQueuedEventV0_1_1) { +func examplePipelineRunQueuedEvent(e *apiv03.PipelineRunQueuedEvent) { // Set example specific fields e.SetSubjectPipelineName(testPipeline) e.SetSubjectUrl(testSubjecturl) } -func examplePipelineRunStartedEvent(e *api.PipelineRunStartedEventV0_1_1) { +func examplePipelineRunStartedEvent(e *apiv03.PipelineRunStartedEvent) { // Set example specific fields e.SetSubjectPipelineName(testPipeline) e.SetSubjectUrl(testSubjecturl) } -func exampleRepositoryCreatedEvent(e *api.RepositoryCreatedEventV0_1_1) { +func exampleRepositoryCreatedEvent(e *apiv03.RepositoryCreatedEvent) { // Set example specific fields e.SetSubjectName(testRepo) e.SetSubjectOwner(testOwner) @@ -253,7 +254,7 @@ func exampleRepositoryCreatedEvent(e *api.RepositoryCreatedEventV0_1_1) { e.SetSubjectViewUrl(testViewUrl) } -func exampleRepositoryDeletedEvent(e *api.RepositoryDeletedEventV0_1_1) { +func exampleRepositoryDeletedEvent(e *apiv03.RepositoryDeletedEvent) { // Set example specific fields e.SetSubjectName(testRepo) e.SetSubjectOwner(testOwner) @@ -261,7 +262,7 @@ func exampleRepositoryDeletedEvent(e *api.RepositoryDeletedEventV0_1_1) { e.SetSubjectViewUrl(testViewUrl) } -func exampleRepositoryModifiedEvent(e *api.RepositoryModifiedEventV0_1_1) { +func exampleRepositoryModifiedEvent(e *apiv03.RepositoryModifiedEvent) { // Set example specific fields e.SetSubjectName(testRepo) e.SetSubjectOwner(testOwner) @@ -269,35 +270,35 @@ func exampleRepositoryModifiedEvent(e *api.RepositoryModifiedEventV0_1_1) { e.SetSubjectViewUrl(testViewUrl) } -func exampleServiceDeployedEvent(e *api.ServiceDeployedEventV0_1_1) { +func exampleServiceDeployedEvent(e *apiv03.ServiceDeployedEvent) { // Set example specific fields e.SetSubjectEnvironment(&api.Reference{Id: testEnvironmentId}) e.SetSubjectArtifactId(testArtifactId) } -func exampleServicePublishedEvent(e *api.ServicePublishedEventV0_1_1) { +func exampleServicePublishedEvent(e *apiv03.ServicePublishedEvent) { // Set example specific fields e.SetSubjectEnvironment(&api.Reference{Id: testEnvironmentId}) } -func exampleServiceRemovedEvent(e *api.ServiceRemovedEventV0_1_1) { +func exampleServiceRemovedEvent(e *apiv03.ServiceRemovedEvent) { // Set example specific fields e.SetSubjectEnvironment(&api.Reference{Id: testEnvironmentId}) } -func exampleServiceRolledbackEvent(e *api.ServiceRolledbackEventV0_1_1) { +func exampleServiceRolledbackEvent(e *apiv03.ServiceRolledbackEvent) { // Set example specific fields e.SetSubjectEnvironment(&api.Reference{Id: testEnvironmentId}) e.SetSubjectArtifactId(testArtifactId) } -func exampleServiceUpgradedEvent(e *api.ServiceUpgradedEventV0_1_1) { +func exampleServiceUpgradedEvent(e *apiv03.ServiceUpgradedEvent) { // Set example specific fields e.SetSubjectEnvironment(&api.Reference{Id: testEnvironmentId}) e.SetSubjectArtifactId(testArtifactId) } -func exampleTaskRunFinishedEvent(e *api.TaskRunFinishedEventV0_1_1) { +func exampleTaskRunFinishedEvent(e *apiv03.TaskRunFinishedEvent) { // Set example specific fields e.SetSubjectTaskName(testTaskName) e.SetSubjectUrl(testSubjecturl) @@ -306,14 +307,14 @@ func exampleTaskRunFinishedEvent(e *api.TaskRunFinishedEventV0_1_1) { e.SetSubjectErrors(testTaskRunErrors) } -func exampleTaskRunStartedEvent(e *api.TaskRunStartedEventV0_1_1) { +func exampleTaskRunStartedEvent(e *apiv03.TaskRunStartedEvent) { // Set example specific fields e.SetSubjectTaskName(testTaskName) e.SetSubjectUrl(testSubjecturl) e.SetSubjectPipelineRun(&api.Reference{Id: testSubjectId}) } -func exampleTestCaseRunFinishedEvent(e *api.TestCaseRunFinishedEventV0_1_0) { +func exampleTestCaseRunFinishedEvent(e *apiv03.TestCaseRunFinishedEvent) { // Set example specific fields e.SetSubjectId(testTestRunId) e.SetSubjectId(testTestRunId) @@ -322,7 +323,7 @@ func exampleTestCaseRunFinishedEvent(e *api.TestCaseRunFinishedEventV0_1_0) { e.SetSubjectOutcome(testTestOutcome) } -func exampleTestCaseRunQueuedEvent(e *api.TestCaseRunQueuedEventV0_1_0) { +func exampleTestCaseRunQueuedEvent(e *apiv03.TestCaseRunQueuedEvent) { // Set example specific fields e.SetSubjectId(testTestRunId) e.SetSubjectId(testTestRunId) @@ -331,7 +332,7 @@ func exampleTestCaseRunQueuedEvent(e *api.TestCaseRunQueuedEventV0_1_0) { e.SetSubjectTrigger(testTestTriggerQueued) } -func exampleTestCaseRunStartedEvent(e *api.TestCaseRunStartedEventV0_1_0) { +func exampleTestCaseRunStartedEvent(e *apiv03.TestCaseRunStartedEvent) { // Set example specific fields e.SetSubjectId(testTestRunId) e.SetSubjectEnvironment(testTestEnvironment) @@ -339,7 +340,7 @@ func exampleTestCaseRunStartedEvent(e *api.TestCaseRunStartedEventV0_1_0) { e.SetSubjectTrigger(testTestTriggerStarted) } -func exampleTestSuiteRunFinishedEvent(e *api.TestSuiteRunFinishedEventV0_1_0) { +func exampleTestSuiteRunFinishedEvent(e *apiv03.TestSuiteRunFinishedEvent) { // Set example specific fields e.SetSubjectId(testTestSuiteRunId) e.SetSubjectEnvironment(testTestEnvironment) @@ -349,7 +350,7 @@ func exampleTestSuiteRunFinishedEvent(e *api.TestSuiteRunFinishedEventV0_1_0) { e.SetSubjectReason(testTestSuiteReason) } -func exampleTestSuiteRunStartedEvent(e *api.TestSuiteRunStartedEventV0_1_0) { +func exampleTestSuiteRunStartedEvent(e *apiv03.TestSuiteRunStartedEvent) { // Set example specific fields e.SetSubjectId(testTestSuiteRunId) e.SetSubjectEnvironment(testTestEnvironment) @@ -357,7 +358,7 @@ func exampleTestSuiteRunStartedEvent(e *api.TestSuiteRunStartedEventV0_1_0) { e.SetSubjectTrigger(testTestSuiteTriggerStarted) } -func exampleTestSuiteRunQueuedEvent(e *api.TestSuiteRunQueuedEventV0_1_0) { +func exampleTestSuiteRunQueuedEvent(e *apiv03.TestSuiteRunQueuedEvent) { // Set example specific fields e.SetSubjectId(testTestSuiteRunId) e.SetSubjectEnvironment(testTestEnvironment) @@ -365,7 +366,7 @@ func exampleTestSuiteRunQueuedEvent(e *api.TestSuiteRunQueuedEventV0_1_0) { e.SetSubjectTrigger(testTestSuiteTriggerQueued) } -func exampleTestOutputPublishedEvent(e *api.TestOutputPublishedEventV0_1_0) { +func exampleTestOutputPublishedEvent(e *apiv03.TestOutputPublishedEvent) { // Set example specific fields e.SetSubjectId(testTestOutputSubjectId) e.SetSubjectSource(testTestOutputSubjectSource) @@ -381,7 +382,7 @@ func init() { for _, event := range apiv03.CDEventsTypes { short := event.GetType().Short() - examplesConsumed[short], err = os.ReadFile(examplesFolder + string(os.PathSeparator) + short + ".json") + examplesConsumed[short], err = os.ReadFile(filepath.Join("..", examplesFolder, short+".json")) panicOnError(err) } } diff --git a/pkg/api/factory_test.go b/pkg/api/v03/factory_test.go similarity index 99% rename from pkg/api/factory_test.go rename to pkg/api/v03/factory_test.go index a460d85..eae6f0a 100644 --- a/pkg/api/factory_test.go +++ b/pkg/api/v03/factory_test.go @@ -16,7 +16,7 @@ limitations under the License. SPDX-License-Identifier: Apache-2.0 */ -package api_test +package v03_test import ( "encoding/json" diff --git a/pkg/api/zz_examples_test.go b/pkg/api/v03/zz_examples_test.go similarity index 95% rename from pkg/api/zz_examples_test.go rename to pkg/api/v03/zz_examples_test.go index e6da6bd..d658d61 100644 --- a/pkg/api/zz_examples_test.go +++ b/pkg/api/v03/zz_examples_test.go @@ -18,7 +18,7 @@ limitations under the License. SPDX-License-Identifier: Apache-2.0 */ -package api_test +package v03_test import ( "github.com/cdevents/sdk-go/pkg/api" @@ -28,6 +28,30 @@ import ( func init() { // Create events equal to examples in the spec examplesProduced = make(map[string]api.CDEvent) + + // Set up test links + tags := api.Tags{ + "foo1": "bar", + "foo2": "bar", + } + reference := api.EventReference{ + ContextId: testContextId, + } + elr := api.NewEmbeddedLinkRelation() + elr.SetTags(tags) + elr.SetLinkKind("TRIGGER") + elr.SetTarget(reference) + elp := api.NewEmbeddedLinkPath() + elp.SetTags(tags) + elp.SetFrom(reference) + ele := api.NewEmbeddedLinkEnd() + ele.SetTags(tags) + ele.SetFrom(reference) + testLinks = api.EmbeddedLinksArray{ + elr, elp, ele, + } + + // Create events for test // ArtifactPackaged Event producer newArtifactPackaged, _ := specv03.NewArtifactPackagedEvent() setContext(newArtifactPackaged, testSubjectId) diff --git a/pkg/api/zz_factory_test.go b/pkg/api/v03/zz_factory_test.go similarity index 51% rename from pkg/api/zz_factory_test.go rename to pkg/api/v03/zz_factory_test.go index 2df50f4..ec23c73 100644 --- a/pkg/api/zz_factory_test.go +++ b/pkg/api/v03/zz_factory_test.go @@ -18,23 +18,26 @@ limitations under the License. SPDX-License-Identifier: Apache-2.0 */ -package api_test +package v03_test -import "github.com/cdevents/sdk-go/pkg/api" +import ( + "github.com/cdevents/sdk-go/pkg/api" + apiv03 "github.com/cdevents/sdk-go/pkg/api/v03" +) func init() { tests = []testNewCDEventType{} tests = append(tests, testNewCDEventType{ name: "artifact packaged", - eventType: api.ArtifactPackagedEventTypeV0_1_1.String(), - expectedEvent: &api.ArtifactPackagedEventV0_1_1{ + eventType: apiv03.ArtifactPackagedEventType.String(), + expectedEvent: &apiv03.ArtifactPackagedEvent{ Context: api.Context{ - Type: api.ArtifactPackagedEventTypeV0_1_1, + Type: apiv03.ArtifactPackagedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ArtifactPackagedSubject{ + Subject: apiv03.ArtifactPackagedSubject{ SubjectBase: api.SubjectBase{ Type: "artifact", }, @@ -43,15 +46,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "artifact published", - eventType: api.ArtifactPublishedEventTypeV0_1_1.String(), - expectedEvent: &api.ArtifactPublishedEventV0_1_1{ + eventType: apiv03.ArtifactPublishedEventType.String(), + expectedEvent: &apiv03.ArtifactPublishedEvent{ Context: api.Context{ - Type: api.ArtifactPublishedEventTypeV0_1_1, + Type: apiv03.ArtifactPublishedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ArtifactPublishedSubject{ + Subject: apiv03.ArtifactPublishedSubject{ SubjectBase: api.SubjectBase{ Type: "artifact", }, @@ -60,15 +63,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "artifact signed", - eventType: api.ArtifactSignedEventTypeV0_1_0.String(), - expectedEvent: &api.ArtifactSignedEventV0_1_0{ + eventType: apiv03.ArtifactSignedEventType.String(), + expectedEvent: &apiv03.ArtifactSignedEvent{ Context: api.Context{ - Type: api.ArtifactSignedEventTypeV0_1_0, + Type: apiv03.ArtifactSignedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ArtifactSignedSubject{ + Subject: apiv03.ArtifactSignedSubject{ SubjectBase: api.SubjectBase{ Type: "artifact", }, @@ -77,15 +80,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "branch created", - eventType: api.BranchCreatedEventTypeV0_1_2.String(), - expectedEvent: &api.BranchCreatedEventV0_1_2{ + eventType: apiv03.BranchCreatedEventType.String(), + expectedEvent: &apiv03.BranchCreatedEvent{ Context: api.Context{ - Type: api.BranchCreatedEventTypeV0_1_2, + Type: apiv03.BranchCreatedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.BranchCreatedSubject{ + Subject: apiv03.BranchCreatedSubject{ SubjectBase: api.SubjectBase{ Type: "branch", }, @@ -94,15 +97,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "branch deleted", - eventType: api.BranchDeletedEventTypeV0_1_2.String(), - expectedEvent: &api.BranchDeletedEventV0_1_2{ + eventType: apiv03.BranchDeletedEventType.String(), + expectedEvent: &apiv03.BranchDeletedEvent{ Context: api.Context{ - Type: api.BranchDeletedEventTypeV0_1_2, + Type: apiv03.BranchDeletedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.BranchDeletedSubject{ + Subject: apiv03.BranchDeletedSubject{ SubjectBase: api.SubjectBase{ Type: "branch", }, @@ -111,15 +114,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "build finished", - eventType: api.BuildFinishedEventTypeV0_1_1.String(), - expectedEvent: &api.BuildFinishedEventV0_1_1{ + eventType: apiv03.BuildFinishedEventType.String(), + expectedEvent: &apiv03.BuildFinishedEvent{ Context: api.Context{ - Type: api.BuildFinishedEventTypeV0_1_1, + Type: apiv03.BuildFinishedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.BuildFinishedSubject{ + Subject: apiv03.BuildFinishedSubject{ SubjectBase: api.SubjectBase{ Type: "build", }, @@ -128,15 +131,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "build queued", - eventType: api.BuildQueuedEventTypeV0_1_1.String(), - expectedEvent: &api.BuildQueuedEventV0_1_1{ + eventType: apiv03.BuildQueuedEventType.String(), + expectedEvent: &apiv03.BuildQueuedEvent{ Context: api.Context{ - Type: api.BuildQueuedEventTypeV0_1_1, + Type: apiv03.BuildQueuedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.BuildQueuedSubject{ + Subject: apiv03.BuildQueuedSubject{ SubjectBase: api.SubjectBase{ Type: "build", }, @@ -145,15 +148,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "build started", - eventType: api.BuildStartedEventTypeV0_1_1.String(), - expectedEvent: &api.BuildStartedEventV0_1_1{ + eventType: apiv03.BuildStartedEventType.String(), + expectedEvent: &apiv03.BuildStartedEvent{ Context: api.Context{ - Type: api.BuildStartedEventTypeV0_1_1, + Type: apiv03.BuildStartedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.BuildStartedSubject{ + Subject: apiv03.BuildStartedSubject{ SubjectBase: api.SubjectBase{ Type: "build", }, @@ -162,15 +165,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "change abandoned", - eventType: api.ChangeAbandonedEventTypeV0_1_2.String(), - expectedEvent: &api.ChangeAbandonedEventV0_1_2{ + eventType: apiv03.ChangeAbandonedEventType.String(), + expectedEvent: &apiv03.ChangeAbandonedEvent{ Context: api.Context{ - Type: api.ChangeAbandonedEventTypeV0_1_2, + Type: apiv03.ChangeAbandonedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ChangeAbandonedSubject{ + Subject: apiv03.ChangeAbandonedSubject{ SubjectBase: api.SubjectBase{ Type: "change", }, @@ -179,15 +182,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "change created", - eventType: api.ChangeCreatedEventTypeV0_1_2.String(), - expectedEvent: &api.ChangeCreatedEventV0_1_2{ + eventType: apiv03.ChangeCreatedEventType.String(), + expectedEvent: &apiv03.ChangeCreatedEvent{ Context: api.Context{ - Type: api.ChangeCreatedEventTypeV0_1_2, + Type: apiv03.ChangeCreatedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ChangeCreatedSubject{ + Subject: apiv03.ChangeCreatedSubject{ SubjectBase: api.SubjectBase{ Type: "change", }, @@ -196,15 +199,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "change merged", - eventType: api.ChangeMergedEventTypeV0_1_2.String(), - expectedEvent: &api.ChangeMergedEventV0_1_2{ + eventType: apiv03.ChangeMergedEventType.String(), + expectedEvent: &apiv03.ChangeMergedEvent{ Context: api.Context{ - Type: api.ChangeMergedEventTypeV0_1_2, + Type: apiv03.ChangeMergedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ChangeMergedSubject{ + Subject: apiv03.ChangeMergedSubject{ SubjectBase: api.SubjectBase{ Type: "change", }, @@ -213,15 +216,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "change reviewed", - eventType: api.ChangeReviewedEventTypeV0_1_2.String(), - expectedEvent: &api.ChangeReviewedEventV0_1_2{ + eventType: apiv03.ChangeReviewedEventType.String(), + expectedEvent: &apiv03.ChangeReviewedEvent{ Context: api.Context{ - Type: api.ChangeReviewedEventTypeV0_1_2, + Type: apiv03.ChangeReviewedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ChangeReviewedSubject{ + Subject: apiv03.ChangeReviewedSubject{ SubjectBase: api.SubjectBase{ Type: "change", }, @@ -230,15 +233,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "change updated", - eventType: api.ChangeUpdatedEventTypeV0_1_2.String(), - expectedEvent: &api.ChangeUpdatedEventV0_1_2{ + eventType: apiv03.ChangeUpdatedEventType.String(), + expectedEvent: &apiv03.ChangeUpdatedEvent{ Context: api.Context{ - Type: api.ChangeUpdatedEventTypeV0_1_2, + Type: apiv03.ChangeUpdatedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ChangeUpdatedSubject{ + Subject: apiv03.ChangeUpdatedSubject{ SubjectBase: api.SubjectBase{ Type: "change", }, @@ -247,15 +250,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "environment created", - eventType: api.EnvironmentCreatedEventTypeV0_1_1.String(), - expectedEvent: &api.EnvironmentCreatedEventV0_1_1{ + eventType: apiv03.EnvironmentCreatedEventType.String(), + expectedEvent: &apiv03.EnvironmentCreatedEvent{ Context: api.Context{ - Type: api.EnvironmentCreatedEventTypeV0_1_1, + Type: apiv03.EnvironmentCreatedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.EnvironmentCreatedSubject{ + Subject: apiv03.EnvironmentCreatedSubject{ SubjectBase: api.SubjectBase{ Type: "environment", }, @@ -264,15 +267,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "environment deleted", - eventType: api.EnvironmentDeletedEventTypeV0_1_1.String(), - expectedEvent: &api.EnvironmentDeletedEventV0_1_1{ + eventType: apiv03.EnvironmentDeletedEventType.String(), + expectedEvent: &apiv03.EnvironmentDeletedEvent{ Context: api.Context{ - Type: api.EnvironmentDeletedEventTypeV0_1_1, + Type: apiv03.EnvironmentDeletedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.EnvironmentDeletedSubject{ + Subject: apiv03.EnvironmentDeletedSubject{ SubjectBase: api.SubjectBase{ Type: "environment", }, @@ -281,15 +284,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "environment modified", - eventType: api.EnvironmentModifiedEventTypeV0_1_1.String(), - expectedEvent: &api.EnvironmentModifiedEventV0_1_1{ + eventType: apiv03.EnvironmentModifiedEventType.String(), + expectedEvent: &apiv03.EnvironmentModifiedEvent{ Context: api.Context{ - Type: api.EnvironmentModifiedEventTypeV0_1_1, + Type: apiv03.EnvironmentModifiedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.EnvironmentModifiedSubject{ + Subject: apiv03.EnvironmentModifiedSubject{ SubjectBase: api.SubjectBase{ Type: "environment", }, @@ -298,15 +301,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "incident detected", - eventType: api.IncidentDetectedEventTypeV0_1_0.String(), - expectedEvent: &api.IncidentDetectedEventV0_1_0{ + eventType: apiv03.IncidentDetectedEventType.String(), + expectedEvent: &apiv03.IncidentDetectedEvent{ Context: api.Context{ - Type: api.IncidentDetectedEventTypeV0_1_0, + Type: apiv03.IncidentDetectedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.IncidentDetectedSubject{ + Subject: apiv03.IncidentDetectedSubject{ SubjectBase: api.SubjectBase{ Type: "incident", }, @@ -315,15 +318,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "incident reported", - eventType: api.IncidentReportedEventTypeV0_1_0.String(), - expectedEvent: &api.IncidentReportedEventV0_1_0{ + eventType: apiv03.IncidentReportedEventType.String(), + expectedEvent: &apiv03.IncidentReportedEvent{ Context: api.Context{ - Type: api.IncidentReportedEventTypeV0_1_0, + Type: apiv03.IncidentReportedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.IncidentReportedSubject{ + Subject: apiv03.IncidentReportedSubject{ SubjectBase: api.SubjectBase{ Type: "incident", }, @@ -332,15 +335,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "incident resolved", - eventType: api.IncidentResolvedEventTypeV0_1_0.String(), - expectedEvent: &api.IncidentResolvedEventV0_1_0{ + eventType: apiv03.IncidentResolvedEventType.String(), + expectedEvent: &apiv03.IncidentResolvedEvent{ Context: api.Context{ - Type: api.IncidentResolvedEventTypeV0_1_0, + Type: apiv03.IncidentResolvedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.IncidentResolvedSubject{ + Subject: apiv03.IncidentResolvedSubject{ SubjectBase: api.SubjectBase{ Type: "incident", }, @@ -349,15 +352,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "pipelinerun finished", - eventType: api.PipelineRunFinishedEventTypeV0_1_1.String(), - expectedEvent: &api.PipelineRunFinishedEventV0_1_1{ + eventType: apiv03.PipelineRunFinishedEventType.String(), + expectedEvent: &apiv03.PipelineRunFinishedEvent{ Context: api.Context{ - Type: api.PipelineRunFinishedEventTypeV0_1_1, + Type: apiv03.PipelineRunFinishedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.PipelineRunFinishedSubject{ + Subject: apiv03.PipelineRunFinishedSubject{ SubjectBase: api.SubjectBase{ Type: "pipelineRun", }, @@ -366,15 +369,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "pipelinerun queued", - eventType: api.PipelineRunQueuedEventTypeV0_1_1.String(), - expectedEvent: &api.PipelineRunQueuedEventV0_1_1{ + eventType: apiv03.PipelineRunQueuedEventType.String(), + expectedEvent: &apiv03.PipelineRunQueuedEvent{ Context: api.Context{ - Type: api.PipelineRunQueuedEventTypeV0_1_1, + Type: apiv03.PipelineRunQueuedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.PipelineRunQueuedSubject{ + Subject: apiv03.PipelineRunQueuedSubject{ SubjectBase: api.SubjectBase{ Type: "pipelineRun", }, @@ -383,15 +386,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "pipelinerun started", - eventType: api.PipelineRunStartedEventTypeV0_1_1.String(), - expectedEvent: &api.PipelineRunStartedEventV0_1_1{ + eventType: apiv03.PipelineRunStartedEventType.String(), + expectedEvent: &apiv03.PipelineRunStartedEvent{ Context: api.Context{ - Type: api.PipelineRunStartedEventTypeV0_1_1, + Type: apiv03.PipelineRunStartedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.PipelineRunStartedSubject{ + Subject: apiv03.PipelineRunStartedSubject{ SubjectBase: api.SubjectBase{ Type: "pipelineRun", }, @@ -400,15 +403,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "repository created", - eventType: api.RepositoryCreatedEventTypeV0_1_1.String(), - expectedEvent: &api.RepositoryCreatedEventV0_1_1{ + eventType: apiv03.RepositoryCreatedEventType.String(), + expectedEvent: &apiv03.RepositoryCreatedEvent{ Context: api.Context{ - Type: api.RepositoryCreatedEventTypeV0_1_1, + Type: apiv03.RepositoryCreatedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.RepositoryCreatedSubject{ + Subject: apiv03.RepositoryCreatedSubject{ SubjectBase: api.SubjectBase{ Type: "repository", }, @@ -417,15 +420,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "repository deleted", - eventType: api.RepositoryDeletedEventTypeV0_1_1.String(), - expectedEvent: &api.RepositoryDeletedEventV0_1_1{ + eventType: apiv03.RepositoryDeletedEventType.String(), + expectedEvent: &apiv03.RepositoryDeletedEvent{ Context: api.Context{ - Type: api.RepositoryDeletedEventTypeV0_1_1, + Type: apiv03.RepositoryDeletedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.RepositoryDeletedSubject{ + Subject: apiv03.RepositoryDeletedSubject{ SubjectBase: api.SubjectBase{ Type: "repository", }, @@ -434,15 +437,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "repository modified", - eventType: api.RepositoryModifiedEventTypeV0_1_1.String(), - expectedEvent: &api.RepositoryModifiedEventV0_1_1{ + eventType: apiv03.RepositoryModifiedEventType.String(), + expectedEvent: &apiv03.RepositoryModifiedEvent{ Context: api.Context{ - Type: api.RepositoryModifiedEventTypeV0_1_1, + Type: apiv03.RepositoryModifiedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.RepositoryModifiedSubject{ + Subject: apiv03.RepositoryModifiedSubject{ SubjectBase: api.SubjectBase{ Type: "repository", }, @@ -451,15 +454,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "service deployed", - eventType: api.ServiceDeployedEventTypeV0_1_1.String(), - expectedEvent: &api.ServiceDeployedEventV0_1_1{ + eventType: apiv03.ServiceDeployedEventType.String(), + expectedEvent: &apiv03.ServiceDeployedEvent{ Context: api.Context{ - Type: api.ServiceDeployedEventTypeV0_1_1, + Type: apiv03.ServiceDeployedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ServiceDeployedSubject{ + Subject: apiv03.ServiceDeployedSubject{ SubjectBase: api.SubjectBase{ Type: "service", }, @@ -468,15 +471,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "service published", - eventType: api.ServicePublishedEventTypeV0_1_1.String(), - expectedEvent: &api.ServicePublishedEventV0_1_1{ + eventType: apiv03.ServicePublishedEventType.String(), + expectedEvent: &apiv03.ServicePublishedEvent{ Context: api.Context{ - Type: api.ServicePublishedEventTypeV0_1_1, + Type: apiv03.ServicePublishedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ServicePublishedSubject{ + Subject: apiv03.ServicePublishedSubject{ SubjectBase: api.SubjectBase{ Type: "service", }, @@ -485,15 +488,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "service removed", - eventType: api.ServiceRemovedEventTypeV0_1_1.String(), - expectedEvent: &api.ServiceRemovedEventV0_1_1{ + eventType: apiv03.ServiceRemovedEventType.String(), + expectedEvent: &apiv03.ServiceRemovedEvent{ Context: api.Context{ - Type: api.ServiceRemovedEventTypeV0_1_1, + Type: apiv03.ServiceRemovedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ServiceRemovedSubject{ + Subject: apiv03.ServiceRemovedSubject{ SubjectBase: api.SubjectBase{ Type: "service", }, @@ -502,15 +505,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "service rolledback", - eventType: api.ServiceRolledbackEventTypeV0_1_1.String(), - expectedEvent: &api.ServiceRolledbackEventV0_1_1{ + eventType: apiv03.ServiceRolledbackEventType.String(), + expectedEvent: &apiv03.ServiceRolledbackEvent{ Context: api.Context{ - Type: api.ServiceRolledbackEventTypeV0_1_1, + Type: apiv03.ServiceRolledbackEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ServiceRolledbackSubject{ + Subject: apiv03.ServiceRolledbackSubject{ SubjectBase: api.SubjectBase{ Type: "service", }, @@ -519,15 +522,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "service upgraded", - eventType: api.ServiceUpgradedEventTypeV0_1_1.String(), - expectedEvent: &api.ServiceUpgradedEventV0_1_1{ + eventType: apiv03.ServiceUpgradedEventType.String(), + expectedEvent: &apiv03.ServiceUpgradedEvent{ Context: api.Context{ - Type: api.ServiceUpgradedEventTypeV0_1_1, + Type: apiv03.ServiceUpgradedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.ServiceUpgradedSubject{ + Subject: apiv03.ServiceUpgradedSubject{ SubjectBase: api.SubjectBase{ Type: "service", }, @@ -536,15 +539,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "taskrun finished", - eventType: api.TaskRunFinishedEventTypeV0_1_1.String(), - expectedEvent: &api.TaskRunFinishedEventV0_1_1{ + eventType: apiv03.TaskRunFinishedEventType.String(), + expectedEvent: &apiv03.TaskRunFinishedEvent{ Context: api.Context{ - Type: api.TaskRunFinishedEventTypeV0_1_1, + Type: apiv03.TaskRunFinishedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.TaskRunFinishedSubject{ + Subject: apiv03.TaskRunFinishedSubject{ SubjectBase: api.SubjectBase{ Type: "taskRun", }, @@ -553,15 +556,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "taskrun started", - eventType: api.TaskRunStartedEventTypeV0_1_1.String(), - expectedEvent: &api.TaskRunStartedEventV0_1_1{ + eventType: apiv03.TaskRunStartedEventType.String(), + expectedEvent: &apiv03.TaskRunStartedEvent{ Context: api.Context{ - Type: api.TaskRunStartedEventTypeV0_1_1, + Type: apiv03.TaskRunStartedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.TaskRunStartedSubject{ + Subject: apiv03.TaskRunStartedSubject{ SubjectBase: api.SubjectBase{ Type: "taskRun", }, @@ -570,15 +573,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "testcaserun finished", - eventType: api.TestCaseRunFinishedEventTypeV0_1_0.String(), - expectedEvent: &api.TestCaseRunFinishedEventV0_1_0{ + eventType: apiv03.TestCaseRunFinishedEventType.String(), + expectedEvent: &apiv03.TestCaseRunFinishedEvent{ Context: api.Context{ - Type: api.TestCaseRunFinishedEventTypeV0_1_0, + Type: apiv03.TestCaseRunFinishedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.TestCaseRunFinishedSubject{ + Subject: apiv03.TestCaseRunFinishedSubject{ SubjectBase: api.SubjectBase{ Type: "testCaseRun", }, @@ -587,15 +590,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "testcaserun queued", - eventType: api.TestCaseRunQueuedEventTypeV0_1_0.String(), - expectedEvent: &api.TestCaseRunQueuedEventV0_1_0{ + eventType: apiv03.TestCaseRunQueuedEventType.String(), + expectedEvent: &apiv03.TestCaseRunQueuedEvent{ Context: api.Context{ - Type: api.TestCaseRunQueuedEventTypeV0_1_0, + Type: apiv03.TestCaseRunQueuedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.TestCaseRunQueuedSubject{ + Subject: apiv03.TestCaseRunQueuedSubject{ SubjectBase: api.SubjectBase{ Type: "testCaseRun", }, @@ -604,15 +607,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "testcaserun started", - eventType: api.TestCaseRunStartedEventTypeV0_1_0.String(), - expectedEvent: &api.TestCaseRunStartedEventV0_1_0{ + eventType: apiv03.TestCaseRunStartedEventType.String(), + expectedEvent: &apiv03.TestCaseRunStartedEvent{ Context: api.Context{ - Type: api.TestCaseRunStartedEventTypeV0_1_0, + Type: apiv03.TestCaseRunStartedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.TestCaseRunStartedSubject{ + Subject: apiv03.TestCaseRunStartedSubject{ SubjectBase: api.SubjectBase{ Type: "testCaseRun", }, @@ -621,15 +624,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "testoutput published", - eventType: api.TestOutputPublishedEventTypeV0_1_0.String(), - expectedEvent: &api.TestOutputPublishedEventV0_1_0{ + eventType: apiv03.TestOutputPublishedEventType.String(), + expectedEvent: &apiv03.TestOutputPublishedEvent{ Context: api.Context{ - Type: api.TestOutputPublishedEventTypeV0_1_0, + Type: apiv03.TestOutputPublishedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.TestOutputPublishedSubject{ + Subject: apiv03.TestOutputPublishedSubject{ SubjectBase: api.SubjectBase{ Type: "testOutput", }, @@ -638,15 +641,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "testsuiterun finished", - eventType: api.TestSuiteRunFinishedEventTypeV0_1_0.String(), - expectedEvent: &api.TestSuiteRunFinishedEventV0_1_0{ + eventType: apiv03.TestSuiteRunFinishedEventType.String(), + expectedEvent: &apiv03.TestSuiteRunFinishedEvent{ Context: api.Context{ - Type: api.TestSuiteRunFinishedEventTypeV0_1_0, + Type: apiv03.TestSuiteRunFinishedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.TestSuiteRunFinishedSubject{ + Subject: apiv03.TestSuiteRunFinishedSubject{ SubjectBase: api.SubjectBase{ Type: "testSuiteRun", }, @@ -655,15 +658,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "testsuiterun queued", - eventType: api.TestSuiteRunQueuedEventTypeV0_1_0.String(), - expectedEvent: &api.TestSuiteRunQueuedEventV0_1_0{ + eventType: apiv03.TestSuiteRunQueuedEventType.String(), + expectedEvent: &apiv03.TestSuiteRunQueuedEvent{ Context: api.Context{ - Type: api.TestSuiteRunQueuedEventTypeV0_1_0, + Type: apiv03.TestSuiteRunQueuedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.TestSuiteRunQueuedSubject{ + Subject: apiv03.TestSuiteRunQueuedSubject{ SubjectBase: api.SubjectBase{ Type: "testSuiteRun", }, @@ -672,15 +675,15 @@ func init() { }) tests = append(tests, testNewCDEventType{ name: "testsuiterun started", - eventType: api.TestSuiteRunStartedEventTypeV0_1_0.String(), - expectedEvent: &api.TestSuiteRunStartedEventV0_1_0{ + eventType: apiv03.TestSuiteRunStartedEventType.String(), + expectedEvent: &apiv03.TestSuiteRunStartedEvent{ Context: api.Context{ - Type: api.TestSuiteRunStartedEventTypeV0_1_0, + Type: apiv03.TestSuiteRunStartedEventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "0.3.0", }, - Subject: api.TestSuiteRunStartedSubject{ + Subject: apiv03.TestSuiteRunStartedSubject{ SubjectBase: api.SubjectBase{ Type: "testSuiteRun", }, diff --git a/pkg/api/v03/zz_shared_test.go b/pkg/api/v03/zz_shared_test.go new file mode 100644 index 0000000..22cf47c --- /dev/null +++ b/pkg/api/v03/zz_shared_test.go @@ -0,0 +1,92 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package v03_test + +import "github.com/cdevents/sdk-go/pkg/api" + +func panicOnError(err error) { + if err != nil { + panic(err.Error()) + } +} + +type testData struct { + TestValues []map[string]string `json:"testValues"` +} + +var ( + // Examples Data + testSource = "/event/source/123" + testSubjectId = "mySubject123" + testValue = "testValue" + testArtifactId = "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" + testDataJson = testData{TestValues: []map[string]string{{"k1": "v1"}, {"k2": "v2"}}} + testDataJsonUnmarshalled = map[string]any{ + "testValues": []any{map[string]any{"k1": string("v1")}, map[string]any{"k2": string("v2")}}, + } + testDataXml = []byte("testData") + testChangeId = "myChange123" + + // V04+ Examples Data + testChainId = "4c8cb7dd-3448-41de-8768-eec704e2829b" + testLinks api.EmbeddedLinksArray + testContextId = "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + testSchemaUri = "https://myorg.com/schema/custom" +) + +func init() { + // Set up test links + tags := api.Tags{ + "foo1": "bar", + "foo2": "bar", + } + reference := api.EventReference{ + ContextId: testContextId, + } + elr := api.NewEmbeddedLinkRelation() + elr.SetTags(tags) + elr.SetLinkKind("TRIGGER") + elr.SetTarget(reference) + elp := api.NewEmbeddedLinkPath() + elp.SetTags(tags) + elp.SetFrom(reference) + ele := api.NewEmbeddedLinkEnd() + ele.SetTags(tags) + ele.SetFrom(reference) + testLinks = api.EmbeddedLinksArray{ + elr, elp, ele, + } +} + +func setContext(event api.CDEventWriter, subjectId string) { + event.SetSource(testSource) + event.SetSubjectId(subjectId) +} + +func setContextV04(event api.CDEventWriterV04, chainId, schemaUri bool) { + if chainId { + event.SetChainId(testChainId) + } + if schemaUri { + event.SetSchemaUri(testSchemaUri) + } + event.SetLinks(testLinks) +} diff --git a/pkg/api/v04/conformance_test.go b/pkg/api/v04/conformance_test.go new file mode 100644 index 0000000..b1346b9 --- /dev/null +++ b/pkg/api/v04/conformance_test.go @@ -0,0 +1,552 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package v04_test + +import ( + "os" + "path/filepath" + "testing" + "time" + + "github.com/cdevents/sdk-go/pkg/api" + apiv04 "github.com/cdevents/sdk-go/pkg/api/v04" + "github.com/google/go-cmp/cmp" + "github.com/google/uuid" +) + +const examplesFolder = "spec-v0.4/conformance" + +var ( + // Examples Data + testArtifactSubjectId = "pkg:golang/mygit.com/myorg/myapp@234fd47e07d1004f0aed9c" + testChangeSource = "my-git.example/an-org/a-repo" + testPipeline = "myPipeline" + testSubjecturl = "https://www.example.com/mySubject123" + testPipelineOutcome = "failure" + testPipelineErrors = "Something went wrong\nWith some more details" + testTaskName = "myTask" + testTaskOutcome = "failure" + testTaskRunErrors = "Something went wrong\nWith some more details" + testRepo = "TestRepo" + testOwner = "TestOrg" + testUrl = "https://example.org/TestOrg/TestRepo" + testViewUrl = "https://example.org/view/TestOrg/TestRepo" + testEnvironmentId = "test123" + testEnvironmentName = "testEnv" + testEnvironmentUrl = "https://example.org/testEnv" + testRepoReference = &api.Reference{ + Id: "TestRepo/TestOrg", Source: "https://example.org"} + testIncidentSubjectId = "incident-123" + testIncidentSource = "/monitoring/prod1" + testEnvironmentReference = &api.Reference{ + Id: "prod1", Source: "/iaas/geo1"} + testServiceReference = &api.Reference{ + Id: "myApp", Source: "/clusterA/namespaceB"} + testTestRunId = "myTestCaseRun123" + testSignature = "MEYCIQCBT8U5ypDXWCjlNKfzTV4KH516/SK13NZSh8znnSMNkQIhAJ3XiQlc9PM1KyjITcZXHotdMB+J3NGua5T/yshmiPmp" + testTestEnvironment = &api.Reference{ + Id: "dev", Source: "testkube-dev-123"} + testTestCaseStarted = &apiv04.TestCaseRunStartedSubjectContentTestCase{ + Id: "92834723894", Name: "Login Test", Type: "integration", Version: "1.0"} + testTestCaseFinished = &apiv04.TestCaseRunFinishedSubjectContentTestCase{ + Id: "92834723894", Name: "Login Test", Type: "integration", Version: "1.0"} + testTestCaseQueued = &apiv04.TestCaseRunQueuedSubjectContentTestCase{ + Id: "92834723894", Name: "Login Test", Type: "integration", Version: "1.0"} + testTestTriggerQueued = &apiv04.TestCaseRunQueuedSubjectContentTrigger{ + Type: "schedule"} + testTestTriggerStarted = &apiv04.TestCaseRunStartedSubjectContentTrigger{ + Type: "schedule"} + testTestOutcome = "pass" + testTestOutputSubjectId = "testrunreport-12123" + testTestOutputSubjectSource = "/event/source/testrunreport-12123" + testTestOutputFormat = "video/quicktime" + testTestOutputOutputType = "video" + testTestCaseRun = &api.Reference{Id: testTestRunId, Source: "testkube-dev-123"} + testTestSuiteRunId = "myTestSuiteRun123" + testTestSuiteStarted = &apiv04.TestSuiteRunStartedSubjectContentTestSuite{ + Id: "92834723894", Name: "Auth TestSuite", Version: "1.0"} + testTestSuiteQueued = &apiv04.TestSuiteRunQueuedSubjectContentTestSuite{ + Id: "92834723894", Name: "Auth TestSuite", Version: "1.0"} + testTestSuiteFinished = &apiv04.TestSuiteRunFinishedSubjectContentTestSuite{ + Id: "92834723894", Name: "Auth TestSuite", Version: "1.0"} + testTestSuiteOutcome = "fail" + testTestSuiteReason = "Host 123.34.23.32 not found" + testTestSuiteSeverity = "critical" + testTestSuiteTriggerQueued = &apiv04.TestSuiteRunQueuedSubjectContentTrigger{Type: "pipeline"} + testTestSuiteTriggerStarted = &apiv04.TestSuiteRunStartedSubjectContentTrigger{Type: "pipeline"} + testSubjectUser = "mybot-myapp" + testSbomUri = "https://sbom.repo/myorg/234fd47e07d1004f0aed9c.sbom" + testChangeDescription = "This PR address a bug from a recent PR" + testTicketId = "ticket-123" + testTicketSource = "/ticketing/system" + testTicketAssignees = []string{"Bob"} + testTicketCreator = "Alice" + testTicketGroup = "security" + testTicketLabels = []string{"bug"} + testTicketMilestone = "123" + testTicketPriority = "high" + testTicketResolution = "completed" + testTicketSummary = "New CVE-123 detected" + testTicketType = "task" + testTicketUpdatedBy = "Bob" + testTicketUri = "https://example.issues.com/ticket123" + + examplesConsumed map[string][]byte + examplesProduced map[string]api.CDEventV04 + err error +) + +func init() { + // Get the time once + t, _ := time.Parse(time.RFC3339Nano, "2023-03-20T14:27:05.315384Z") + timeNow = func() time.Time { + return t + } + + // Set the UUID to a fixed one + u, _ := uuid.Parse("271069a8-fc18-44f1-b38f-9d70a1695819") + uuidNewRandom = func() (uuid.UUID, error) { + return u, nil + } +} + +func exampleArtifactPackagedEvent(e *apiv04.ArtifactPackagedEvent) { + // Set example specific fields + setContext(e, testArtifactSubjectId) + e.SetSubjectChange(&api.Reference{Id: testChangeId, Source: testChangeSource}) + e.SetSubjectSbom(&api.ArtifactPackagedSubjectContentSbomV0_2_0{ + Uri: testSbomUri, + }) +} + +func exampleArtifactPublishedEvent(e *apiv04.ArtifactPublishedEvent) { + // Set example specific fields + setContext(e, testArtifactSubjectId) + e.SetSubjectUser(testSubjectUser) + e.SetSubjectSbom(&api.ArtifactPublishedSubjectContentSbomV0_2_0{ + Uri: testSbomUri, + }) +} + +func exampleArtifactSignedEvent(e *apiv04.ArtifactSignedEvent) { + // Set example specific fields + setContext(e, testArtifactSubjectId) + e.SetSubjectSignature(testSignature) +} + +func exampleArtifactDeletedEvent(e *apiv04.ArtifactDeletedEvent) { + // Set example specific fields + setContext(e, testArtifactSubjectId) + e.SetSubjectUser(testSubjectUser) + e.SetChainId("") +} + +func exampleArtifactDownloadedEvent(e *apiv04.ArtifactDownloadedEvent) { + // Set example specific fields + setContext(e, testArtifactSubjectId) + e.SetSubjectUser(testSubjectUser) + e.SetChainId("") +} + +func exampleBranchCreatedEvent(e *apiv04.BranchCreatedEvent) { + // Set example specific fields + e.SetSubjectRepository(testRepoReference) +} + +func exampleBranchDeletedEvent(e *apiv04.BranchDeletedEvent) { + // Set example specific fields + e.SetSubjectRepository(testRepoReference) +} + +func exampleBuildFinishedEvent(e *apiv04.BuildFinishedEvent) { + // Set example specific fields + e.SetSubjectArtifactId(testArtifactId) +} + +func exampleBuildQueuedEvent(e *apiv04.BuildQueuedEvent) { + // Set example specific fields +} + +func exampleBuildStartedEvent(e *apiv04.BuildStartedEvent) { + // Set example specific fields +} + +func exampleChangeAbandonedEvent(e *apiv04.ChangeAbandonedEvent) { + // Set example specific fields + e.SetSubjectRepository(testRepoReference) +} + +func exampleChangeCreatedEvent(e *apiv04.ChangeCreatedEvent) { + // Set example specific fields + e.SetSubjectRepository(testRepoReference) + e.SetSubjectDescription(testChangeDescription) +} + +func exampleChangeMergedEvent(e *apiv04.ChangeMergedEvent) { + // Set example specific fields + e.SetSubjectRepository(testRepoReference) +} + +func exampleChangeReviewedEvent(e *apiv04.ChangeReviewedEvent) { + // Set example specific fields + e.SetSubjectRepository(testRepoReference) +} + +func exampleChangeUpdatedEvent(e *apiv04.ChangeUpdatedEvent) { + // Set example specific fields + e.SetSubjectRepository(testRepoReference) +} + +func exampleEnvironmentCreatedEvent(e *apiv04.EnvironmentCreatedEvent) { + // Set example specific fields + e.SetSubjectName(testEnvironmentName) + e.SetSubjectUrl(testEnvironmentUrl) +} + +func exampleEnvironmentDeletedEvent(e *apiv04.EnvironmentDeletedEvent) { + // Set example specific fields + e.SetSubjectName(testEnvironmentName) +} + +func exampleEnvironmentModifiedEvent(e *apiv04.EnvironmentModifiedEvent) { + // Set example specific fields + e.SetSubjectName(testEnvironmentName) + e.SetSubjectUrl(testEnvironmentUrl) +} + +func exampleIncidentDetectedEvent(e *apiv04.IncidentDetectedEvent) { + // Set example specific fields + e.SetSubjectId(testIncidentSubjectId) + e.SetSource(testIncidentSource) + e.SetSubjectSource(testIncidentSource) + e.SetSubjectArtifactId(testArtifactId) + e.SetSubjectService(testServiceReference) + e.SetSubjectEnvironment(testEnvironmentReference) + e.SetSubjectDescription("Response time above threshold of 100ms") +} + +func exampleIncidentReportedEvent(e *apiv04.IncidentReportedEvent) { + // Set example specific fields + e.SetSubjectId(testIncidentSubjectId) + e.SetSource(testIncidentSource) + e.SetSubjectSource(testIncidentSource) + e.SetSubjectArtifactId(testArtifactId) + e.SetSubjectService(testServiceReference) + e.SetSubjectEnvironment(testEnvironmentReference) + e.SetSubjectDescription("Response time above threshold of 100ms") + e.SetSubjectTicketURI("https://my-issues.example/incidents/ticket-345") +} + +func exampleIncidentResolvedEvent(e *apiv04.IncidentResolvedEvent) { + // Set example specific fields + e.SetSubjectId(testIncidentSubjectId) + e.SetSource(testIncidentSource) + e.SetSubjectSource(testIncidentSource) + e.SetSubjectArtifactId("pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93439") + e.SetSubjectService(testServiceReference) + e.SetSubjectEnvironment(testEnvironmentReference) + e.SetSubjectDescription("Response time restored below 100ms") +} + +func examplePipelineRunFinishedEvent(e *apiv04.PipelineRunFinishedEvent) { + // Set example specific fields + e.SetSubjectPipelineName(testPipeline) + e.SetSubjectUrl(testSubjecturl) + e.SetSubjectOutcome(testPipelineOutcome) + e.SetSubjectErrors(testPipelineErrors) +} + +func examplePipelineRunQueuedEvent(e *apiv04.PipelineRunQueuedEvent) { + // Set example specific fields + e.SetSubjectPipelineName(testPipeline) + e.SetSubjectUrl(testSubjecturl) +} + +func examplePipelineRunStartedEvent(e *apiv04.PipelineRunStartedEvent) { + // Set example specific fields + e.SetSubjectPipelineName(testPipeline) + e.SetSubjectUrl(testSubjecturl) +} + +func exampleRepositoryCreatedEvent(e *apiv04.RepositoryCreatedEvent) { + // Set example specific fields + e.SetSubjectName(testRepo) + e.SetSubjectOwner(testOwner) + e.SetSubjectUrl(testUrl) + e.SetSubjectViewUrl(testViewUrl) +} + +func exampleRepositoryDeletedEvent(e *apiv04.RepositoryDeletedEvent) { + // Set example specific fields + e.SetSubjectName(testRepo) + e.SetSubjectOwner(testOwner) + e.SetSubjectUrl(testUrl) + e.SetSubjectViewUrl(testViewUrl) +} + +func exampleRepositoryModifiedEvent(e *apiv04.RepositoryModifiedEvent) { + // Set example specific fields + e.SetSubjectName(testRepo) + e.SetSubjectOwner(testOwner) + e.SetSubjectUrl(testUrl) + e.SetSubjectViewUrl(testViewUrl) +} + +func exampleServiceDeployedEvent(e *apiv04.ServiceDeployedEvent) { + // Set example specific fields + e.SetSubjectEnvironment(&api.Reference{Id: testEnvironmentId}) + e.SetSubjectArtifactId(testArtifactId) +} + +func exampleServicePublishedEvent(e *apiv04.ServicePublishedEvent) { + // Set example specific fields + e.SetSubjectEnvironment(&api.Reference{Id: testEnvironmentId}) +} + +func exampleServiceRemovedEvent(e *apiv04.ServiceRemovedEvent) { + // Set example specific fields + e.SetSubjectEnvironment(&api.Reference{Id: testEnvironmentId}) +} + +func exampleServiceRolledbackEvent(e *apiv04.ServiceRolledbackEvent) { + // Set example specific fields + e.SetSubjectEnvironment(&api.Reference{Id: testEnvironmentId}) + e.SetSubjectArtifactId(testArtifactId) +} + +func exampleServiceUpgradedEvent(e *apiv04.ServiceUpgradedEvent) { + // Set example specific fields + e.SetSubjectEnvironment(&api.Reference{Id: testEnvironmentId}) + e.SetSubjectArtifactId(testArtifactId) +} + +func exampleTaskRunFinishedEvent(e *apiv04.TaskRunFinishedEvent) { + // Set example specific fields + e.SetSubjectTaskName(testTaskName) + e.SetSubjectUrl(testSubjecturl) + e.SetSubjectPipelineRun(&api.Reference{Id: testSubjectId}) + e.SetSubjectOutcome(testTaskOutcome) + e.SetSubjectErrors(testTaskRunErrors) +} + +func exampleTestCaseRunSkippedEvent(e *apiv04.TestCaseRunSkippedEvent) { + // Set example specific fields + e.SetSubjectId("myTestCaseRun123") + e.SetSubjectEnvironment(&api.Reference{ + Id: "dev", + Source: "testkube-dev-123", + }) + e.SetSubjectReason("Not running in this environment") + e.SetSubjectTestCase(&api.TestCaseRunSkippedSubjectContentTestCaseV0_1_0{ + Id: "92834723894", + Name: "Login Test", + Type: "integration", + Version: "1.0", + }) + e.SetSubjectTestSuiteRun(&api.Reference{ + Id: "test-suite-111", + Source: "testkube-dev-123", + }) + e.SetChainId("") +} + +func exampleTaskRunStartedEvent(e *apiv04.TaskRunStartedEvent) { + // Set example specific fields + e.SetSubjectTaskName(testTaskName) + e.SetSubjectUrl(testSubjecturl) + e.SetSubjectPipelineRun(&api.Reference{Id: testSubjectId}) +} + +func exampleTestCaseRunFinishedEvent(e *apiv04.TestCaseRunFinishedEvent) { + // Set example specific fields + e.SetSubjectId(testTestRunId) + e.SetSubjectId(testTestRunId) + e.SetSubjectEnvironment(testTestEnvironment) + e.SetSubjectTestCase(testTestCaseFinished) + e.SetSubjectOutcome(testTestOutcome) +} + +func exampleTestCaseRunQueuedEvent(e *apiv04.TestCaseRunQueuedEvent) { + // Set example specific fields + e.SetSubjectId(testTestRunId) + e.SetSubjectId(testTestRunId) + e.SetSubjectEnvironment(testTestEnvironment) + e.SetSubjectTestCase(testTestCaseQueued) + e.SetSubjectTrigger(testTestTriggerQueued) +} + +func exampleTestCaseRunStartedEvent(e *apiv04.TestCaseRunStartedEvent) { + // Set example specific fields + e.SetSubjectId(testTestRunId) + e.SetSubjectEnvironment(testTestEnvironment) + e.SetSubjectTestCase(testTestCaseStarted) + e.SetSubjectTrigger(testTestTriggerStarted) +} + +func exampleTestSuiteRunFinishedEvent(e *apiv04.TestSuiteRunFinishedEvent) { + // Set example specific fields + e.SetSubjectId(testTestSuiteRunId) + e.SetSubjectEnvironment(testTestEnvironment) + e.SetSubjectTestSuite(testTestSuiteFinished) + e.SetSubjectOutcome(testTestSuiteOutcome) + e.SetSubjectSeverity(testTestSuiteSeverity) + e.SetSubjectReason(testTestSuiteReason) +} + +func exampleTestSuiteRunStartedEvent(e *apiv04.TestSuiteRunStartedEvent) { + // Set example specific fields + e.SetSubjectId(testTestSuiteRunId) + e.SetSubjectEnvironment(testTestEnvironment) + e.SetSubjectTestSuite(testTestSuiteStarted) + e.SetSubjectTrigger(testTestSuiteTriggerStarted) +} + +func exampleTestSuiteRunQueuedEvent(e *apiv04.TestSuiteRunQueuedEvent) { + // Set example specific fields + e.SetSubjectId(testTestSuiteRunId) + e.SetSubjectEnvironment(testTestEnvironment) + e.SetSubjectTestSuite(testTestSuiteQueued) + e.SetSubjectTrigger(testTestSuiteTriggerQueued) +} + +func exampleTestOutputPublishedEvent(e *apiv04.TestOutputPublishedEvent) { + // Set example specific fields + e.SetSubjectId(testTestOutputSubjectId) + e.SetSubjectSource(testTestOutputSubjectSource) + e.SetSubjectOutputType(testTestOutputOutputType) + e.SetSubjectFormat(testTestOutputFormat) + e.SetSubjectTestCaseRun(testTestCaseRun) +} + +func exampleTicketClosedEvent(e *apiv04.TicketClosedEvent) { + // Set example specific fields + e.SetSubjectId(testTicketId) + e.SetSource(testTicketSource) + e.SetSubjectSource(testTicketSource) + e.SetSubjectAssignees(testTicketAssignees) + e.SetSubjectCreator(testTicketCreator) + e.SetSubjectGroup(testTicketGroup) + e.SetSubjectLabels(testTicketLabels) + e.SetSubjectMilestone(testTicketMilestone) + e.SetSubjectPriority(testTicketPriority) + e.SetSubjectResolution(testTicketResolution) + e.SetSubjectSummary(testTicketSummary) + e.SetSubjectTicketType(testTicketType) + e.SetSubjectUpdatedBy(testTicketUpdatedBy) + e.SetSubjectUri(testTicketUri) + e.SetChainId("") +} + +func exampleTicketCreatedEvent(e *apiv04.TicketCreatedEvent) { + // Set example specific fields + e.SetSubjectId(testTicketId) + e.SetSource(testTicketSource) + e.SetSubjectSource(testTicketSource) + e.SetSubjectAssignees(testTicketAssignees) + e.SetSubjectCreator(testTicketCreator) + e.SetSubjectGroup(testTicketGroup) + e.SetSubjectLabels(testTicketLabels) + e.SetSubjectMilestone(testTicketMilestone) + e.SetSubjectPriority(testTicketPriority) + e.SetSubjectSummary(testTicketSummary) + e.SetSubjectTicketType(testTicketType) + e.SetSubjectUri(testTicketUri) + e.SetChainId("") +} + +func exampleTicketUpdatedEvent(e *apiv04.TicketUpdatedEvent) { + // Set example specific fields + e.SetSubjectId(testTicketId) + e.SetSource(testTicketSource) + e.SetSubjectSource(testTicketSource) + e.SetSubjectAssignees(testTicketAssignees) + e.SetSubjectCreator(testTicketCreator) + e.SetSubjectGroup(testTicketGroup) + e.SetSubjectLabels(testTicketLabels) + e.SetSubjectMilestone(testTicketMilestone) + e.SetSubjectPriority(testTicketPriority) + e.SetSubjectSummary(testTicketSummary) + e.SetSubjectTicketType(testTicketType) + e.SetSubjectUpdatedBy(testTicketUpdatedBy) + e.SetSubjectUri(testTicketUri) + e.SetChainId("") +} + +func init() { + + // Load event examples from the spec + examplesConsumed = make(map[string][]byte) + + for _, event := range apiv04.CDEventsTypes { + short := event.GetType().Short() + examplesConsumed[short], err = os.ReadFile(filepath.Join("..", examplesFolder, short+".json")) + panicOnError(err) + } +} + +// TestExamples verifies that the SDK can produce events like those +// included in the specification examples folder. +// To do so: +// - it produces a CDEvent from scratch, and sets the values like in the examples +// - it parses the examples into a CDEvent and +// - it verifies that produced and consumed CDEvent match +func TestExamples(t *testing.T) { + + for name, exampleConsumed := range examplesConsumed { + t.Run(name, func(t *testing.T) { + produced, ok := examplesProduced[name] + if !ok { + t.Fatalf("missing produced event for event type: %v", name) + } + // Check that the produced event is valid + err := api.Validate(produced) + if err != nil { + t.Errorf("produced event failed to validate: %v", err) + } + consumed, err := apiv04.NewFromJsonBytes(exampleConsumed) + if err != nil { + t.Fatalf("didn't expected it to fail, but it did: %v", err) + } + // Check the context, except for ID and Timestamp + if d := cmp.Diff(consumed.GetVersion(), produced.GetVersion()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + if d := cmp.Diff(consumed.GetSource(), produced.GetSource()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + if d := cmp.Diff(consumed.GetType(), produced.GetType()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + // Check the subject + if d := cmp.Diff(consumed.GetSubject(), produced.GetSubject()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + // Check v04+ attributes + if d := cmp.Diff(consumed.GetChainId(), produced.GetChainId()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + if d := cmp.Diff(consumed.GetSchemaUri(), produced.GetSchemaUri()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + if d := cmp.Diff(consumed.GetLinks(), produced.GetLinks()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + }) + } +} diff --git a/pkg/api/v04/docs.go b/pkg/api/v04/docs.go new file mode 100644 index 0000000..15db905 --- /dev/null +++ b/pkg/api/v04/docs.go @@ -0,0 +1,485 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2024 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +// Package v03 contains method to create events that belong to the +// CDEvents specification v0.4.x + +package v04 + +import "github.com/cdevents/sdk-go/pkg/api" + +var SpecVersion = "0.4.1" + +type ArtifactDeletedEvent = api.ArtifactDeletedEventV0_1_0 +type ArtifactDeletedSubject = api.ArtifactDeletedSubjectV0_1_0 + +func NewArtifactDeletedEvent() (*ArtifactDeletedEvent, error) { + return api.NewArtifactDeletedEventV0_1_0(SpecVersion) +} + +var ArtifactDeletedEventType = api.ArtifactDeletedEventTypeV0_1_0 + +type ArtifactDownloadedEvent = api.ArtifactDownloadedEventV0_1_0 +type ArtifactDownloadedSubject = api.ArtifactDownloadedSubjectV0_1_0 + +func NewArtifactDownloadedEvent() (*ArtifactDownloadedEvent, error) { + return api.NewArtifactDownloadedEventV0_1_0(SpecVersion) +} + +var ArtifactDownloadedEventType = api.ArtifactDownloadedEventTypeV0_1_0 + +type ArtifactPackagedEvent = api.ArtifactPackagedEventV0_2_0 +type ArtifactPackagedSubject = api.ArtifactPackagedSubjectV0_2_0 + +// ArtifactArtifactSubjectContentSbomV0_2_0 holds the content of a Sbom field in the content +type ArtifactPackagedSubjectContentSbom = api.ArtifactPackagedSubjectContentSbomV0_2_0 + +func NewArtifactPackagedEvent() (*ArtifactPackagedEvent, error) { + return api.NewArtifactPackagedEventV0_2_0(SpecVersion) +} + +var ArtifactPackagedEventType = api.ArtifactPackagedEventTypeV0_2_0 + +type ArtifactPublishedEvent = api.ArtifactPublishedEventV0_2_0 +type ArtifactPublishedSubject = api.ArtifactPublishedSubjectV0_2_0 + +// ArtifactArtifactSubjectContentSbomV0_2_0 holds the content of a Sbom field in the content +type ArtifactPublishedSubjectContentSbom = api.ArtifactPublishedSubjectContentSbomV0_2_0 + +func NewArtifactPublishedEvent() (*ArtifactPublishedEvent, error) { + return api.NewArtifactPublishedEventV0_2_0(SpecVersion) +} + +var ArtifactPublishedEventType = api.ArtifactPublishedEventTypeV0_2_0 + +type ArtifactSignedEvent = api.ArtifactSignedEventV0_2_0 +type ArtifactSignedSubject = api.ArtifactSignedSubjectV0_2_0 + +func NewArtifactSignedEvent() (*ArtifactSignedEvent, error) { + return api.NewArtifactSignedEventV0_2_0(SpecVersion) +} + +var ArtifactSignedEventType = api.ArtifactSignedEventTypeV0_2_0 + +type BranchCreatedEvent = api.BranchCreatedEventV0_2_0 +type BranchCreatedSubject = api.BranchCreatedSubjectV0_2_0 + +func NewBranchCreatedEvent() (*BranchCreatedEvent, error) { + return api.NewBranchCreatedEventV0_2_0(SpecVersion) +} + +var BranchCreatedEventType = api.BranchCreatedEventTypeV0_2_0 + +type BranchDeletedEvent = api.BranchDeletedEventV0_2_0 +type BranchDeletedSubject = api.BranchDeletedSubjectV0_2_0 + +func NewBranchDeletedEvent() (*BranchDeletedEvent, error) { + return api.NewBranchDeletedEventV0_2_0(SpecVersion) +} + +var BranchDeletedEventType = api.BranchDeletedEventTypeV0_2_0 + +type BuildFinishedEvent = api.BuildFinishedEventV0_2_0 +type BuildFinishedSubject = api.BuildFinishedSubjectV0_2_0 + +func NewBuildFinishedEvent() (*BuildFinishedEvent, error) { + return api.NewBuildFinishedEventV0_2_0(SpecVersion) +} + +var BuildFinishedEventType = api.BuildFinishedEventTypeV0_2_0 + +type BuildQueuedEvent = api.BuildQueuedEventV0_2_0 +type BuildQueuedSubject = api.BuildQueuedSubjectV0_2_0 + +func NewBuildQueuedEvent() (*BuildQueuedEvent, error) { + return api.NewBuildQueuedEventV0_2_0(SpecVersion) +} + +var BuildQueuedEventType = api.BuildQueuedEventTypeV0_2_0 + +type BuildStartedEvent = api.BuildStartedEventV0_2_0 +type BuildStartedSubject = api.BuildStartedSubjectV0_2_0 + +func NewBuildStartedEvent() (*BuildStartedEvent, error) { + return api.NewBuildStartedEventV0_2_0(SpecVersion) +} + +var BuildStartedEventType = api.BuildStartedEventTypeV0_2_0 + +type ChangeAbandonedEvent = api.ChangeAbandonedEventV0_2_0 +type ChangeAbandonedSubject = api.ChangeAbandonedSubjectV0_2_0 + +func NewChangeAbandonedEvent() (*ChangeAbandonedEvent, error) { + return api.NewChangeAbandonedEventV0_2_0(SpecVersion) +} + +var ChangeAbandonedEventType = api.ChangeAbandonedEventTypeV0_2_0 + +type ChangeCreatedEvent = api.ChangeCreatedEventV0_3_0 +type ChangeCreatedSubject = api.ChangeCreatedSubjectV0_3_0 + +func NewChangeCreatedEvent() (*ChangeCreatedEvent, error) { + return api.NewChangeCreatedEventV0_3_0(SpecVersion) +} + +var ChangeCreatedEventType = api.ChangeCreatedEventTypeV0_3_0 + +type ChangeMergedEvent = api.ChangeMergedEventV0_2_0 +type ChangeMergedSubject = api.ChangeMergedSubjectV0_2_0 + +func NewChangeMergedEvent() (*ChangeMergedEvent, error) { + return api.NewChangeMergedEventV0_2_0(SpecVersion) +} + +var ChangeMergedEventType = api.ChangeMergedEventTypeV0_2_0 + +type ChangeReviewedEvent = api.ChangeReviewedEventV0_2_0 +type ChangeReviewedSubject = api.ChangeReviewedSubjectV0_2_0 + +func NewChangeReviewedEvent() (*ChangeReviewedEvent, error) { + return api.NewChangeReviewedEventV0_2_0(SpecVersion) +} + +var ChangeReviewedEventType = api.ChangeReviewedEventTypeV0_2_0 + +type ChangeUpdatedEvent = api.ChangeUpdatedEventV0_2_0 +type ChangeUpdatedSubject = api.ChangeUpdatedSubjectV0_2_0 + +func NewChangeUpdatedEvent() (*ChangeUpdatedEvent, error) { + return api.NewChangeUpdatedEventV0_2_0(SpecVersion) +} + +var ChangeUpdatedEventType = api.ChangeUpdatedEventTypeV0_2_0 + +type EnvironmentCreatedEvent = api.EnvironmentCreatedEventV0_2_0 +type EnvironmentCreatedSubject = api.EnvironmentCreatedSubjectV0_2_0 + +func NewEnvironmentCreatedEvent() (*EnvironmentCreatedEvent, error) { + return api.NewEnvironmentCreatedEventV0_2_0(SpecVersion) +} + +var EnvironmentCreatedEventType = api.EnvironmentCreatedEventTypeV0_2_0 + +type EnvironmentDeletedEvent = api.EnvironmentDeletedEventV0_2_0 +type EnvironmentDeletedSubject = api.EnvironmentDeletedSubjectV0_2_0 + +func NewEnvironmentDeletedEvent() (*EnvironmentDeletedEvent, error) { + return api.NewEnvironmentDeletedEventV0_2_0(SpecVersion) +} + +var EnvironmentDeletedEventType = api.EnvironmentDeletedEventTypeV0_2_0 + +type EnvironmentModifiedEvent = api.EnvironmentModifiedEventV0_2_0 +type EnvironmentModifiedSubject = api.EnvironmentModifiedSubjectV0_2_0 + +func NewEnvironmentModifiedEvent() (*EnvironmentModifiedEvent, error) { + return api.NewEnvironmentModifiedEventV0_2_0(SpecVersion) +} + +var EnvironmentModifiedEventType = api.EnvironmentModifiedEventTypeV0_2_0 + +type IncidentDetectedEvent = api.IncidentDetectedEventV0_2_0 +type IncidentDetectedSubject = api.IncidentDetectedSubjectV0_2_0 + +func NewIncidentDetectedEvent() (*IncidentDetectedEvent, error) { + return api.NewIncidentDetectedEventV0_2_0(SpecVersion) +} + +var IncidentDetectedEventType = api.IncidentDetectedEventTypeV0_2_0 + +type IncidentReportedEvent = api.IncidentReportedEventV0_2_0 +type IncidentReportedSubject = api.IncidentReportedSubjectV0_2_0 + +func NewIncidentReportedEvent() (*IncidentReportedEvent, error) { + return api.NewIncidentReportedEventV0_2_0(SpecVersion) +} + +var IncidentReportedEventType = api.IncidentReportedEventTypeV0_2_0 + +type IncidentResolvedEvent = api.IncidentResolvedEventV0_2_0 +type IncidentResolvedSubject = api.IncidentResolvedSubjectV0_2_0 + +func NewIncidentResolvedEvent() (*IncidentResolvedEvent, error) { + return api.NewIncidentResolvedEventV0_2_0(SpecVersion) +} + +var IncidentResolvedEventType = api.IncidentResolvedEventTypeV0_2_0 + +type PipelineRunFinishedEvent = api.PipelineRunFinishedEventV0_2_0 +type PipelineRunFinishedSubject = api.PipelineRunFinishedSubjectV0_2_0 + +func NewPipelineRunFinishedEvent() (*PipelineRunFinishedEvent, error) { + return api.NewPipelineRunFinishedEventV0_2_0(SpecVersion) +} + +var PipelineRunFinishedEventType = api.PipelineRunFinishedEventTypeV0_2_0 + +type PipelineRunQueuedEvent = api.PipelineRunQueuedEventV0_2_0 +type PipelineRunQueuedSubject = api.PipelineRunQueuedSubjectV0_2_0 + +func NewPipelineRunQueuedEvent() (*PipelineRunQueuedEvent, error) { + return api.NewPipelineRunQueuedEventV0_2_0(SpecVersion) +} + +var PipelineRunQueuedEventType = api.PipelineRunQueuedEventTypeV0_2_0 + +type PipelineRunStartedEvent = api.PipelineRunStartedEventV0_2_0 +type PipelineRunStartedSubject = api.PipelineRunStartedSubjectV0_2_0 + +func NewPipelineRunStartedEvent() (*PipelineRunStartedEvent, error) { + return api.NewPipelineRunStartedEventV0_2_0(SpecVersion) +} + +var PipelineRunStartedEventType = api.PipelineRunStartedEventTypeV0_2_0 + +type RepositoryCreatedEvent = api.RepositoryCreatedEventV0_2_0 +type RepositoryCreatedSubject = api.RepositoryCreatedSubjectV0_2_0 + +func NewRepositoryCreatedEvent() (*RepositoryCreatedEvent, error) { + return api.NewRepositoryCreatedEventV0_2_0(SpecVersion) +} + +var RepositoryCreatedEventType = api.RepositoryCreatedEventTypeV0_2_0 + +type RepositoryDeletedEvent = api.RepositoryDeletedEventV0_2_0 +type RepositoryDeletedSubject = api.RepositoryDeletedSubjectV0_2_0 + +func NewRepositoryDeletedEvent() (*RepositoryDeletedEvent, error) { + return api.NewRepositoryDeletedEventV0_2_0(SpecVersion) +} + +var RepositoryDeletedEventType = api.RepositoryDeletedEventTypeV0_2_0 + +type RepositoryModifiedEvent = api.RepositoryModifiedEventV0_2_0 +type RepositoryModifiedSubject = api.RepositoryModifiedSubjectV0_2_0 + +func NewRepositoryModifiedEvent() (*RepositoryModifiedEvent, error) { + return api.NewRepositoryModifiedEventV0_2_0(SpecVersion) +} + +var RepositoryModifiedEventType = api.RepositoryModifiedEventTypeV0_2_0 + +type ServiceDeployedEvent = api.ServiceDeployedEventV0_2_0 +type ServiceDeployedSubject = api.ServiceDeployedSubjectV0_2_0 + +func NewServiceDeployedEvent() (*ServiceDeployedEvent, error) { + return api.NewServiceDeployedEventV0_2_0(SpecVersion) +} + +var ServiceDeployedEventType = api.ServiceDeployedEventTypeV0_2_0 + +type ServicePublishedEvent = api.ServicePublishedEventV0_2_0 +type ServicePublishedSubject = api.ServicePublishedSubjectV0_2_0 + +func NewServicePublishedEvent() (*ServicePublishedEvent, error) { + return api.NewServicePublishedEventV0_2_0(SpecVersion) +} + +var ServicePublishedEventType = api.ServicePublishedEventTypeV0_2_0 + +type ServiceRemovedEvent = api.ServiceRemovedEventV0_2_0 +type ServiceRemovedSubject = api.ServiceRemovedSubjectV0_2_0 + +func NewServiceRemovedEvent() (*ServiceRemovedEvent, error) { + return api.NewServiceRemovedEventV0_2_0(SpecVersion) +} + +var ServiceRemovedEventType = api.ServiceRemovedEventTypeV0_2_0 + +type ServiceRolledbackEvent = api.ServiceRolledbackEventV0_2_0 +type ServiceRolledbackSubject = api.ServiceRolledbackSubjectV0_2_0 + +func NewServiceRolledbackEvent() (*ServiceRolledbackEvent, error) { + return api.NewServiceRolledbackEventV0_2_0(SpecVersion) +} + +var ServiceRolledbackEventType = api.ServiceRolledbackEventTypeV0_2_0 + +type ServiceUpgradedEvent = api.ServiceUpgradedEventV0_2_0 +type ServiceUpgradedSubject = api.ServiceUpgradedSubjectV0_2_0 + +func NewServiceUpgradedEvent() (*ServiceUpgradedEvent, error) { + return api.NewServiceUpgradedEventV0_2_0(SpecVersion) +} + +var ServiceUpgradedEventType = api.ServiceUpgradedEventTypeV0_2_0 + +type TaskRunFinishedEvent = api.TaskRunFinishedEventV0_2_0 +type TaskRunFinishedSubject = api.TaskRunFinishedSubjectV0_2_0 + +func NewTaskRunFinishedEvent() (*TaskRunFinishedEvent, error) { + return api.NewTaskRunFinishedEventV0_2_0(SpecVersion) +} + +var TaskRunFinishedEventType = api.TaskRunFinishedEventTypeV0_2_0 + +type TaskRunStartedEvent = api.TaskRunStartedEventV0_2_0 +type TaskRunStartedSubject = api.TaskRunStartedSubjectV0_2_0 + +func NewTaskRunStartedEvent() (*TaskRunStartedEvent, error) { + return api.NewTaskRunStartedEventV0_2_0(SpecVersion) +} + +var TaskRunStartedEventType = api.TaskRunStartedEventTypeV0_2_0 + +type TestCaseRunFinishedEvent = api.TestCaseRunFinishedEventV0_2_0 +type TestCaseRunFinishedSubject = api.TestCaseRunFinishedSubjectV0_2_0 + +// TestCaseRunTestCaseRunSubjectContentTestCaseV0_2_0 holds the content of a TestCase field in the content +type TestCaseRunFinishedSubjectContentTestCase = api.TestCaseRunFinishedSubjectContentTestCaseV0_2_0 + +func NewTestCaseRunFinishedEvent() (*TestCaseRunFinishedEvent, error) { + return api.NewTestCaseRunFinishedEventV0_2_0(SpecVersion) +} + +var TestCaseRunFinishedEventType = api.TestCaseRunFinishedEventTypeV0_2_0 + +type TestCaseRunQueuedEvent = api.TestCaseRunQueuedEventV0_2_0 +type TestCaseRunQueuedSubject = api.TestCaseRunQueuedSubjectV0_2_0 + +// TestCaseRunTestCaseRunSubjectContentTestCaseV0_2_0 holds the content of a TestCase field in the content +type TestCaseRunQueuedSubjectContentTestCase = api.TestCaseRunQueuedSubjectContentTestCaseV0_2_0 + +// TestCaseRunTestCaseRunSubjectContentTriggerV0_2_0 holds the content of a Trigger field in the content +type TestCaseRunQueuedSubjectContentTrigger = api.TestCaseRunQueuedSubjectContentTriggerV0_2_0 + +func NewTestCaseRunQueuedEvent() (*TestCaseRunQueuedEvent, error) { + return api.NewTestCaseRunQueuedEventV0_2_0(SpecVersion) +} + +var TestCaseRunQueuedEventType = api.TestCaseRunQueuedEventTypeV0_2_0 + +type TestCaseRunSkippedEvent = api.TestCaseRunSkippedEventV0_1_0 +type TestCaseRunSkippedSubject = api.TestCaseRunSkippedSubjectV0_1_0 + +// TestCaseRunTestCaseRunSubjectContentTestCaseV0_1_0 holds the content of a TestCase field in the content +type TestCaseRunSkippedSubjectContentTestCase = api.TestCaseRunSkippedSubjectContentTestCaseV0_1_0 + +func NewTestCaseRunSkippedEvent() (*TestCaseRunSkippedEvent, error) { + return api.NewTestCaseRunSkippedEventV0_1_0(SpecVersion) +} + +var TestCaseRunSkippedEventType = api.TestCaseRunSkippedEventTypeV0_1_0 + +type TestCaseRunStartedEvent = api.TestCaseRunStartedEventV0_2_0 +type TestCaseRunStartedSubject = api.TestCaseRunStartedSubjectV0_2_0 + +// TestCaseRunTestCaseRunSubjectContentTestCaseV0_2_0 holds the content of a TestCase field in the content +type TestCaseRunStartedSubjectContentTestCase = api.TestCaseRunStartedSubjectContentTestCaseV0_2_0 + +// TestCaseRunTestCaseRunSubjectContentTriggerV0_2_0 holds the content of a Trigger field in the content +type TestCaseRunStartedSubjectContentTrigger = api.TestCaseRunStartedSubjectContentTriggerV0_2_0 + +func NewTestCaseRunStartedEvent() (*TestCaseRunStartedEvent, error) { + return api.NewTestCaseRunStartedEventV0_2_0(SpecVersion) +} + +var TestCaseRunStartedEventType = api.TestCaseRunStartedEventTypeV0_2_0 + +type TestOutputPublishedEvent = api.TestOutputPublishedEventV0_2_0 +type TestOutputPublishedSubject = api.TestOutputPublishedSubjectV0_2_0 + +func NewTestOutputPublishedEvent() (*TestOutputPublishedEvent, error) { + return api.NewTestOutputPublishedEventV0_2_0(SpecVersion) +} + +var TestOutputPublishedEventType = api.TestOutputPublishedEventTypeV0_2_0 + +type TestSuiteRunFinishedEvent = api.TestSuiteRunFinishedEventV0_2_0 +type TestSuiteRunFinishedSubject = api.TestSuiteRunFinishedSubjectV0_2_0 + +// TestSuiteRunTestSuiteRunSubjectContentTestSuiteV0_2_0 holds the content of a TestSuite field in the content +type TestSuiteRunFinishedSubjectContentTestSuite = api.TestSuiteRunFinishedSubjectContentTestSuiteV0_2_0 + +func NewTestSuiteRunFinishedEvent() (*TestSuiteRunFinishedEvent, error) { + return api.NewTestSuiteRunFinishedEventV0_2_0(SpecVersion) +} + +var TestSuiteRunFinishedEventType = api.TestSuiteRunFinishedEventTypeV0_2_0 + +type TestSuiteRunQueuedEvent = api.TestSuiteRunQueuedEventV0_2_0 +type TestSuiteRunQueuedSubject = api.TestSuiteRunQueuedSubjectV0_2_0 + +// TestSuiteRunTestSuiteRunSubjectContentTestSuiteV0_2_0 holds the content of a TestSuite field in the content +type TestSuiteRunQueuedSubjectContentTestSuite = api.TestSuiteRunQueuedSubjectContentTestSuiteV0_2_0 + +// TestSuiteRunTestSuiteRunSubjectContentTriggerV0_2_0 holds the content of a Trigger field in the content +type TestSuiteRunQueuedSubjectContentTrigger = api.TestSuiteRunQueuedSubjectContentTriggerV0_2_0 + +func NewTestSuiteRunQueuedEvent() (*TestSuiteRunQueuedEvent, error) { + return api.NewTestSuiteRunQueuedEventV0_2_0(SpecVersion) +} + +var TestSuiteRunQueuedEventType = api.TestSuiteRunQueuedEventTypeV0_2_0 + +type TestSuiteRunStartedEvent = api.TestSuiteRunStartedEventV0_2_0 +type TestSuiteRunStartedSubject = api.TestSuiteRunStartedSubjectV0_2_0 + +// TestSuiteRunTestSuiteRunSubjectContentTestSuiteV0_2_0 holds the content of a TestSuite field in the content +type TestSuiteRunStartedSubjectContentTestSuite = api.TestSuiteRunStartedSubjectContentTestSuiteV0_2_0 + +// TestSuiteRunTestSuiteRunSubjectContentTriggerV0_2_0 holds the content of a Trigger field in the content +type TestSuiteRunStartedSubjectContentTrigger = api.TestSuiteRunStartedSubjectContentTriggerV0_2_0 + +func NewTestSuiteRunStartedEvent() (*TestSuiteRunStartedEvent, error) { + return api.NewTestSuiteRunStartedEventV0_2_0(SpecVersion) +} + +var TestSuiteRunStartedEventType = api.TestSuiteRunStartedEventTypeV0_2_0 + +type TicketClosedEvent = api.TicketClosedEventV0_1_0 +type TicketClosedSubject = api.TicketClosedSubjectV0_1_0 + +func NewTicketClosedEvent() (*TicketClosedEvent, error) { + return api.NewTicketClosedEventV0_1_0(SpecVersion) +} + +var TicketClosedEventType = api.TicketClosedEventTypeV0_1_0 + +type TicketCreatedEvent = api.TicketCreatedEventV0_1_0 +type TicketCreatedSubject = api.TicketCreatedSubjectV0_1_0 + +func NewTicketCreatedEvent() (*TicketCreatedEvent, error) { + return api.NewTicketCreatedEventV0_1_0(SpecVersion) +} + +var TicketCreatedEventType = api.TicketCreatedEventTypeV0_1_0 + +type TicketUpdatedEvent = api.TicketUpdatedEventV0_1_0 +type TicketUpdatedSubject = api.TicketUpdatedSubjectV0_1_0 + +func NewTicketUpdatedEvent() (*TicketUpdatedEvent, error) { + return api.NewTicketUpdatedEventV0_1_0(SpecVersion) +} + +var TicketUpdatedEventType = api.TicketUpdatedEventTypeV0_1_0 + +// NewFromJsonBytes builds a new CDEventReader from a JSON string as []bytes +// This works by unmarshalling the context first, extracting the event type and using +// that to unmarshal the rest of the event into the correct object. +// It assumes the context can be unmarshalled in a `Context` object. +func NewFromJsonBytes(event []byte) (api.CDEventV04, error) { + return api.NewFromJsonBytesContext[api.CDEventV04](event, CDEventsByUnversionedTypes) +} + +// Build a new CDEventReader from a JSON string +func NewFromJsonString(event string) (api.CDEventV04, error) { + return NewFromJsonBytes([]byte(event)) +} diff --git a/pkg/api/v04/factory_test.go b/pkg/api/v04/factory_test.go new file mode 100644 index 0000000..c8c0f10 --- /dev/null +++ b/pkg/api/v04/factory_test.go @@ -0,0 +1,137 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package v04_test + +import ( + "encoding/json" + "fmt" + "testing" + "time" + + "github.com/cdevents/sdk-go/pkg/api" + cdevents "github.com/cdevents/sdk-go/pkg/api/v04" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/google/uuid" +) + +func init() { + // Get the time once + t := time.Now() + timeNow = func() time.Time { + return t + } + + // Get the UUID once + u, _ := uuid.NewRandom() + uuidNewRandom = func() (uuid.UUID, error) { + return u, nil + } +} + +func testUUID() string { + u, _ := uuidNewRandom() + return fmt.Sprintf("%v", u) +} + +type testNewCDEventType struct { + name string + eventType string + expectedEvent api.CDEvent +} + +// tests is used in TestNewCDEvents. It's content is +// generated in zz_factory_tests.go +var ( + tests []testNewCDEventType + testContentType = "application/json" + timeNow = time.Now + uuidNewRandom = uuid.NewRandom + testSpecVersion = "0.4.1" +) + +func TestNewCDEvent(t *testing.T) { + testDataJsonBytes, err := json.Marshal(testDataJson) + if err != nil { + t.Fatalf("didn't expected it to fail, but it did: %v", err) + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + event, err := cdevents.NewCDEvent(tc.eventType, testSpecVersion) + if err != nil { + t.Fatalf("didn't expected it to fail, but it did: %v", err) + } + if d := cmp.Diff(tc.expectedEvent, event, + cmpopts.IgnoreFields(api.Context{}, "Timestamp"), + cmpopts.IgnoreFields(api.Context{}, "Id")); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + // Check GetType + if d := cmp.Diff(tc.eventType, event.GetType().String()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + // CustomData set and get + err = event.SetCustomData(testContentType, testDataJsonBytes) + if err != nil { + t.Fatalf("didn't expected it to fail, but it did: %v", err) + } + customDataRawGot, err := event.GetCustomDataRaw() + if err != nil { + t.Fatalf("didn't expected it to fail, but it did: %v", err) + } + if d := cmp.Diff(testDataJsonBytes, customDataRawGot); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + customDataGot, err := event.GetCustomData() + if err != nil { + t.Fatalf("didn't expected it to fail, but it did: %v", err) + } + if d := cmp.Diff(testDataJsonUnmarshalled, customDataGot); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + var customDataAsGot testData + err = event.GetCustomDataAs(&customDataAsGot) + if err != nil { + t.Fatalf("didn't expected it to fail, but it did: %v", err) + } + if d := cmp.Diff(testDataJson, customDataAsGot); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + if d := cmp.Diff(event.GetCustomDataContentType(), testContentType); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + // Subject source set and get + event.SetSubjectSource("randomSubjectSource") + gotSubjectSource := event.GetSubjectSource() + if d := cmp.Diff("randomSubjectSource", gotSubjectSource); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + }) + } +} + +func TestNewCDEventFailed(t *testing.T) { + + _, err := cdevents.NewCDEvent(api.CDEventType{Subject: "not supported"}.String(), testSpecVersion) + if err == nil { + t.Fatalf("expected it to fail, but it didn't") + } +} diff --git a/pkg/api/v04/types.go b/pkg/api/v04/types.go new file mode 100644 index 0000000..df1f3fe --- /dev/null +++ b/pkg/api/v04/types.go @@ -0,0 +1,184 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package v04 + +import ( + "fmt" + + "github.com/cdevents/sdk-go/pkg/api" +) + +var CDEventsTypes = []api.CDEventV04{ + &ArtifactDeletedEvent{}, + &ArtifactDownloadedEvent{}, + &ArtifactPackagedEvent{}, + &ArtifactPublishedEvent{}, + &ArtifactSignedEvent{}, + &BranchCreatedEvent{}, + &BranchDeletedEvent{}, + &BuildFinishedEvent{}, + &BuildQueuedEvent{}, + &BuildStartedEvent{}, + &ChangeAbandonedEvent{}, + &ChangeCreatedEvent{}, + &ChangeMergedEvent{}, + &ChangeReviewedEvent{}, + &ChangeUpdatedEvent{}, + &EnvironmentCreatedEvent{}, + &EnvironmentDeletedEvent{}, + &EnvironmentModifiedEvent{}, + &IncidentDetectedEvent{}, + &IncidentReportedEvent{}, + &IncidentResolvedEvent{}, + &PipelineRunFinishedEvent{}, + &PipelineRunQueuedEvent{}, + &PipelineRunStartedEvent{}, + &RepositoryCreatedEvent{}, + &RepositoryDeletedEvent{}, + &RepositoryModifiedEvent{}, + &ServiceDeployedEvent{}, + &ServicePublishedEvent{}, + &ServiceRemovedEvent{}, + &ServiceRolledbackEvent{}, + &ServiceUpgradedEvent{}, + &TaskRunFinishedEvent{}, + &TaskRunStartedEvent{}, + &TestCaseRunFinishedEvent{}, + &TestCaseRunQueuedEvent{}, + &TestCaseRunSkippedEvent{}, + &TestCaseRunStartedEvent{}, + &TestOutputPublishedEvent{}, + &TestSuiteRunFinishedEvent{}, + &TestSuiteRunQueuedEvent{}, + &TestSuiteRunStartedEvent{}, + &TicketClosedEvent{}, + &TicketCreatedEvent{}, + &TicketUpdatedEvent{}, +} + +var CDEventsByUnversionedTypes map[string]api.CDEventV04 + +func init() { + // Set up CDEventsByUnversionedTypes for convenience + CDEventsByUnversionedTypes = make(map[string]api.CDEventV04) + for _, event := range CDEventsTypes { + CDEventsByUnversionedTypes[event.GetType().UnversionedString()] = event + } +} + +// NewCDEvent produces a CDEvent by type +// This function can be used by users but it's meant mainly for testing purposes +func NewCDEvent(eventType, specVersion string) (api.CDEvent, error) { + switch eventType { + case api.ArtifactDeletedEventTypeV0_1_0.String(): + return NewArtifactDeletedEvent() + case api.ArtifactDownloadedEventTypeV0_1_0.String(): + return NewArtifactDownloadedEvent() + case api.ArtifactPackagedEventTypeV0_2_0.String(): + return NewArtifactPackagedEvent() + case api.ArtifactPublishedEventTypeV0_2_0.String(): + return NewArtifactPublishedEvent() + case api.ArtifactSignedEventTypeV0_2_0.String(): + return NewArtifactSignedEvent() + case api.BranchCreatedEventTypeV0_2_0.String(): + return NewBranchCreatedEvent() + case api.BranchDeletedEventTypeV0_2_0.String(): + return NewBranchDeletedEvent() + case api.BuildFinishedEventTypeV0_2_0.String(): + return NewBuildFinishedEvent() + case api.BuildQueuedEventTypeV0_2_0.String(): + return NewBuildQueuedEvent() + case api.BuildStartedEventTypeV0_2_0.String(): + return NewBuildStartedEvent() + case api.ChangeAbandonedEventTypeV0_2_0.String(): + return NewChangeAbandonedEvent() + case api.ChangeCreatedEventTypeV0_3_0.String(): + return NewChangeCreatedEvent() + case api.ChangeMergedEventTypeV0_2_0.String(): + return NewChangeMergedEvent() + case api.ChangeReviewedEventTypeV0_2_0.String(): + return NewChangeReviewedEvent() + case api.ChangeUpdatedEventTypeV0_2_0.String(): + return NewChangeUpdatedEvent() + case api.EnvironmentCreatedEventTypeV0_2_0.String(): + return NewEnvironmentCreatedEvent() + case api.EnvironmentDeletedEventTypeV0_2_0.String(): + return NewEnvironmentDeletedEvent() + case api.EnvironmentModifiedEventTypeV0_2_0.String(): + return NewEnvironmentModifiedEvent() + case api.IncidentDetectedEventTypeV0_2_0.String(): + return NewIncidentDetectedEvent() + case api.IncidentReportedEventTypeV0_2_0.String(): + return NewIncidentReportedEvent() + case api.IncidentResolvedEventTypeV0_2_0.String(): + return NewIncidentResolvedEvent() + case api.PipelineRunFinishedEventTypeV0_2_0.String(): + return NewPipelineRunFinishedEvent() + case api.PipelineRunQueuedEventTypeV0_2_0.String(): + return NewPipelineRunQueuedEvent() + case api.PipelineRunStartedEventTypeV0_2_0.String(): + return NewPipelineRunStartedEvent() + case api.RepositoryCreatedEventTypeV0_2_0.String(): + return NewRepositoryCreatedEvent() + case api.RepositoryDeletedEventTypeV0_2_0.String(): + return NewRepositoryDeletedEvent() + case api.RepositoryModifiedEventTypeV0_2_0.String(): + return NewRepositoryModifiedEvent() + case api.ServiceDeployedEventTypeV0_2_0.String(): + return NewServiceDeployedEvent() + case api.ServicePublishedEventTypeV0_2_0.String(): + return NewServicePublishedEvent() + case api.ServiceRemovedEventTypeV0_2_0.String(): + return NewServiceRemovedEvent() + case api.ServiceRolledbackEventTypeV0_2_0.String(): + return NewServiceRolledbackEvent() + case api.ServiceUpgradedEventTypeV0_2_0.String(): + return NewServiceUpgradedEvent() + case api.TaskRunFinishedEventTypeV0_2_0.String(): + return NewTaskRunFinishedEvent() + case api.TaskRunStartedEventTypeV0_2_0.String(): + return NewTaskRunStartedEvent() + case api.TestCaseRunFinishedEventTypeV0_2_0.String(): + return NewTestCaseRunFinishedEvent() + case api.TestCaseRunQueuedEventTypeV0_2_0.String(): + return NewTestCaseRunQueuedEvent() + case api.TestCaseRunSkippedEventTypeV0_1_0.String(): + return NewTestCaseRunSkippedEvent() + case api.TestCaseRunStartedEventTypeV0_2_0.String(): + return NewTestCaseRunStartedEvent() + case api.TestOutputPublishedEventTypeV0_2_0.String(): + return NewTestOutputPublishedEvent() + case api.TestSuiteRunFinishedEventTypeV0_2_0.String(): + return NewTestSuiteRunFinishedEvent() + case api.TestSuiteRunQueuedEventTypeV0_2_0.String(): + return NewTestSuiteRunQueuedEvent() + case api.TestSuiteRunStartedEventTypeV0_2_0.String(): + return NewTestSuiteRunStartedEvent() + case api.TicketClosedEventTypeV0_1_0.String(): + return NewTicketClosedEvent() + case api.TicketCreatedEventTypeV0_1_0.String(): + return NewTicketCreatedEvent() + case api.TicketUpdatedEventTypeV0_1_0.String(): + return NewTicketUpdatedEvent() + default: + return nil, fmt.Errorf("event %v not supported", eventType) + } +} diff --git a/pkg/api/v04/zz_examples_test.go b/pkg/api/v04/zz_examples_test.go new file mode 100644 index 0000000..7a191d5 --- /dev/null +++ b/pkg/api/v04/zz_examples_test.go @@ -0,0 +1,370 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package v04_test + +import ( + "github.com/cdevents/sdk-go/pkg/api" + specv04 "github.com/cdevents/sdk-go/pkg/api/v04" +) + +func init() { + // Create events equal to examples in the spec + examplesProduced = make(map[string]api.CDEventV04) + + // Set up test links + tags := api.Tags{ + "foo1": "bar", + "foo2": "bar", + } + reference := api.EventReference{ + ContextId: testContextId, + } + elr := api.NewEmbeddedLinkRelation() + elr.SetTags(tags) + elr.SetLinkKind("TRIGGER") + elr.SetTarget(reference) + elp := api.NewEmbeddedLinkPath() + elp.SetTags(tags) + elp.SetFrom(reference) + ele := api.NewEmbeddedLinkEnd() + ele.SetTags(tags) + ele.SetFrom(reference) + testLinks = api.EmbeddedLinksArray{ + elr, elp, ele, + } + + // Create events for test + // ArtifactDeleted Event producer + newArtifactDeleted, _ := specv04.NewArtifactDeletedEvent() + setContext(newArtifactDeleted, testSubjectId) + setContextV04(newArtifactDeleted, true, true) + exampleArtifactDeletedEvent(newArtifactDeleted) + examplesProduced[newArtifactDeleted.GetType().Short()] = newArtifactDeleted + + // ArtifactDownloaded Event producer + newArtifactDownloaded, _ := specv04.NewArtifactDownloadedEvent() + setContext(newArtifactDownloaded, testSubjectId) + setContextV04(newArtifactDownloaded, true, true) + exampleArtifactDownloadedEvent(newArtifactDownloaded) + examplesProduced[newArtifactDownloaded.GetType().Short()] = newArtifactDownloaded + + // ArtifactPackaged Event producer + newArtifactPackaged, _ := specv04.NewArtifactPackagedEvent() + setContext(newArtifactPackaged, testSubjectId) + setContextV04(newArtifactPackaged, true, true) + exampleArtifactPackagedEvent(newArtifactPackaged) + examplesProduced[newArtifactPackaged.GetType().Short()] = newArtifactPackaged + + // ArtifactPublished Event producer + newArtifactPublished, _ := specv04.NewArtifactPublishedEvent() + setContext(newArtifactPublished, testSubjectId) + setContextV04(newArtifactPublished, true, true) + exampleArtifactPublishedEvent(newArtifactPublished) + examplesProduced[newArtifactPublished.GetType().Short()] = newArtifactPublished + + // ArtifactSigned Event producer + newArtifactSigned, _ := specv04.NewArtifactSignedEvent() + setContext(newArtifactSigned, testSubjectId) + setContextV04(newArtifactSigned, true, true) + exampleArtifactSignedEvent(newArtifactSigned) + examplesProduced[newArtifactSigned.GetType().Short()] = newArtifactSigned + + // BranchCreated Event producer + newBranchCreated, _ := specv04.NewBranchCreatedEvent() + setContext(newBranchCreated, testSubjectId) + setContextV04(newBranchCreated, true, true) + exampleBranchCreatedEvent(newBranchCreated) + examplesProduced[newBranchCreated.GetType().Short()] = newBranchCreated + + // BranchDeleted Event producer + newBranchDeleted, _ := specv04.NewBranchDeletedEvent() + setContext(newBranchDeleted, testSubjectId) + setContextV04(newBranchDeleted, true, true) + exampleBranchDeletedEvent(newBranchDeleted) + examplesProduced[newBranchDeleted.GetType().Short()] = newBranchDeleted + + // BuildFinished Event producer + newBuildFinished, _ := specv04.NewBuildFinishedEvent() + setContext(newBuildFinished, testSubjectId) + setContextV04(newBuildFinished, true, true) + exampleBuildFinishedEvent(newBuildFinished) + examplesProduced[newBuildFinished.GetType().Short()] = newBuildFinished + + // BuildQueued Event producer + newBuildQueued, _ := specv04.NewBuildQueuedEvent() + setContext(newBuildQueued, testSubjectId) + setContextV04(newBuildQueued, true, true) + exampleBuildQueuedEvent(newBuildQueued) + examplesProduced[newBuildQueued.GetType().Short()] = newBuildQueued + + // BuildStarted Event producer + newBuildStarted, _ := specv04.NewBuildStartedEvent() + setContext(newBuildStarted, testSubjectId) + setContextV04(newBuildStarted, true, true) + exampleBuildStartedEvent(newBuildStarted) + examplesProduced[newBuildStarted.GetType().Short()] = newBuildStarted + + // ChangeAbandoned Event producer + newChangeAbandoned, _ := specv04.NewChangeAbandonedEvent() + setContext(newChangeAbandoned, testSubjectId) + setContextV04(newChangeAbandoned, true, true) + exampleChangeAbandonedEvent(newChangeAbandoned) + examplesProduced[newChangeAbandoned.GetType().Short()] = newChangeAbandoned + + // ChangeCreated Event producer + newChangeCreated, _ := specv04.NewChangeCreatedEvent() + setContext(newChangeCreated, testSubjectId) + setContextV04(newChangeCreated, true, true) + exampleChangeCreatedEvent(newChangeCreated) + examplesProduced[newChangeCreated.GetType().Short()] = newChangeCreated + + // ChangeMerged Event producer + newChangeMerged, _ := specv04.NewChangeMergedEvent() + setContext(newChangeMerged, testSubjectId) + setContextV04(newChangeMerged, true, true) + exampleChangeMergedEvent(newChangeMerged) + examplesProduced[newChangeMerged.GetType().Short()] = newChangeMerged + + // ChangeReviewed Event producer + newChangeReviewed, _ := specv04.NewChangeReviewedEvent() + setContext(newChangeReviewed, testSubjectId) + setContextV04(newChangeReviewed, true, true) + exampleChangeReviewedEvent(newChangeReviewed) + examplesProduced[newChangeReviewed.GetType().Short()] = newChangeReviewed + + // ChangeUpdated Event producer + newChangeUpdated, _ := specv04.NewChangeUpdatedEvent() + setContext(newChangeUpdated, testSubjectId) + setContextV04(newChangeUpdated, true, true) + exampleChangeUpdatedEvent(newChangeUpdated) + examplesProduced[newChangeUpdated.GetType().Short()] = newChangeUpdated + + // EnvironmentCreated Event producer + newEnvironmentCreated, _ := specv04.NewEnvironmentCreatedEvent() + setContext(newEnvironmentCreated, testSubjectId) + setContextV04(newEnvironmentCreated, true, true) + exampleEnvironmentCreatedEvent(newEnvironmentCreated) + examplesProduced[newEnvironmentCreated.GetType().Short()] = newEnvironmentCreated + + // EnvironmentDeleted Event producer + newEnvironmentDeleted, _ := specv04.NewEnvironmentDeletedEvent() + setContext(newEnvironmentDeleted, testSubjectId) + setContextV04(newEnvironmentDeleted, true, true) + exampleEnvironmentDeletedEvent(newEnvironmentDeleted) + examplesProduced[newEnvironmentDeleted.GetType().Short()] = newEnvironmentDeleted + + // EnvironmentModified Event producer + newEnvironmentModified, _ := specv04.NewEnvironmentModifiedEvent() + setContext(newEnvironmentModified, testSubjectId) + setContextV04(newEnvironmentModified, true, true) + exampleEnvironmentModifiedEvent(newEnvironmentModified) + examplesProduced[newEnvironmentModified.GetType().Short()] = newEnvironmentModified + + // IncidentDetected Event producer + newIncidentDetected, _ := specv04.NewIncidentDetectedEvent() + setContext(newIncidentDetected, testSubjectId) + setContextV04(newIncidentDetected, true, true) + exampleIncidentDetectedEvent(newIncidentDetected) + examplesProduced[newIncidentDetected.GetType().Short()] = newIncidentDetected + + // IncidentReported Event producer + newIncidentReported, _ := specv04.NewIncidentReportedEvent() + setContext(newIncidentReported, testSubjectId) + setContextV04(newIncidentReported, true, true) + exampleIncidentReportedEvent(newIncidentReported) + examplesProduced[newIncidentReported.GetType().Short()] = newIncidentReported + + // IncidentResolved Event producer + newIncidentResolved, _ := specv04.NewIncidentResolvedEvent() + setContext(newIncidentResolved, testSubjectId) + setContextV04(newIncidentResolved, true, true) + exampleIncidentResolvedEvent(newIncidentResolved) + examplesProduced[newIncidentResolved.GetType().Short()] = newIncidentResolved + + // PipelineRunFinished Event producer + newPipelineRunFinished, _ := specv04.NewPipelineRunFinishedEvent() + setContext(newPipelineRunFinished, testSubjectId) + setContextV04(newPipelineRunFinished, true, true) + examplePipelineRunFinishedEvent(newPipelineRunFinished) + examplesProduced[newPipelineRunFinished.GetType().Short()] = newPipelineRunFinished + + // PipelineRunQueued Event producer + newPipelineRunQueued, _ := specv04.NewPipelineRunQueuedEvent() + setContext(newPipelineRunQueued, testSubjectId) + setContextV04(newPipelineRunQueued, true, true) + examplePipelineRunQueuedEvent(newPipelineRunQueued) + examplesProduced[newPipelineRunQueued.GetType().Short()] = newPipelineRunQueued + + // PipelineRunStarted Event producer + newPipelineRunStarted, _ := specv04.NewPipelineRunStartedEvent() + setContext(newPipelineRunStarted, testSubjectId) + setContextV04(newPipelineRunStarted, true, true) + examplePipelineRunStartedEvent(newPipelineRunStarted) + examplesProduced[newPipelineRunStarted.GetType().Short()] = newPipelineRunStarted + + // RepositoryCreated Event producer + newRepositoryCreated, _ := specv04.NewRepositoryCreatedEvent() + setContext(newRepositoryCreated, testSubjectId) + setContextV04(newRepositoryCreated, true, true) + exampleRepositoryCreatedEvent(newRepositoryCreated) + examplesProduced[newRepositoryCreated.GetType().Short()] = newRepositoryCreated + + // RepositoryDeleted Event producer + newRepositoryDeleted, _ := specv04.NewRepositoryDeletedEvent() + setContext(newRepositoryDeleted, testSubjectId) + setContextV04(newRepositoryDeleted, true, true) + exampleRepositoryDeletedEvent(newRepositoryDeleted) + examplesProduced[newRepositoryDeleted.GetType().Short()] = newRepositoryDeleted + + // RepositoryModified Event producer + newRepositoryModified, _ := specv04.NewRepositoryModifiedEvent() + setContext(newRepositoryModified, testSubjectId) + setContextV04(newRepositoryModified, true, true) + exampleRepositoryModifiedEvent(newRepositoryModified) + examplesProduced[newRepositoryModified.GetType().Short()] = newRepositoryModified + + // ServiceDeployed Event producer + newServiceDeployed, _ := specv04.NewServiceDeployedEvent() + setContext(newServiceDeployed, testSubjectId) + setContextV04(newServiceDeployed, true, true) + exampleServiceDeployedEvent(newServiceDeployed) + examplesProduced[newServiceDeployed.GetType().Short()] = newServiceDeployed + + // ServicePublished Event producer + newServicePublished, _ := specv04.NewServicePublishedEvent() + setContext(newServicePublished, testSubjectId) + setContextV04(newServicePublished, true, true) + exampleServicePublishedEvent(newServicePublished) + examplesProduced[newServicePublished.GetType().Short()] = newServicePublished + + // ServiceRemoved Event producer + newServiceRemoved, _ := specv04.NewServiceRemovedEvent() + setContext(newServiceRemoved, testSubjectId) + setContextV04(newServiceRemoved, true, true) + exampleServiceRemovedEvent(newServiceRemoved) + examplesProduced[newServiceRemoved.GetType().Short()] = newServiceRemoved + + // ServiceRolledback Event producer + newServiceRolledback, _ := specv04.NewServiceRolledbackEvent() + setContext(newServiceRolledback, testSubjectId) + setContextV04(newServiceRolledback, true, true) + exampleServiceRolledbackEvent(newServiceRolledback) + examplesProduced[newServiceRolledback.GetType().Short()] = newServiceRolledback + + // ServiceUpgraded Event producer + newServiceUpgraded, _ := specv04.NewServiceUpgradedEvent() + setContext(newServiceUpgraded, testSubjectId) + setContextV04(newServiceUpgraded, true, true) + exampleServiceUpgradedEvent(newServiceUpgraded) + examplesProduced[newServiceUpgraded.GetType().Short()] = newServiceUpgraded + + // TaskRunFinished Event producer + newTaskRunFinished, _ := specv04.NewTaskRunFinishedEvent() + setContext(newTaskRunFinished, testSubjectId) + setContextV04(newTaskRunFinished, true, true) + exampleTaskRunFinishedEvent(newTaskRunFinished) + examplesProduced[newTaskRunFinished.GetType().Short()] = newTaskRunFinished + + // TaskRunStarted Event producer + newTaskRunStarted, _ := specv04.NewTaskRunStartedEvent() + setContext(newTaskRunStarted, testSubjectId) + setContextV04(newTaskRunStarted, true, true) + exampleTaskRunStartedEvent(newTaskRunStarted) + examplesProduced[newTaskRunStarted.GetType().Short()] = newTaskRunStarted + + // TestCaseRunFinished Event producer + newTestCaseRunFinished, _ := specv04.NewTestCaseRunFinishedEvent() + setContext(newTestCaseRunFinished, testSubjectId) + setContextV04(newTestCaseRunFinished, true, true) + exampleTestCaseRunFinishedEvent(newTestCaseRunFinished) + examplesProduced[newTestCaseRunFinished.GetType().Short()] = newTestCaseRunFinished + + // TestCaseRunQueued Event producer + newTestCaseRunQueued, _ := specv04.NewTestCaseRunQueuedEvent() + setContext(newTestCaseRunQueued, testSubjectId) + setContextV04(newTestCaseRunQueued, true, true) + exampleTestCaseRunQueuedEvent(newTestCaseRunQueued) + examplesProduced[newTestCaseRunQueued.GetType().Short()] = newTestCaseRunQueued + + // TestCaseRunSkipped Event producer + newTestCaseRunSkipped, _ := specv04.NewTestCaseRunSkippedEvent() + setContext(newTestCaseRunSkipped, testSubjectId) + setContextV04(newTestCaseRunSkipped, true, true) + exampleTestCaseRunSkippedEvent(newTestCaseRunSkipped) + examplesProduced[newTestCaseRunSkipped.GetType().Short()] = newTestCaseRunSkipped + + // TestCaseRunStarted Event producer + newTestCaseRunStarted, _ := specv04.NewTestCaseRunStartedEvent() + setContext(newTestCaseRunStarted, testSubjectId) + setContextV04(newTestCaseRunStarted, true, true) + exampleTestCaseRunStartedEvent(newTestCaseRunStarted) + examplesProduced[newTestCaseRunStarted.GetType().Short()] = newTestCaseRunStarted + + // TestOutputPublished Event producer + newTestOutputPublished, _ := specv04.NewTestOutputPublishedEvent() + setContext(newTestOutputPublished, testSubjectId) + setContextV04(newTestOutputPublished, true, true) + exampleTestOutputPublishedEvent(newTestOutputPublished) + examplesProduced[newTestOutputPublished.GetType().Short()] = newTestOutputPublished + + // TestSuiteRunFinished Event producer + newTestSuiteRunFinished, _ := specv04.NewTestSuiteRunFinishedEvent() + setContext(newTestSuiteRunFinished, testSubjectId) + setContextV04(newTestSuiteRunFinished, true, true) + exampleTestSuiteRunFinishedEvent(newTestSuiteRunFinished) + examplesProduced[newTestSuiteRunFinished.GetType().Short()] = newTestSuiteRunFinished + + // TestSuiteRunQueued Event producer + newTestSuiteRunQueued, _ := specv04.NewTestSuiteRunQueuedEvent() + setContext(newTestSuiteRunQueued, testSubjectId) + setContextV04(newTestSuiteRunQueued, true, true) + exampleTestSuiteRunQueuedEvent(newTestSuiteRunQueued) + examplesProduced[newTestSuiteRunQueued.GetType().Short()] = newTestSuiteRunQueued + + // TestSuiteRunStarted Event producer + newTestSuiteRunStarted, _ := specv04.NewTestSuiteRunStartedEvent() + setContext(newTestSuiteRunStarted, testSubjectId) + setContextV04(newTestSuiteRunStarted, true, true) + exampleTestSuiteRunStartedEvent(newTestSuiteRunStarted) + examplesProduced[newTestSuiteRunStarted.GetType().Short()] = newTestSuiteRunStarted + + // TicketClosed Event producer + newTicketClosed, _ := specv04.NewTicketClosedEvent() + setContext(newTicketClosed, testSubjectId) + setContextV04(newTicketClosed, true, true) + exampleTicketClosedEvent(newTicketClosed) + examplesProduced[newTicketClosed.GetType().Short()] = newTicketClosed + + // TicketCreated Event producer + newTicketCreated, _ := specv04.NewTicketCreatedEvent() + setContext(newTicketCreated, testSubjectId) + setContextV04(newTicketCreated, true, true) + exampleTicketCreatedEvent(newTicketCreated) + examplesProduced[newTicketCreated.GetType().Short()] = newTicketCreated + + // TicketUpdated Event producer + newTicketUpdated, _ := specv04.NewTicketUpdatedEvent() + setContext(newTicketUpdated, testSubjectId) + setContextV04(newTicketUpdated, true, true) + exampleTicketUpdatedEvent(newTicketUpdated) + examplesProduced[newTicketUpdated.GetType().Short()] = newTicketUpdated + +} diff --git a/pkg/api/v04/zz_factory_test.go b/pkg/api/v04/zz_factory_test.go new file mode 100644 index 0000000..c0c515d --- /dev/null +++ b/pkg/api/v04/zz_factory_test.go @@ -0,0 +1,885 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package v04_test + +import ( + "github.com/cdevents/sdk-go/pkg/api" + apiv04 "github.com/cdevents/sdk-go/pkg/api/v04" +) + +func init() { + tests = []testNewCDEventType{} + tests = append(tests, testNewCDEventType{ + name: "artifact deleted", + eventType: apiv04.ArtifactDeletedEventType.String(), + expectedEvent: &apiv04.ArtifactDeletedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ArtifactDeletedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ArtifactDeletedSubject{ + SubjectBase: api.SubjectBase{ + Type: "artifact", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "artifact downloaded", + eventType: apiv04.ArtifactDownloadedEventType.String(), + expectedEvent: &apiv04.ArtifactDownloadedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ArtifactDownloadedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ArtifactDownloadedSubject{ + SubjectBase: api.SubjectBase{ + Type: "artifact", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "artifact packaged", + eventType: apiv04.ArtifactPackagedEventType.String(), + expectedEvent: &apiv04.ArtifactPackagedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ArtifactPackagedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ArtifactPackagedSubject{ + SubjectBase: api.SubjectBase{ + Type: "artifact", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "artifact published", + eventType: apiv04.ArtifactPublishedEventType.String(), + expectedEvent: &apiv04.ArtifactPublishedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ArtifactPublishedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ArtifactPublishedSubject{ + SubjectBase: api.SubjectBase{ + Type: "artifact", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "artifact signed", + eventType: apiv04.ArtifactSignedEventType.String(), + expectedEvent: &apiv04.ArtifactSignedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ArtifactSignedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ArtifactSignedSubject{ + SubjectBase: api.SubjectBase{ + Type: "artifact", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "branch created", + eventType: apiv04.BranchCreatedEventType.String(), + expectedEvent: &apiv04.BranchCreatedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.BranchCreatedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.BranchCreatedSubject{ + SubjectBase: api.SubjectBase{ + Type: "branch", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "branch deleted", + eventType: apiv04.BranchDeletedEventType.String(), + expectedEvent: &apiv04.BranchDeletedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.BranchDeletedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.BranchDeletedSubject{ + SubjectBase: api.SubjectBase{ + Type: "branch", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "build finished", + eventType: apiv04.BuildFinishedEventType.String(), + expectedEvent: &apiv04.BuildFinishedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.BuildFinishedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.BuildFinishedSubject{ + SubjectBase: api.SubjectBase{ + Type: "build", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "build queued", + eventType: apiv04.BuildQueuedEventType.String(), + expectedEvent: &apiv04.BuildQueuedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.BuildQueuedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.BuildQueuedSubject{ + SubjectBase: api.SubjectBase{ + Type: "build", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "build started", + eventType: apiv04.BuildStartedEventType.String(), + expectedEvent: &apiv04.BuildStartedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.BuildStartedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.BuildStartedSubject{ + SubjectBase: api.SubjectBase{ + Type: "build", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "change abandoned", + eventType: apiv04.ChangeAbandonedEventType.String(), + expectedEvent: &apiv04.ChangeAbandonedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ChangeAbandonedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ChangeAbandonedSubject{ + SubjectBase: api.SubjectBase{ + Type: "change", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "change created", + eventType: apiv04.ChangeCreatedEventType.String(), + expectedEvent: &apiv04.ChangeCreatedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ChangeCreatedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ChangeCreatedSubject{ + SubjectBase: api.SubjectBase{ + Type: "change", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "change merged", + eventType: apiv04.ChangeMergedEventType.String(), + expectedEvent: &apiv04.ChangeMergedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ChangeMergedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ChangeMergedSubject{ + SubjectBase: api.SubjectBase{ + Type: "change", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "change reviewed", + eventType: apiv04.ChangeReviewedEventType.String(), + expectedEvent: &apiv04.ChangeReviewedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ChangeReviewedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ChangeReviewedSubject{ + SubjectBase: api.SubjectBase{ + Type: "change", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "change updated", + eventType: apiv04.ChangeUpdatedEventType.String(), + expectedEvent: &apiv04.ChangeUpdatedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ChangeUpdatedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ChangeUpdatedSubject{ + SubjectBase: api.SubjectBase{ + Type: "change", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "environment created", + eventType: apiv04.EnvironmentCreatedEventType.String(), + expectedEvent: &apiv04.EnvironmentCreatedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.EnvironmentCreatedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.EnvironmentCreatedSubject{ + SubjectBase: api.SubjectBase{ + Type: "environment", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "environment deleted", + eventType: apiv04.EnvironmentDeletedEventType.String(), + expectedEvent: &apiv04.EnvironmentDeletedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.EnvironmentDeletedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.EnvironmentDeletedSubject{ + SubjectBase: api.SubjectBase{ + Type: "environment", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "environment modified", + eventType: apiv04.EnvironmentModifiedEventType.String(), + expectedEvent: &apiv04.EnvironmentModifiedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.EnvironmentModifiedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.EnvironmentModifiedSubject{ + SubjectBase: api.SubjectBase{ + Type: "environment", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "incident detected", + eventType: apiv04.IncidentDetectedEventType.String(), + expectedEvent: &apiv04.IncidentDetectedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.IncidentDetectedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.IncidentDetectedSubject{ + SubjectBase: api.SubjectBase{ + Type: "incident", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "incident reported", + eventType: apiv04.IncidentReportedEventType.String(), + expectedEvent: &apiv04.IncidentReportedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.IncidentReportedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.IncidentReportedSubject{ + SubjectBase: api.SubjectBase{ + Type: "incident", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "incident resolved", + eventType: apiv04.IncidentResolvedEventType.String(), + expectedEvent: &apiv04.IncidentResolvedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.IncidentResolvedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.IncidentResolvedSubject{ + SubjectBase: api.SubjectBase{ + Type: "incident", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "pipelinerun finished", + eventType: apiv04.PipelineRunFinishedEventType.String(), + expectedEvent: &apiv04.PipelineRunFinishedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.PipelineRunFinishedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.PipelineRunFinishedSubject{ + SubjectBase: api.SubjectBase{ + Type: "pipelineRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "pipelinerun queued", + eventType: apiv04.PipelineRunQueuedEventType.String(), + expectedEvent: &apiv04.PipelineRunQueuedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.PipelineRunQueuedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.PipelineRunQueuedSubject{ + SubjectBase: api.SubjectBase{ + Type: "pipelineRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "pipelinerun started", + eventType: apiv04.PipelineRunStartedEventType.String(), + expectedEvent: &apiv04.PipelineRunStartedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.PipelineRunStartedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.PipelineRunStartedSubject{ + SubjectBase: api.SubjectBase{ + Type: "pipelineRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "repository created", + eventType: apiv04.RepositoryCreatedEventType.String(), + expectedEvent: &apiv04.RepositoryCreatedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.RepositoryCreatedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.RepositoryCreatedSubject{ + SubjectBase: api.SubjectBase{ + Type: "repository", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "repository deleted", + eventType: apiv04.RepositoryDeletedEventType.String(), + expectedEvent: &apiv04.RepositoryDeletedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.RepositoryDeletedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.RepositoryDeletedSubject{ + SubjectBase: api.SubjectBase{ + Type: "repository", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "repository modified", + eventType: apiv04.RepositoryModifiedEventType.String(), + expectedEvent: &apiv04.RepositoryModifiedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.RepositoryModifiedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.RepositoryModifiedSubject{ + SubjectBase: api.SubjectBase{ + Type: "repository", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "service deployed", + eventType: apiv04.ServiceDeployedEventType.String(), + expectedEvent: &apiv04.ServiceDeployedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ServiceDeployedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ServiceDeployedSubject{ + SubjectBase: api.SubjectBase{ + Type: "service", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "service published", + eventType: apiv04.ServicePublishedEventType.String(), + expectedEvent: &apiv04.ServicePublishedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ServicePublishedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ServicePublishedSubject{ + SubjectBase: api.SubjectBase{ + Type: "service", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "service removed", + eventType: apiv04.ServiceRemovedEventType.String(), + expectedEvent: &apiv04.ServiceRemovedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ServiceRemovedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ServiceRemovedSubject{ + SubjectBase: api.SubjectBase{ + Type: "service", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "service rolledback", + eventType: apiv04.ServiceRolledbackEventType.String(), + expectedEvent: &apiv04.ServiceRolledbackEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ServiceRolledbackEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ServiceRolledbackSubject{ + SubjectBase: api.SubjectBase{ + Type: "service", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "service upgraded", + eventType: apiv04.ServiceUpgradedEventType.String(), + expectedEvent: &apiv04.ServiceUpgradedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.ServiceUpgradedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.ServiceUpgradedSubject{ + SubjectBase: api.SubjectBase{ + Type: "service", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "taskrun finished", + eventType: apiv04.TaskRunFinishedEventType.String(), + expectedEvent: &apiv04.TaskRunFinishedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TaskRunFinishedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TaskRunFinishedSubject{ + SubjectBase: api.SubjectBase{ + Type: "taskRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "taskrun started", + eventType: apiv04.TaskRunStartedEventType.String(), + expectedEvent: &apiv04.TaskRunStartedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TaskRunStartedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TaskRunStartedSubject{ + SubjectBase: api.SubjectBase{ + Type: "taskRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "testcaserun finished", + eventType: apiv04.TestCaseRunFinishedEventType.String(), + expectedEvent: &apiv04.TestCaseRunFinishedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TestCaseRunFinishedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TestCaseRunFinishedSubject{ + SubjectBase: api.SubjectBase{ + Type: "testCaseRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "testcaserun queued", + eventType: apiv04.TestCaseRunQueuedEventType.String(), + expectedEvent: &apiv04.TestCaseRunQueuedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TestCaseRunQueuedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TestCaseRunQueuedSubject{ + SubjectBase: api.SubjectBase{ + Type: "testCaseRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "testcaserun skipped", + eventType: apiv04.TestCaseRunSkippedEventType.String(), + expectedEvent: &apiv04.TestCaseRunSkippedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TestCaseRunSkippedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TestCaseRunSkippedSubject{ + SubjectBase: api.SubjectBase{ + Type: "testCaseRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "testcaserun started", + eventType: apiv04.TestCaseRunStartedEventType.String(), + expectedEvent: &apiv04.TestCaseRunStartedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TestCaseRunStartedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TestCaseRunStartedSubject{ + SubjectBase: api.SubjectBase{ + Type: "testCaseRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "testoutput published", + eventType: apiv04.TestOutputPublishedEventType.String(), + expectedEvent: &apiv04.TestOutputPublishedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TestOutputPublishedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TestOutputPublishedSubject{ + SubjectBase: api.SubjectBase{ + Type: "testOutput", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "testsuiterun finished", + eventType: apiv04.TestSuiteRunFinishedEventType.String(), + expectedEvent: &apiv04.TestSuiteRunFinishedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TestSuiteRunFinishedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TestSuiteRunFinishedSubject{ + SubjectBase: api.SubjectBase{ + Type: "testSuiteRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "testsuiterun queued", + eventType: apiv04.TestSuiteRunQueuedEventType.String(), + expectedEvent: &apiv04.TestSuiteRunQueuedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TestSuiteRunQueuedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TestSuiteRunQueuedSubject{ + SubjectBase: api.SubjectBase{ + Type: "testSuiteRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "testsuiterun started", + eventType: apiv04.TestSuiteRunStartedEventType.String(), + expectedEvent: &apiv04.TestSuiteRunStartedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TestSuiteRunStartedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TestSuiteRunStartedSubject{ + SubjectBase: api.SubjectBase{ + Type: "testSuiteRun", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "ticket closed", + eventType: apiv04.TicketClosedEventType.String(), + expectedEvent: &apiv04.TicketClosedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TicketClosedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TicketClosedSubject{ + SubjectBase: api.SubjectBase{ + Type: "ticket", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "ticket created", + eventType: apiv04.TicketCreatedEventType.String(), + expectedEvent: &apiv04.TicketCreatedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TicketCreatedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TicketCreatedSubject{ + SubjectBase: api.SubjectBase{ + Type: "ticket", + }, + }, + }, + }) + tests = append(tests, testNewCDEventType{ + name: "ticket updated", + eventType: apiv04.TicketUpdatedEventType.String(), + expectedEvent: &apiv04.TicketUpdatedEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.TicketUpdatedEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.TicketUpdatedSubject{ + SubjectBase: api.SubjectBase{ + Type: "ticket", + }, + }, + }, + }) +} diff --git a/pkg/api/v04/zz_shared_test.go b/pkg/api/v04/zz_shared_test.go new file mode 100644 index 0000000..5833ea6 --- /dev/null +++ b/pkg/api/v04/zz_shared_test.go @@ -0,0 +1,92 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package v04_test + +import "github.com/cdevents/sdk-go/pkg/api" + +func panicOnError(err error) { + if err != nil { + panic(err.Error()) + } +} + +type testData struct { + TestValues []map[string]string `json:"testValues"` +} + +var ( + // Examples Data + testSource = "/event/source/123" + testSubjectId = "mySubject123" + testValue = "testValue" + testArtifactId = "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" + testDataJson = testData{TestValues: []map[string]string{{"k1": "v1"}, {"k2": "v2"}}} + testDataJsonUnmarshalled = map[string]any{ + "testValues": []any{map[string]any{"k1": string("v1")}, map[string]any{"k2": string("v2")}}, + } + testDataXml = []byte("testData") + testChangeId = "myChange123" + + // V04+ Examples Data + testChainId = "4c8cb7dd-3448-41de-8768-eec704e2829b" + testLinks api.EmbeddedLinksArray + testContextId = "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + testSchemaUri = "https://myorg.com/schema/custom" +) + +func init() { + // Set up test links + tags := api.Tags{ + "foo1": "bar", + "foo2": "bar", + } + reference := api.EventReference{ + ContextId: testContextId, + } + elr := api.NewEmbeddedLinkRelation() + elr.SetTags(tags) + elr.SetLinkKind("TRIGGER") + elr.SetTarget(reference) + elp := api.NewEmbeddedLinkPath() + elp.SetTags(tags) + elp.SetFrom(reference) + ele := api.NewEmbeddedLinkEnd() + ele.SetTags(tags) + ele.SetFrom(reference) + testLinks = api.EmbeddedLinksArray{ + elr, elp, ele, + } +} + +func setContext(event api.CDEventWriter, subjectId string) { + event.SetSource(testSource) + event.SetSubjectId(subjectId) +} + +func setContextV04(event api.CDEventWriterV04, chainId, schemaUri bool) { + if chainId { + event.SetChainId(testChainId) + } + if schemaUri { + event.SetSchemaUri(testSchemaUri) + } + event.SetLinks(testLinks) +} diff --git a/pkg/api/v990/docs.go b/pkg/api/v990/docs.go index 11d8e4b..e25c151 100644 --- a/pkg/api/v990/docs.go +++ b/pkg/api/v990/docs.go @@ -30,20 +30,26 @@ import "github.com/cdevents/sdk-go/pkg/api" var SpecVersion = "99.0.0" type FooSubjectBarPredicateEvent = api.FooSubjectBarPredicateEventV1_2_3 +type FooSubjectBarPredicateSubject = api.FooSubjectBarPredicateSubjectV1_2_3 + +// FooSubjectFooSubjectSubjectContentObjectFieldV1_2_3 holds the content of a ObjectField field in the content +type FooSubjectBarPredicateSubjectContentObjectField = api.FooSubjectBarPredicateSubjectContentObjectFieldV1_2_3 func NewFooSubjectBarPredicateEvent() (*FooSubjectBarPredicateEvent, error) { return api.NewFooSubjectBarPredicateEventV1_2_3(SpecVersion) } +var FooSubjectBarPredicateEventType = api.FooSubjectBarPredicateEventTypeV1_2_3 + // NewFromJsonBytes builds a new CDEventReader from a JSON string as []bytes // This works by unmarshalling the context first, extracting the event type and using // that to unmarshal the rest of the event into the correct object. // It assumes the context can be unmarshalled in a `Context` object. -func NewFromJsonBytes(event []byte) (api.CDEvent, error) { - return api.NewFromJsonBytesContext[api.Context](event, CDEventsByUnversionedTypes) +func NewFromJsonBytes(event []byte) (api.CDEventV04, error) { + return api.NewFromJsonBytesContext[api.CDEventV04](event, CDEventsByUnversionedTypes) } // Build a new CDEventReader from a JSON string -func NewFromJsonString(event string) (api.CDEvent, error) { +func NewFromJsonString(event string) (api.CDEventV04, error) { return NewFromJsonBytes([]byte(event)) } diff --git a/pkg/api/v990/types.go b/pkg/api/v990/types.go index 778f91f..6dfa657 100644 --- a/pkg/api/v990/types.go +++ b/pkg/api/v990/types.go @@ -28,15 +28,15 @@ import ( "github.com/cdevents/sdk-go/pkg/api" ) -var CDEventsTypes = []api.CDEvent{ +var CDEventsTypes = []api.CDEventV04{ &FooSubjectBarPredicateEvent{}, } -var CDEventsByUnversionedTypes map[string]api.CDEvent +var CDEventsByUnversionedTypes map[string]api.CDEventV04 func init() { // Set up CDEventsByUnversionedTypes for convenience - CDEventsByUnversionedTypes = make(map[string]api.CDEvent) + CDEventsByUnversionedTypes = make(map[string]api.CDEventV04) for _, event := range CDEventsTypes { CDEventsByUnversionedTypes[event.GetType().UnversionedString()] = event } diff --git a/pkg/api/v991/docs.go b/pkg/api/v991/docs.go new file mode 100644 index 0000000..bdf934c --- /dev/null +++ b/pkg/api/v991/docs.go @@ -0,0 +1,55 @@ +// Code generated by tools/generator. DO NOT EDIT. + +//go:build testonly + +/* +Copyright 2024 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +// Package v03 contains method to create events that belong to the +// CDEvents specification v99.1.x + +package v991 + +import "github.com/cdevents/sdk-go/pkg/api" + +var SpecVersion = "99.1.0" + +type FooSubjectBarPredicateEvent = api.FooSubjectBarPredicateEventV2_2_3 +type FooSubjectBarPredicateSubject = api.FooSubjectBarPredicateSubjectV2_2_3 + +// FooSubjectFooSubjectSubjectContentObjectFieldV2_2_3 holds the content of a ObjectField field in the content +type FooSubjectBarPredicateSubjectContentObjectField = api.FooSubjectBarPredicateSubjectContentObjectFieldV2_2_3 + +func NewFooSubjectBarPredicateEvent() (*FooSubjectBarPredicateEvent, error) { + return api.NewFooSubjectBarPredicateEventV2_2_3(SpecVersion) +} + +var FooSubjectBarPredicateEventType = api.FooSubjectBarPredicateEventTypeV2_2_3 + +// NewFromJsonBytes builds a new CDEventReader from a JSON string as []bytes +// This works by unmarshalling the context first, extracting the event type and using +// that to unmarshal the rest of the event into the correct object. +// It assumes the context can be unmarshalled in a `Context` object. +func NewFromJsonBytes(event []byte) (api.CDEventV04, error) { + return api.NewFromJsonBytesContext[api.CDEventV04](event, CDEventsByUnversionedTypes) +} + +// Build a new CDEventReader from a JSON string +func NewFromJsonString(event string) (api.CDEventV04, error) { + return NewFromJsonBytes([]byte(event)) +} diff --git a/pkg/api/v991/types.go b/pkg/api/v991/types.go new file mode 100644 index 0000000..715b996 --- /dev/null +++ b/pkg/api/v991/types.go @@ -0,0 +1,54 @@ +// Code generated by tools/generator. DO NOT EDIT. + +//go:build testonly + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package v991 + +import ( + "fmt" + + "github.com/cdevents/sdk-go/pkg/api" +) + +var CDEventsTypes = []api.CDEventV04{ + &FooSubjectBarPredicateEvent{}, +} + +var CDEventsByUnversionedTypes map[string]api.CDEventV04 + +func init() { + // Set up CDEventsByUnversionedTypes for convenience + CDEventsByUnversionedTypes = make(map[string]api.CDEventV04) + for _, event := range CDEventsTypes { + CDEventsByUnversionedTypes[event.GetType().UnversionedString()] = event + } +} + +// NewCDEvent produces a CDEvent by type +// This function can be used by users but it's meant mainly for testing purposes +func NewCDEvent(eventType, specVersion string) (api.CDEvent, error) { + switch eventType { + case api.FooSubjectBarPredicateEventTypeV2_2_3.String(): + return NewFooSubjectBarPredicateEvent() + default: + return nil, fmt.Errorf("event %v not supported", eventType) + } +} diff --git a/pkg/api/ztest_schemas.go b/pkg/api/ztest_schemas.go new file mode 100644 index 0000000..4a6fcfa --- /dev/null +++ b/pkg/api/ztest_schemas.go @@ -0,0 +1,371 @@ +// Code generated by tools/generator. DO NOT EDIT. + +//go:build testonly + +/* +Copyright 2024 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "encoding/json" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // All compiled schemas by Id + TestCompiledSchemas SchemaDB + + // All schemas as string by Id + TestSchemasById = map[string]string{ + "https://cdevents.dev/99.0.0/schema/foosubject-barpredicate-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/99.0.0/schema/foosubject-barpredicate-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.foosubject.barpredicate.1.2.3" + ], + "default": "dev.cdevents.foosubject.barpredicate.1.2.3" + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "fooSubject" + ], + "default": "fooSubject" + }, + "content": { + "properties": { + "plainField": { + "type": "string", + "minLength": 1 + }, + "referenceField": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string" + }, + "objectField": { + "properties": { + "required": { + "type": "string", + "minLength": 1 + }, + "optional": { + "type": "string", + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "required" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "plainField", + "referenceField" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + "https://cdevents.dev/99.1.0/schema/foosubject-barpredicate-event": `{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://cdevents.dev/99.1.0/schema/foosubject-barpredicate-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "enum": [ + "dev.cdevents.foosubject.barpredicate.2.2.3" + ], + "default": "dev.cdevents.foosubject.barpredicate.2.2.3" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "schemaUri": { + "type": "string", + "minLength": 1, + "format": "uri" + }, + "chainId": { + "type": "string", + "minLength": 1 + }, + "links": { + "$ref": "https://cdevents.dev/0.4.1/schema/links/embeddedlinksarray" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + }, + "type": { + "type": "string", + "minLength": 1, + "enum": [ + "fooSubject" + ], + "default": "fooSubject" + }, + "content": { + "properties": { + "plainField": { + "type": "string", + "minLength": 1 + }, + "referenceField": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1, + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id" + ] + }, + "artifactId": { + "type": "string" + }, + "objectField": { + "properties": { + "required": { + "type": "string", + "minLength": 1 + }, + "optional": { + "type": "string", + "format": "uri-reference" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "required" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "plainField", + "referenceField" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + }, + "customData": { + "oneOf": [ + { + "type": "object" + }, + { + "type": "string", + "contentEncoding": "base64" + } + ] + }, + "customDataContentType": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +}`, + } +) + +func init() { + compiler, err := newTestJsonSchemaCompiler() + panicOnError(err) + TestCompiledSchemas = make(map[string]*jsonschema.Schema) + // For tests load non-test schemas first to cover links and custom + for url, _ := range SchemasById { + sch, err := compiler.Compile(url) + panicOnError(err) + TestCompiledSchemas[url] = sch + } + for url, _ := range TestSchemasById { + sch, err := compiler.Compile(url) + panicOnError(err) + TestCompiledSchemas[url] = sch + } +} + +func newTestJsonSchemaCompiler() (*jsonschema.Compiler, error) { + c, err := newJsonSchemaCompiler() + if err != nil { + return nil, err + } + for url, content := range TestSchemasById { + var loaded map[string]interface{} + err := json.Unmarshal([]byte(content), &loaded) + if err != nil { + return nil, err + } + if err := c.AddResource(url, loaded); err != nil { + return nil, err + } + } + return c, nil +} diff --git a/pkg/api/zz_artifactdeleted_0_1_0.go b/pkg/api/zz_artifactdeleted_0_1_0.go new file mode 100644 index 0000000..2340164 --- /dev/null +++ b/pkg/api/zz_artifactdeleted_0_1_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ArtifactDeleted event type v0.1.0 + ArtifactDeletedEventTypeV0_1_0 CDEventType = CDEventType{ + Subject: "artifact", + Predicate: "deleted", + Version: "0.1.0", + } +) + +type ArtifactDeletedSubjectContentV0_1_0 struct { + User string `json:"user,omitempty"` +} + +type ArtifactDeletedSubjectV0_1_0 struct { + SubjectBase + Content ArtifactDeletedSubjectContentV0_1_0 `json:"content"` +} + +func (sc ArtifactDeletedSubjectV0_1_0) GetSubjectType() SubjectType { + return "artifact" +} + +type ArtifactDeletedEventV0_1_0 struct { + Context ContextV04 `json:"context"` + Subject ArtifactDeletedSubjectV0_1_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ArtifactDeletedEventV0_1_0) GetType() CDEventType { + return ArtifactDeletedEventTypeV0_1_0 +} + +func (e ArtifactDeletedEventV0_1_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ArtifactDeletedEventV0_1_0) GetId() string { + return e.Context.Id +} + +func (e ArtifactDeletedEventV0_1_0) GetSource() string { + return e.Context.Source +} + +func (e ArtifactDeletedEventV0_1_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ArtifactDeletedEventV0_1_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ArtifactDeletedEventV0_1_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ArtifactDeletedEventV0_1_0) GetSubject() Subject { + return e.Subject +} + +func (e ArtifactDeletedEventV0_1_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ArtifactDeletedEventV0_1_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ArtifactDeletedEventV0_1_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ArtifactDeletedEventV0_1_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ArtifactDeletedEventV0_1_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ArtifactDeletedEventV0_1_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ArtifactDeletedEventV0_1_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ArtifactDeletedEventV0_1_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ArtifactDeletedEventV0_1_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ArtifactDeletedEventV0_1_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ArtifactDeletedEventV0_1_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ArtifactDeletedEventV0_1_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ArtifactDeletedEventV0_1_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ArtifactDeletedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ArtifactDeletedEventV0_1_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ArtifactDeletedEventV0_1_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ArtifactDeletedEventV0_1_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ArtifactDeletedEventV0_1_0) SetSubjectUser(user string) { + e.Subject.Content.User = user +} + +// New creates a new ArtifactDeletedEventV0_1_0 +func NewArtifactDeletedEventV0_1_0(specVersion string) (*ArtifactDeletedEventV0_1_0, error) { + e := &ArtifactDeletedEventV0_1_0{ + Context: ContextV04{ + Context{ + Type: ArtifactDeletedEventTypeV0_1_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ArtifactDeletedSubjectV0_1_0{ + SubjectBase: SubjectBase{ + Type: "artifact", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_artifactdownloaded_0_1_0.go b/pkg/api/zz_artifactdownloaded_0_1_0.go new file mode 100644 index 0000000..87746f7 --- /dev/null +++ b/pkg/api/zz_artifactdownloaded_0_1_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ArtifactDownloaded event type v0.1.0 + ArtifactDownloadedEventTypeV0_1_0 CDEventType = CDEventType{ + Subject: "artifact", + Predicate: "downloaded", + Version: "0.1.0", + } +) + +type ArtifactDownloadedSubjectContentV0_1_0 struct { + User string `json:"user,omitempty"` +} + +type ArtifactDownloadedSubjectV0_1_0 struct { + SubjectBase + Content ArtifactDownloadedSubjectContentV0_1_0 `json:"content"` +} + +func (sc ArtifactDownloadedSubjectV0_1_0) GetSubjectType() SubjectType { + return "artifact" +} + +type ArtifactDownloadedEventV0_1_0 struct { + Context ContextV04 `json:"context"` + Subject ArtifactDownloadedSubjectV0_1_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ArtifactDownloadedEventV0_1_0) GetType() CDEventType { + return ArtifactDownloadedEventTypeV0_1_0 +} + +func (e ArtifactDownloadedEventV0_1_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ArtifactDownloadedEventV0_1_0) GetId() string { + return e.Context.Id +} + +func (e ArtifactDownloadedEventV0_1_0) GetSource() string { + return e.Context.Source +} + +func (e ArtifactDownloadedEventV0_1_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ArtifactDownloadedEventV0_1_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ArtifactDownloadedEventV0_1_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ArtifactDownloadedEventV0_1_0) GetSubject() Subject { + return e.Subject +} + +func (e ArtifactDownloadedEventV0_1_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ArtifactDownloadedEventV0_1_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ArtifactDownloadedEventV0_1_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ArtifactDownloadedEventV0_1_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ArtifactDownloadedEventV0_1_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ArtifactDownloadedEventV0_1_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ArtifactDownloadedEventV0_1_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ArtifactDownloadedEventV0_1_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ArtifactDownloadedEventV0_1_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ArtifactDownloadedEventV0_1_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ArtifactDownloadedEventV0_1_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ArtifactDownloadedEventV0_1_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ArtifactDownloadedEventV0_1_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ArtifactDownloadedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ArtifactDownloadedEventV0_1_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ArtifactDownloadedEventV0_1_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ArtifactDownloadedEventV0_1_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ArtifactDownloadedEventV0_1_0) SetSubjectUser(user string) { + e.Subject.Content.User = user +} + +// New creates a new ArtifactDownloadedEventV0_1_0 +func NewArtifactDownloadedEventV0_1_0(specVersion string) (*ArtifactDownloadedEventV0_1_0, error) { + e := &ArtifactDownloadedEventV0_1_0{ + Context: ContextV04{ + Context{ + Type: ArtifactDownloadedEventTypeV0_1_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ArtifactDownloadedSubjectV0_1_0{ + SubjectBase: SubjectBase{ + Type: "artifact", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_artifactpackaged_0_1_1.go b/pkg/api/zz_artifactpackaged_0_1_1.go index e05ee02..2762da8 100644 --- a/pkg/api/zz_artifactpackaged_0_1_1.go +++ b/pkg/api/zz_artifactpackaged_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var artifactpackagedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/artifact-packaged-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.artifact.packaged.0.1.1"],"default":"dev.cdevents.artifact.packaged.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["artifact"],"default":"artifact"},"content":{"properties":{"change":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object","required":["change"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ArtifactPackaged event type v0.1.1 @@ -36,22 +35,22 @@ var ( } ) -type ArtifactPackagedSubjectContent struct { +type ArtifactPackagedSubjectContentV0_1_1 struct { Change *Reference `json:"change"` } -type ArtifactPackagedSubject struct { +type ArtifactPackagedSubjectV0_1_1 struct { SubjectBase - Content ArtifactPackagedSubjectContent `json:"content"` + Content ArtifactPackagedSubjectContentV0_1_1 `json:"content"` } -func (sc ArtifactPackagedSubject) GetSubjectType() SubjectType { +func (sc ArtifactPackagedSubjectV0_1_1) GetSubjectType() SubjectType { return "artifact" } type ArtifactPackagedEventV0_1_1 struct { - Context Context `json:"context"` - Subject ArtifactPackagedSubject `json:"subject"` + Context Context `json:"context"` + Subject ArtifactPackagedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *ArtifactPackagedEventV0_1_1) SetCustomData(contentType string, data int return nil } -func (e ArtifactPackagedEventV0_1_1) GetSchema() (string, string) { +func (e ArtifactPackagedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), artifactpackagedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewArtifactPackagedEventV0_1_1(specVersion string) (*ArtifactPackagedEventV Type: ArtifactPackagedEventTypeV0_1_1, Version: specVersion, }, - Subject: ArtifactPackagedSubject{ + Subject: ArtifactPackagedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "artifact", }, diff --git a/pkg/api/zz_artifactpackaged_0_2_0.go b/pkg/api/zz_artifactpackaged_0_2_0.go new file mode 100644 index 0000000..5a21e3d --- /dev/null +++ b/pkg/api/zz_artifactpackaged_0_2_0.go @@ -0,0 +1,215 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ArtifactPackaged event type v0.2.0 + ArtifactPackagedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "artifact", + Predicate: "packaged", + Version: "0.2.0", + } +) + +type ArtifactPackagedSubjectContentV0_2_0 struct { + Change *Reference `json:"change"` + + Sbom *ArtifactPackagedSubjectContentSbomV0_2_0 `json:"sbom,omitempty"` +} + +type ArtifactPackagedSubjectV0_2_0 struct { + SubjectBase + Content ArtifactPackagedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ArtifactPackagedSubjectV0_2_0) GetSubjectType() SubjectType { + return "artifact" +} + +type ArtifactPackagedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ArtifactPackagedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ArtifactPackagedEventV0_2_0) GetType() CDEventType { + return ArtifactPackagedEventTypeV0_2_0 +} + +func (e ArtifactPackagedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ArtifactPackagedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ArtifactPackagedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ArtifactPackagedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ArtifactPackagedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ArtifactPackagedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ArtifactPackagedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ArtifactPackagedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ArtifactPackagedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ArtifactPackagedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ArtifactPackagedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ArtifactPackagedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ArtifactPackagedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ArtifactPackagedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ArtifactPackagedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ArtifactPackagedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ArtifactPackagedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ArtifactPackagedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ArtifactPackagedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ArtifactPackagedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ArtifactPackagedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ArtifactPackagedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ArtifactPackagedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ArtifactPackagedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ArtifactPackagedEventV0_2_0) SetSubjectChange(change *Reference) { + e.Subject.Content.Change = change +} + +func (e *ArtifactPackagedEventV0_2_0) SetSubjectSbom(sbom *ArtifactPackagedSubjectContentSbomV0_2_0) { + e.Subject.Content.Sbom = sbom +} + +// New creates a new ArtifactPackagedEventV0_2_0 +func NewArtifactPackagedEventV0_2_0(specVersion string) (*ArtifactPackagedEventV0_2_0, error) { + e := &ArtifactPackagedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ArtifactPackagedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ArtifactPackagedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "artifact", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} + +// ArtifactPackagedSubjectContentSbomV0_2_0 holds the content of a Sbom field in the content +type ArtifactPackagedSubjectContentSbomV0_2_0 struct { + Uri string `json:"uri"` +} diff --git a/pkg/api/zz_artifactpublished_0_1_1.go b/pkg/api/zz_artifactpublished_0_1_1.go index dfd03d3..7e1e12e 100644 --- a/pkg/api/zz_artifactpublished_0_1_1.go +++ b/pkg/api/zz_artifactpublished_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var artifactpublishedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/artifact-published-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.artifact.published.0.1.1"],"default":"dev.cdevents.artifact.published.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["artifact"],"default":"artifact"},"content":{"properties":{},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ArtifactPublished event type v0.1.1 @@ -36,21 +35,21 @@ var ( } ) -type ArtifactPublishedSubjectContent struct { +type ArtifactPublishedSubjectContentV0_1_1 struct { } -type ArtifactPublishedSubject struct { +type ArtifactPublishedSubjectV0_1_1 struct { SubjectBase - Content ArtifactPublishedSubjectContent `json:"content"` + Content ArtifactPublishedSubjectContentV0_1_1 `json:"content"` } -func (sc ArtifactPublishedSubject) GetSubjectType() SubjectType { +func (sc ArtifactPublishedSubjectV0_1_1) GetSubjectType() SubjectType { return "artifact" } type ArtifactPublishedEventV0_1_1 struct { - Context Context `json:"context"` - Subject ArtifactPublishedSubject `json:"subject"` + Context Context `json:"context"` + Subject ArtifactPublishedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -140,9 +139,9 @@ func (e *ArtifactPublishedEventV0_1_1) SetCustomData(contentType string, data in return nil } -func (e ArtifactPublishedEventV0_1_1) GetSchema() (string, string) { +func (e ArtifactPublishedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), artifactpublishedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -154,7 +153,7 @@ func NewArtifactPublishedEventV0_1_1(specVersion string) (*ArtifactPublishedEven Type: ArtifactPublishedEventTypeV0_1_1, Version: specVersion, }, - Subject: ArtifactPublishedSubject{ + Subject: ArtifactPublishedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "artifact", }, diff --git a/pkg/api/zz_artifactpublished_0_2_0.go b/pkg/api/zz_artifactpublished_0_2_0.go new file mode 100644 index 0000000..bb13ebb --- /dev/null +++ b/pkg/api/zz_artifactpublished_0_2_0.go @@ -0,0 +1,215 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ArtifactPublished event type v0.2.0 + ArtifactPublishedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "artifact", + Predicate: "published", + Version: "0.2.0", + } +) + +type ArtifactPublishedSubjectContentV0_2_0 struct { + Sbom *ArtifactPublishedSubjectContentSbomV0_2_0 `json:"sbom,omitempty"` + + User string `json:"user,omitempty"` +} + +type ArtifactPublishedSubjectV0_2_0 struct { + SubjectBase + Content ArtifactPublishedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ArtifactPublishedSubjectV0_2_0) GetSubjectType() SubjectType { + return "artifact" +} + +type ArtifactPublishedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ArtifactPublishedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ArtifactPublishedEventV0_2_0) GetType() CDEventType { + return ArtifactPublishedEventTypeV0_2_0 +} + +func (e ArtifactPublishedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ArtifactPublishedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ArtifactPublishedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ArtifactPublishedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ArtifactPublishedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ArtifactPublishedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ArtifactPublishedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ArtifactPublishedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ArtifactPublishedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ArtifactPublishedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ArtifactPublishedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ArtifactPublishedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ArtifactPublishedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ArtifactPublishedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ArtifactPublishedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ArtifactPublishedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ArtifactPublishedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ArtifactPublishedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ArtifactPublishedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ArtifactPublishedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ArtifactPublishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ArtifactPublishedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ArtifactPublishedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ArtifactPublishedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ArtifactPublishedEventV0_2_0) SetSubjectSbom(sbom *ArtifactPublishedSubjectContentSbomV0_2_0) { + e.Subject.Content.Sbom = sbom +} + +func (e *ArtifactPublishedEventV0_2_0) SetSubjectUser(user string) { + e.Subject.Content.User = user +} + +// New creates a new ArtifactPublishedEventV0_2_0 +func NewArtifactPublishedEventV0_2_0(specVersion string) (*ArtifactPublishedEventV0_2_0, error) { + e := &ArtifactPublishedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ArtifactPublishedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ArtifactPublishedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "artifact", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} + +// ArtifactPublishedSubjectContentSbomV0_2_0 holds the content of a Sbom field in the content +type ArtifactPublishedSubjectContentSbomV0_2_0 struct { + Uri string `json:"uri"` +} diff --git a/pkg/api/zz_artifactsigned_0_1_0.go b/pkg/api/zz_artifactsigned_0_1_0.go index 4c4c9cf..9590543 100644 --- a/pkg/api/zz_artifactsigned_0_1_0.go +++ b/pkg/api/zz_artifactsigned_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var artifactsignedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/artifact-signed-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.artifact.signed.0.1.0"],"default":"dev.cdevents.artifact.signed.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["artifact"],"default":"artifact"},"content":{"properties":{"signature":{"type":"string","minLength":1}},"additionalProperties":false,"type":"object","required":["signature"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ArtifactSigned event type v0.1.0 @@ -36,22 +35,22 @@ var ( } ) -type ArtifactSignedSubjectContent struct { +type ArtifactSignedSubjectContentV0_1_0 struct { Signature string `json:"signature"` } -type ArtifactSignedSubject struct { +type ArtifactSignedSubjectV0_1_0 struct { SubjectBase - Content ArtifactSignedSubjectContent `json:"content"` + Content ArtifactSignedSubjectContentV0_1_0 `json:"content"` } -func (sc ArtifactSignedSubject) GetSubjectType() SubjectType { +func (sc ArtifactSignedSubjectV0_1_0) GetSubjectType() SubjectType { return "artifact" } type ArtifactSignedEventV0_1_0 struct { - Context Context `json:"context"` - Subject ArtifactSignedSubject `json:"subject"` + Context Context `json:"context"` + Subject ArtifactSignedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *ArtifactSignedEventV0_1_0) SetCustomData(contentType string, data inter return nil } -func (e ArtifactSignedEventV0_1_0) GetSchema() (string, string) { +func (e ArtifactSignedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), artifactsignedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewArtifactSignedEventV0_1_0(specVersion string) (*ArtifactSignedEventV0_1_ Type: ArtifactSignedEventTypeV0_1_0, Version: specVersion, }, - Subject: ArtifactSignedSubject{ + Subject: ArtifactSignedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "artifact", }, diff --git a/pkg/api/zz_artifactsigned_0_2_0.go b/pkg/api/zz_artifactsigned_0_2_0.go new file mode 100644 index 0000000..d8ed4d2 --- /dev/null +++ b/pkg/api/zz_artifactsigned_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ArtifactSigned event type v0.2.0 + ArtifactSignedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "artifact", + Predicate: "signed", + Version: "0.2.0", + } +) + +type ArtifactSignedSubjectContentV0_2_0 struct { + Signature string `json:"signature"` +} + +type ArtifactSignedSubjectV0_2_0 struct { + SubjectBase + Content ArtifactSignedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ArtifactSignedSubjectV0_2_0) GetSubjectType() SubjectType { + return "artifact" +} + +type ArtifactSignedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ArtifactSignedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ArtifactSignedEventV0_2_0) GetType() CDEventType { + return ArtifactSignedEventTypeV0_2_0 +} + +func (e ArtifactSignedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ArtifactSignedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ArtifactSignedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ArtifactSignedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ArtifactSignedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ArtifactSignedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ArtifactSignedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ArtifactSignedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ArtifactSignedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ArtifactSignedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ArtifactSignedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ArtifactSignedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ArtifactSignedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ArtifactSignedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ArtifactSignedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ArtifactSignedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ArtifactSignedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ArtifactSignedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ArtifactSignedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ArtifactSignedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ArtifactSignedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ArtifactSignedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ArtifactSignedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ArtifactSignedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ArtifactSignedEventV0_2_0) SetSubjectSignature(signature string) { + e.Subject.Content.Signature = signature +} + +// New creates a new ArtifactSignedEventV0_2_0 +func NewArtifactSignedEventV0_2_0(specVersion string) (*ArtifactSignedEventV0_2_0, error) { + e := &ArtifactSignedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ArtifactSignedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ArtifactSignedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "artifact", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_branchcreated_0_1_2.go b/pkg/api/zz_branchcreated_0_1_2.go index afd3ff8..15a6886 100644 --- a/pkg/api/zz_branchcreated_0_1_2.go +++ b/pkg/api/zz_branchcreated_0_1_2.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var branchcreatedschema0_1_2 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/branch-created-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.branch.created.0.1.2"],"default":"dev.cdevents.branch.created.0.1.2"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["branch"],"default":"branch"},"content":{"properties":{"repository":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // BranchCreated event type v0.1.2 @@ -36,22 +35,22 @@ var ( } ) -type BranchCreatedSubjectContent struct { +type BranchCreatedSubjectContentV0_1_2 struct { Repository *Reference `json:"repository,omitempty"` } -type BranchCreatedSubject struct { +type BranchCreatedSubjectV0_1_2 struct { SubjectBase - Content BranchCreatedSubjectContent `json:"content"` + Content BranchCreatedSubjectContentV0_1_2 `json:"content"` } -func (sc BranchCreatedSubject) GetSubjectType() SubjectType { +func (sc BranchCreatedSubjectV0_1_2) GetSubjectType() SubjectType { return "branch" } type BranchCreatedEventV0_1_2 struct { - Context Context `json:"context"` - Subject BranchCreatedSubject `json:"subject"` + Context Context `json:"context"` + Subject BranchCreatedSubjectV0_1_2 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *BranchCreatedEventV0_1_2) SetCustomData(contentType string, data interf return nil } -func (e BranchCreatedEventV0_1_2) GetSchema() (string, string) { +func (e BranchCreatedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), branchcreatedschema0_1_2 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewBranchCreatedEventV0_1_2(specVersion string) (*BranchCreatedEventV0_1_2, Type: BranchCreatedEventTypeV0_1_2, Version: specVersion, }, - Subject: BranchCreatedSubject{ + Subject: BranchCreatedSubjectV0_1_2{ SubjectBase: SubjectBase{ Type: "branch", }, diff --git a/pkg/api/zz_branchcreated_0_2_0.go b/pkg/api/zz_branchcreated_0_2_0.go new file mode 100644 index 0000000..2643b97 --- /dev/null +++ b/pkg/api/zz_branchcreated_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // BranchCreated event type v0.2.0 + BranchCreatedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "branch", + Predicate: "created", + Version: "0.2.0", + } +) + +type BranchCreatedSubjectContentV0_2_0 struct { + Repository *Reference `json:"repository,omitempty"` +} + +type BranchCreatedSubjectV0_2_0 struct { + SubjectBase + Content BranchCreatedSubjectContentV0_2_0 `json:"content"` +} + +func (sc BranchCreatedSubjectV0_2_0) GetSubjectType() SubjectType { + return "branch" +} + +type BranchCreatedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject BranchCreatedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e BranchCreatedEventV0_2_0) GetType() CDEventType { + return BranchCreatedEventTypeV0_2_0 +} + +func (e BranchCreatedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e BranchCreatedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e BranchCreatedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e BranchCreatedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e BranchCreatedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e BranchCreatedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e BranchCreatedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e BranchCreatedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e BranchCreatedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e BranchCreatedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e BranchCreatedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e BranchCreatedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e BranchCreatedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e BranchCreatedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *BranchCreatedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *BranchCreatedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *BranchCreatedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *BranchCreatedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *BranchCreatedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *BranchCreatedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e BranchCreatedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *BranchCreatedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *BranchCreatedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *BranchCreatedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *BranchCreatedEventV0_2_0) SetSubjectRepository(repository *Reference) { + e.Subject.Content.Repository = repository +} + +// New creates a new BranchCreatedEventV0_2_0 +func NewBranchCreatedEventV0_2_0(specVersion string) (*BranchCreatedEventV0_2_0, error) { + e := &BranchCreatedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: BranchCreatedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: BranchCreatedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "branch", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_branchdeleted_0_1_2.go b/pkg/api/zz_branchdeleted_0_1_2.go index f982ae7..5edab79 100644 --- a/pkg/api/zz_branchdeleted_0_1_2.go +++ b/pkg/api/zz_branchdeleted_0_1_2.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var branchdeletedschema0_1_2 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/branch-deleted-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.branch.deleted.0.1.2"],"default":"dev.cdevents.branch.deleted.0.1.2"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["branch"],"default":"branch"},"content":{"properties":{"repository":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // BranchDeleted event type v0.1.2 @@ -36,22 +35,22 @@ var ( } ) -type BranchDeletedSubjectContent struct { +type BranchDeletedSubjectContentV0_1_2 struct { Repository *Reference `json:"repository,omitempty"` } -type BranchDeletedSubject struct { +type BranchDeletedSubjectV0_1_2 struct { SubjectBase - Content BranchDeletedSubjectContent `json:"content"` + Content BranchDeletedSubjectContentV0_1_2 `json:"content"` } -func (sc BranchDeletedSubject) GetSubjectType() SubjectType { +func (sc BranchDeletedSubjectV0_1_2) GetSubjectType() SubjectType { return "branch" } type BranchDeletedEventV0_1_2 struct { - Context Context `json:"context"` - Subject BranchDeletedSubject `json:"subject"` + Context Context `json:"context"` + Subject BranchDeletedSubjectV0_1_2 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *BranchDeletedEventV0_1_2) SetCustomData(contentType string, data interf return nil } -func (e BranchDeletedEventV0_1_2) GetSchema() (string, string) { +func (e BranchDeletedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), branchdeletedschema0_1_2 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewBranchDeletedEventV0_1_2(specVersion string) (*BranchDeletedEventV0_1_2, Type: BranchDeletedEventTypeV0_1_2, Version: specVersion, }, - Subject: BranchDeletedSubject{ + Subject: BranchDeletedSubjectV0_1_2{ SubjectBase: SubjectBase{ Type: "branch", }, diff --git a/pkg/api/zz_branchdeleted_0_2_0.go b/pkg/api/zz_branchdeleted_0_2_0.go new file mode 100644 index 0000000..d504cf4 --- /dev/null +++ b/pkg/api/zz_branchdeleted_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // BranchDeleted event type v0.2.0 + BranchDeletedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "branch", + Predicate: "deleted", + Version: "0.2.0", + } +) + +type BranchDeletedSubjectContentV0_2_0 struct { + Repository *Reference `json:"repository,omitempty"` +} + +type BranchDeletedSubjectV0_2_0 struct { + SubjectBase + Content BranchDeletedSubjectContentV0_2_0 `json:"content"` +} + +func (sc BranchDeletedSubjectV0_2_0) GetSubjectType() SubjectType { + return "branch" +} + +type BranchDeletedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject BranchDeletedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e BranchDeletedEventV0_2_0) GetType() CDEventType { + return BranchDeletedEventTypeV0_2_0 +} + +func (e BranchDeletedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e BranchDeletedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e BranchDeletedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e BranchDeletedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e BranchDeletedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e BranchDeletedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e BranchDeletedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e BranchDeletedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e BranchDeletedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e BranchDeletedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e BranchDeletedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e BranchDeletedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e BranchDeletedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e BranchDeletedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *BranchDeletedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *BranchDeletedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *BranchDeletedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *BranchDeletedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *BranchDeletedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *BranchDeletedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e BranchDeletedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *BranchDeletedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *BranchDeletedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *BranchDeletedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *BranchDeletedEventV0_2_0) SetSubjectRepository(repository *Reference) { + e.Subject.Content.Repository = repository +} + +// New creates a new BranchDeletedEventV0_2_0 +func NewBranchDeletedEventV0_2_0(specVersion string) (*BranchDeletedEventV0_2_0, error) { + e := &BranchDeletedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: BranchDeletedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: BranchDeletedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "branch", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_buildfinished_0_1_1.go b/pkg/api/zz_buildfinished_0_1_1.go index d02e517..fba172a 100644 --- a/pkg/api/zz_buildfinished_0_1_1.go +++ b/pkg/api/zz_buildfinished_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var buildfinishedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/build-finished-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.build.finished.0.1.1"],"default":"dev.cdevents.build.finished.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["build"],"default":"build"},"content":{"properties":{"artifactId":{"type":"string"}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // BuildFinished event type v0.1.1 @@ -36,22 +35,22 @@ var ( } ) -type BuildFinishedSubjectContent struct { +type BuildFinishedSubjectContentV0_1_1 struct { ArtifactId string `json:"artifactId,omitempty" validate:"purl"` } -type BuildFinishedSubject struct { +type BuildFinishedSubjectV0_1_1 struct { SubjectBase - Content BuildFinishedSubjectContent `json:"content"` + Content BuildFinishedSubjectContentV0_1_1 `json:"content"` } -func (sc BuildFinishedSubject) GetSubjectType() SubjectType { +func (sc BuildFinishedSubjectV0_1_1) GetSubjectType() SubjectType { return "build" } type BuildFinishedEventV0_1_1 struct { - Context Context `json:"context"` - Subject BuildFinishedSubject `json:"subject"` + Context Context `json:"context"` + Subject BuildFinishedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *BuildFinishedEventV0_1_1) SetCustomData(contentType string, data interf return nil } -func (e BuildFinishedEventV0_1_1) GetSchema() (string, string) { +func (e BuildFinishedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), buildfinishedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewBuildFinishedEventV0_1_1(specVersion string) (*BuildFinishedEventV0_1_1, Type: BuildFinishedEventTypeV0_1_1, Version: specVersion, }, - Subject: BuildFinishedSubject{ + Subject: BuildFinishedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "build", }, diff --git a/pkg/api/zz_buildfinished_0_2_0.go b/pkg/api/zz_buildfinished_0_2_0.go new file mode 100644 index 0000000..8825810 --- /dev/null +++ b/pkg/api/zz_buildfinished_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // BuildFinished event type v0.2.0 + BuildFinishedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "build", + Predicate: "finished", + Version: "0.2.0", + } +) + +type BuildFinishedSubjectContentV0_2_0 struct { + ArtifactId string `json:"artifactId,omitempty" validate:"purl"` +} + +type BuildFinishedSubjectV0_2_0 struct { + SubjectBase + Content BuildFinishedSubjectContentV0_2_0 `json:"content"` +} + +func (sc BuildFinishedSubjectV0_2_0) GetSubjectType() SubjectType { + return "build" +} + +type BuildFinishedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject BuildFinishedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e BuildFinishedEventV0_2_0) GetType() CDEventType { + return BuildFinishedEventTypeV0_2_0 +} + +func (e BuildFinishedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e BuildFinishedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e BuildFinishedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e BuildFinishedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e BuildFinishedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e BuildFinishedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e BuildFinishedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e BuildFinishedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e BuildFinishedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e BuildFinishedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e BuildFinishedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e BuildFinishedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e BuildFinishedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e BuildFinishedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *BuildFinishedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *BuildFinishedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *BuildFinishedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *BuildFinishedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *BuildFinishedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *BuildFinishedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e BuildFinishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *BuildFinishedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *BuildFinishedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *BuildFinishedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *BuildFinishedEventV0_2_0) SetSubjectArtifactId(artifactId string) { + e.Subject.Content.ArtifactId = artifactId +} + +// New creates a new BuildFinishedEventV0_2_0 +func NewBuildFinishedEventV0_2_0(specVersion string) (*BuildFinishedEventV0_2_0, error) { + e := &BuildFinishedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: BuildFinishedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: BuildFinishedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "build", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_buildqueued_0_1_1.go b/pkg/api/zz_buildqueued_0_1_1.go index 297e6bb..0ccaf1e 100644 --- a/pkg/api/zz_buildqueued_0_1_1.go +++ b/pkg/api/zz_buildqueued_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var buildqueuedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/build-queued-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.build.queued.0.1.1"],"default":"dev.cdevents.build.queued.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["build"],"default":"build"},"content":{"properties":{},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // BuildQueued event type v0.1.1 @@ -36,21 +35,21 @@ var ( } ) -type BuildQueuedSubjectContent struct { +type BuildQueuedSubjectContentV0_1_1 struct { } -type BuildQueuedSubject struct { +type BuildQueuedSubjectV0_1_1 struct { SubjectBase - Content BuildQueuedSubjectContent `json:"content"` + Content BuildQueuedSubjectContentV0_1_1 `json:"content"` } -func (sc BuildQueuedSubject) GetSubjectType() SubjectType { +func (sc BuildQueuedSubjectV0_1_1) GetSubjectType() SubjectType { return "build" } type BuildQueuedEventV0_1_1 struct { - Context Context `json:"context"` - Subject BuildQueuedSubject `json:"subject"` + Context Context `json:"context"` + Subject BuildQueuedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -140,9 +139,9 @@ func (e *BuildQueuedEventV0_1_1) SetCustomData(contentType string, data interfac return nil } -func (e BuildQueuedEventV0_1_1) GetSchema() (string, string) { +func (e BuildQueuedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), buildqueuedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -154,7 +153,7 @@ func NewBuildQueuedEventV0_1_1(specVersion string) (*BuildQueuedEventV0_1_1, err Type: BuildQueuedEventTypeV0_1_1, Version: specVersion, }, - Subject: BuildQueuedSubject{ + Subject: BuildQueuedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "build", }, diff --git a/pkg/api/zz_buildqueued_0_2_0.go b/pkg/api/zz_buildqueued_0_2_0.go new file mode 100644 index 0000000..aa11196 --- /dev/null +++ b/pkg/api/zz_buildqueued_0_2_0.go @@ -0,0 +1,199 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // BuildQueued event type v0.2.0 + BuildQueuedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "build", + Predicate: "queued", + Version: "0.2.0", + } +) + +type BuildQueuedSubjectContentV0_2_0 struct { +} + +type BuildQueuedSubjectV0_2_0 struct { + SubjectBase + Content BuildQueuedSubjectContentV0_2_0 `json:"content"` +} + +func (sc BuildQueuedSubjectV0_2_0) GetSubjectType() SubjectType { + return "build" +} + +type BuildQueuedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject BuildQueuedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e BuildQueuedEventV0_2_0) GetType() CDEventType { + return BuildQueuedEventTypeV0_2_0 +} + +func (e BuildQueuedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e BuildQueuedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e BuildQueuedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e BuildQueuedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e BuildQueuedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e BuildQueuedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e BuildQueuedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e BuildQueuedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e BuildQueuedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e BuildQueuedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e BuildQueuedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e BuildQueuedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e BuildQueuedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e BuildQueuedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *BuildQueuedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *BuildQueuedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *BuildQueuedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *BuildQueuedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *BuildQueuedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *BuildQueuedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e BuildQueuedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *BuildQueuedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *BuildQueuedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *BuildQueuedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +// New creates a new BuildQueuedEventV0_2_0 +func NewBuildQueuedEventV0_2_0(specVersion string) (*BuildQueuedEventV0_2_0, error) { + e := &BuildQueuedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: BuildQueuedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: BuildQueuedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "build", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_buildstarted_0_1_1.go b/pkg/api/zz_buildstarted_0_1_1.go index 963676a..43636ea 100644 --- a/pkg/api/zz_buildstarted_0_1_1.go +++ b/pkg/api/zz_buildstarted_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var buildstartedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/build-started-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.build.started.0.1.1"],"default":"dev.cdevents.build.started.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["build"],"default":"build"},"content":{"properties":{},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // BuildStarted event type v0.1.1 @@ -36,21 +35,21 @@ var ( } ) -type BuildStartedSubjectContent struct { +type BuildStartedSubjectContentV0_1_1 struct { } -type BuildStartedSubject struct { +type BuildStartedSubjectV0_1_1 struct { SubjectBase - Content BuildStartedSubjectContent `json:"content"` + Content BuildStartedSubjectContentV0_1_1 `json:"content"` } -func (sc BuildStartedSubject) GetSubjectType() SubjectType { +func (sc BuildStartedSubjectV0_1_1) GetSubjectType() SubjectType { return "build" } type BuildStartedEventV0_1_1 struct { - Context Context `json:"context"` - Subject BuildStartedSubject `json:"subject"` + Context Context `json:"context"` + Subject BuildStartedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -140,9 +139,9 @@ func (e *BuildStartedEventV0_1_1) SetCustomData(contentType string, data interfa return nil } -func (e BuildStartedEventV0_1_1) GetSchema() (string, string) { +func (e BuildStartedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), buildstartedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -154,7 +153,7 @@ func NewBuildStartedEventV0_1_1(specVersion string) (*BuildStartedEventV0_1_1, e Type: BuildStartedEventTypeV0_1_1, Version: specVersion, }, - Subject: BuildStartedSubject{ + Subject: BuildStartedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "build", }, diff --git a/pkg/api/zz_buildstarted_0_2_0.go b/pkg/api/zz_buildstarted_0_2_0.go new file mode 100644 index 0000000..1c4bcc7 --- /dev/null +++ b/pkg/api/zz_buildstarted_0_2_0.go @@ -0,0 +1,199 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // BuildStarted event type v0.2.0 + BuildStartedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "build", + Predicate: "started", + Version: "0.2.0", + } +) + +type BuildStartedSubjectContentV0_2_0 struct { +} + +type BuildStartedSubjectV0_2_0 struct { + SubjectBase + Content BuildStartedSubjectContentV0_2_0 `json:"content"` +} + +func (sc BuildStartedSubjectV0_2_0) GetSubjectType() SubjectType { + return "build" +} + +type BuildStartedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject BuildStartedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e BuildStartedEventV0_2_0) GetType() CDEventType { + return BuildStartedEventTypeV0_2_0 +} + +func (e BuildStartedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e BuildStartedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e BuildStartedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e BuildStartedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e BuildStartedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e BuildStartedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e BuildStartedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e BuildStartedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e BuildStartedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e BuildStartedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e BuildStartedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e BuildStartedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e BuildStartedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e BuildStartedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *BuildStartedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *BuildStartedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *BuildStartedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *BuildStartedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *BuildStartedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *BuildStartedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e BuildStartedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *BuildStartedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *BuildStartedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *BuildStartedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +// New creates a new BuildStartedEventV0_2_0 +func NewBuildStartedEventV0_2_0(specVersion string) (*BuildStartedEventV0_2_0, error) { + e := &BuildStartedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: BuildStartedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: BuildStartedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "build", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_changeabandoned_0_1_2.go b/pkg/api/zz_changeabandoned_0_1_2.go index 52cd0ce..9f0b0e8 100644 --- a/pkg/api/zz_changeabandoned_0_1_2.go +++ b/pkg/api/zz_changeabandoned_0_1_2.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var changeabandonedschema0_1_2 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/change-abandoned-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.change.abandoned.0.1.2"],"default":"dev.cdevents.change.abandoned.0.1.2"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["change"],"default":"change"},"content":{"properties":{"repository":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ChangeAbandoned event type v0.1.2 @@ -36,22 +35,22 @@ var ( } ) -type ChangeAbandonedSubjectContent struct { +type ChangeAbandonedSubjectContentV0_1_2 struct { Repository *Reference `json:"repository,omitempty"` } -type ChangeAbandonedSubject struct { +type ChangeAbandonedSubjectV0_1_2 struct { SubjectBase - Content ChangeAbandonedSubjectContent `json:"content"` + Content ChangeAbandonedSubjectContentV0_1_2 `json:"content"` } -func (sc ChangeAbandonedSubject) GetSubjectType() SubjectType { +func (sc ChangeAbandonedSubjectV0_1_2) GetSubjectType() SubjectType { return "change" } type ChangeAbandonedEventV0_1_2 struct { - Context Context `json:"context"` - Subject ChangeAbandonedSubject `json:"subject"` + Context Context `json:"context"` + Subject ChangeAbandonedSubjectV0_1_2 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *ChangeAbandonedEventV0_1_2) SetCustomData(contentType string, data inte return nil } -func (e ChangeAbandonedEventV0_1_2) GetSchema() (string, string) { +func (e ChangeAbandonedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), changeabandonedschema0_1_2 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewChangeAbandonedEventV0_1_2(specVersion string) (*ChangeAbandonedEventV0_ Type: ChangeAbandonedEventTypeV0_1_2, Version: specVersion, }, - Subject: ChangeAbandonedSubject{ + Subject: ChangeAbandonedSubjectV0_1_2{ SubjectBase: SubjectBase{ Type: "change", }, diff --git a/pkg/api/zz_changeabandoned_0_2_0.go b/pkg/api/zz_changeabandoned_0_2_0.go new file mode 100644 index 0000000..15d4303 --- /dev/null +++ b/pkg/api/zz_changeabandoned_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ChangeAbandoned event type v0.2.0 + ChangeAbandonedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "change", + Predicate: "abandoned", + Version: "0.2.0", + } +) + +type ChangeAbandonedSubjectContentV0_2_0 struct { + Repository *Reference `json:"repository,omitempty"` +} + +type ChangeAbandonedSubjectV0_2_0 struct { + SubjectBase + Content ChangeAbandonedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ChangeAbandonedSubjectV0_2_0) GetSubjectType() SubjectType { + return "change" +} + +type ChangeAbandonedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ChangeAbandonedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ChangeAbandonedEventV0_2_0) GetType() CDEventType { + return ChangeAbandonedEventTypeV0_2_0 +} + +func (e ChangeAbandonedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ChangeAbandonedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ChangeAbandonedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ChangeAbandonedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ChangeAbandonedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ChangeAbandonedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ChangeAbandonedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ChangeAbandonedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ChangeAbandonedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ChangeAbandonedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ChangeAbandonedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ChangeAbandonedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ChangeAbandonedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ChangeAbandonedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ChangeAbandonedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ChangeAbandonedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ChangeAbandonedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ChangeAbandonedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ChangeAbandonedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ChangeAbandonedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ChangeAbandonedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ChangeAbandonedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ChangeAbandonedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ChangeAbandonedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ChangeAbandonedEventV0_2_0) SetSubjectRepository(repository *Reference) { + e.Subject.Content.Repository = repository +} + +// New creates a new ChangeAbandonedEventV0_2_0 +func NewChangeAbandonedEventV0_2_0(specVersion string) (*ChangeAbandonedEventV0_2_0, error) { + e := &ChangeAbandonedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ChangeAbandonedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ChangeAbandonedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "change", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_changecreated_0_1_2.go b/pkg/api/zz_changecreated_0_1_2.go index 26613f0..486b379 100644 --- a/pkg/api/zz_changecreated_0_1_2.go +++ b/pkg/api/zz_changecreated_0_1_2.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var changecreatedschema0_1_2 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/change-created-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.change.created.0.1.2"],"default":"dev.cdevents.change.created.0.1.2"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["change"],"default":"change"},"content":{"properties":{"repository":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ChangeCreated event type v0.1.2 @@ -36,22 +35,22 @@ var ( } ) -type ChangeCreatedSubjectContent struct { +type ChangeCreatedSubjectContentV0_1_2 struct { Repository *Reference `json:"repository,omitempty"` } -type ChangeCreatedSubject struct { +type ChangeCreatedSubjectV0_1_2 struct { SubjectBase - Content ChangeCreatedSubjectContent `json:"content"` + Content ChangeCreatedSubjectContentV0_1_2 `json:"content"` } -func (sc ChangeCreatedSubject) GetSubjectType() SubjectType { +func (sc ChangeCreatedSubjectV0_1_2) GetSubjectType() SubjectType { return "change" } type ChangeCreatedEventV0_1_2 struct { - Context Context `json:"context"` - Subject ChangeCreatedSubject `json:"subject"` + Context Context `json:"context"` + Subject ChangeCreatedSubjectV0_1_2 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *ChangeCreatedEventV0_1_2) SetCustomData(contentType string, data interf return nil } -func (e ChangeCreatedEventV0_1_2) GetSchema() (string, string) { +func (e ChangeCreatedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), changecreatedschema0_1_2 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewChangeCreatedEventV0_1_2(specVersion string) (*ChangeCreatedEventV0_1_2, Type: ChangeCreatedEventTypeV0_1_2, Version: specVersion, }, - Subject: ChangeCreatedSubject{ + Subject: ChangeCreatedSubjectV0_1_2{ SubjectBase: SubjectBase{ Type: "change", }, diff --git a/pkg/api/zz_changecreated_0_3_0.go b/pkg/api/zz_changecreated_0_3_0.go new file mode 100644 index 0000000..649d58a --- /dev/null +++ b/pkg/api/zz_changecreated_0_3_0.go @@ -0,0 +1,210 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ChangeCreated event type v0.3.0 + ChangeCreatedEventTypeV0_3_0 CDEventType = CDEventType{ + Subject: "change", + Predicate: "created", + Version: "0.3.0", + } +) + +type ChangeCreatedSubjectContentV0_3_0 struct { + Description string `json:"description,omitempty"` + + Repository *Reference `json:"repository,omitempty"` +} + +type ChangeCreatedSubjectV0_3_0 struct { + SubjectBase + Content ChangeCreatedSubjectContentV0_3_0 `json:"content"` +} + +func (sc ChangeCreatedSubjectV0_3_0) GetSubjectType() SubjectType { + return "change" +} + +type ChangeCreatedEventV0_3_0 struct { + Context ContextV04 `json:"context"` + Subject ChangeCreatedSubjectV0_3_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ChangeCreatedEventV0_3_0) GetType() CDEventType { + return ChangeCreatedEventTypeV0_3_0 +} + +func (e ChangeCreatedEventV0_3_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ChangeCreatedEventV0_3_0) GetId() string { + return e.Context.Id +} + +func (e ChangeCreatedEventV0_3_0) GetSource() string { + return e.Context.Source +} + +func (e ChangeCreatedEventV0_3_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ChangeCreatedEventV0_3_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ChangeCreatedEventV0_3_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ChangeCreatedEventV0_3_0) GetSubject() Subject { + return e.Subject +} + +func (e ChangeCreatedEventV0_3_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ChangeCreatedEventV0_3_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ChangeCreatedEventV0_3_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ChangeCreatedEventV0_3_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ChangeCreatedEventV0_3_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ChangeCreatedEventV0_3_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ChangeCreatedEventV0_3_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ChangeCreatedEventV0_3_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ChangeCreatedEventV0_3_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ChangeCreatedEventV0_3_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ChangeCreatedEventV0_3_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ChangeCreatedEventV0_3_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ChangeCreatedEventV0_3_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ChangeCreatedEventV0_3_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ChangeCreatedEventV0_3_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ChangeCreatedEventV0_3_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ChangeCreatedEventV0_3_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ChangeCreatedEventV0_3_0) SetSubjectDescription(description string) { + e.Subject.Content.Description = description +} + +func (e *ChangeCreatedEventV0_3_0) SetSubjectRepository(repository *Reference) { + e.Subject.Content.Repository = repository +} + +// New creates a new ChangeCreatedEventV0_3_0 +func NewChangeCreatedEventV0_3_0(specVersion string) (*ChangeCreatedEventV0_3_0, error) { + e := &ChangeCreatedEventV0_3_0{ + Context: ContextV04{ + Context{ + Type: ChangeCreatedEventTypeV0_3_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ChangeCreatedSubjectV0_3_0{ + SubjectBase: SubjectBase{ + Type: "change", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_changemerged_0_1_2.go b/pkg/api/zz_changemerged_0_1_2.go index 47845be..67464e5 100644 --- a/pkg/api/zz_changemerged_0_1_2.go +++ b/pkg/api/zz_changemerged_0_1_2.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var changemergedschema0_1_2 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/change-merged-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.change.merged.0.1.2"],"default":"dev.cdevents.change.merged.0.1.2"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["change"],"default":"change"},"content":{"properties":{"repository":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ChangeMerged event type v0.1.2 @@ -36,22 +35,22 @@ var ( } ) -type ChangeMergedSubjectContent struct { +type ChangeMergedSubjectContentV0_1_2 struct { Repository *Reference `json:"repository,omitempty"` } -type ChangeMergedSubject struct { +type ChangeMergedSubjectV0_1_2 struct { SubjectBase - Content ChangeMergedSubjectContent `json:"content"` + Content ChangeMergedSubjectContentV0_1_2 `json:"content"` } -func (sc ChangeMergedSubject) GetSubjectType() SubjectType { +func (sc ChangeMergedSubjectV0_1_2) GetSubjectType() SubjectType { return "change" } type ChangeMergedEventV0_1_2 struct { - Context Context `json:"context"` - Subject ChangeMergedSubject `json:"subject"` + Context Context `json:"context"` + Subject ChangeMergedSubjectV0_1_2 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *ChangeMergedEventV0_1_2) SetCustomData(contentType string, data interfa return nil } -func (e ChangeMergedEventV0_1_2) GetSchema() (string, string) { +func (e ChangeMergedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), changemergedschema0_1_2 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewChangeMergedEventV0_1_2(specVersion string) (*ChangeMergedEventV0_1_2, e Type: ChangeMergedEventTypeV0_1_2, Version: specVersion, }, - Subject: ChangeMergedSubject{ + Subject: ChangeMergedSubjectV0_1_2{ SubjectBase: SubjectBase{ Type: "change", }, diff --git a/pkg/api/zz_changemerged_0_2_0.go b/pkg/api/zz_changemerged_0_2_0.go new file mode 100644 index 0000000..385f586 --- /dev/null +++ b/pkg/api/zz_changemerged_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ChangeMerged event type v0.2.0 + ChangeMergedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "change", + Predicate: "merged", + Version: "0.2.0", + } +) + +type ChangeMergedSubjectContentV0_2_0 struct { + Repository *Reference `json:"repository,omitempty"` +} + +type ChangeMergedSubjectV0_2_0 struct { + SubjectBase + Content ChangeMergedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ChangeMergedSubjectV0_2_0) GetSubjectType() SubjectType { + return "change" +} + +type ChangeMergedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ChangeMergedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ChangeMergedEventV0_2_0) GetType() CDEventType { + return ChangeMergedEventTypeV0_2_0 +} + +func (e ChangeMergedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ChangeMergedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ChangeMergedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ChangeMergedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ChangeMergedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ChangeMergedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ChangeMergedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ChangeMergedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ChangeMergedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ChangeMergedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ChangeMergedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ChangeMergedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ChangeMergedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ChangeMergedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ChangeMergedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ChangeMergedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ChangeMergedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ChangeMergedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ChangeMergedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ChangeMergedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ChangeMergedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ChangeMergedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ChangeMergedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ChangeMergedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ChangeMergedEventV0_2_0) SetSubjectRepository(repository *Reference) { + e.Subject.Content.Repository = repository +} + +// New creates a new ChangeMergedEventV0_2_0 +func NewChangeMergedEventV0_2_0(specVersion string) (*ChangeMergedEventV0_2_0, error) { + e := &ChangeMergedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ChangeMergedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ChangeMergedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "change", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_changereviewed_0_1_2.go b/pkg/api/zz_changereviewed_0_1_2.go index 3f69080..2d951c3 100644 --- a/pkg/api/zz_changereviewed_0_1_2.go +++ b/pkg/api/zz_changereviewed_0_1_2.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var changereviewedschema0_1_2 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/change-reviewed-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.change.reviewed.0.1.2"],"default":"dev.cdevents.change.reviewed.0.1.2"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["change"],"default":"change"},"content":{"properties":{"repository":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ChangeReviewed event type v0.1.2 @@ -36,22 +35,22 @@ var ( } ) -type ChangeReviewedSubjectContent struct { +type ChangeReviewedSubjectContentV0_1_2 struct { Repository *Reference `json:"repository,omitempty"` } -type ChangeReviewedSubject struct { +type ChangeReviewedSubjectV0_1_2 struct { SubjectBase - Content ChangeReviewedSubjectContent `json:"content"` + Content ChangeReviewedSubjectContentV0_1_2 `json:"content"` } -func (sc ChangeReviewedSubject) GetSubjectType() SubjectType { +func (sc ChangeReviewedSubjectV0_1_2) GetSubjectType() SubjectType { return "change" } type ChangeReviewedEventV0_1_2 struct { - Context Context `json:"context"` - Subject ChangeReviewedSubject `json:"subject"` + Context Context `json:"context"` + Subject ChangeReviewedSubjectV0_1_2 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *ChangeReviewedEventV0_1_2) SetCustomData(contentType string, data inter return nil } -func (e ChangeReviewedEventV0_1_2) GetSchema() (string, string) { +func (e ChangeReviewedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), changereviewedschema0_1_2 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewChangeReviewedEventV0_1_2(specVersion string) (*ChangeReviewedEventV0_1_ Type: ChangeReviewedEventTypeV0_1_2, Version: specVersion, }, - Subject: ChangeReviewedSubject{ + Subject: ChangeReviewedSubjectV0_1_2{ SubjectBase: SubjectBase{ Type: "change", }, diff --git a/pkg/api/zz_changereviewed_0_2_0.go b/pkg/api/zz_changereviewed_0_2_0.go new file mode 100644 index 0000000..90a87e3 --- /dev/null +++ b/pkg/api/zz_changereviewed_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ChangeReviewed event type v0.2.0 + ChangeReviewedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "change", + Predicate: "reviewed", + Version: "0.2.0", + } +) + +type ChangeReviewedSubjectContentV0_2_0 struct { + Repository *Reference `json:"repository,omitempty"` +} + +type ChangeReviewedSubjectV0_2_0 struct { + SubjectBase + Content ChangeReviewedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ChangeReviewedSubjectV0_2_0) GetSubjectType() SubjectType { + return "change" +} + +type ChangeReviewedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ChangeReviewedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ChangeReviewedEventV0_2_0) GetType() CDEventType { + return ChangeReviewedEventTypeV0_2_0 +} + +func (e ChangeReviewedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ChangeReviewedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ChangeReviewedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ChangeReviewedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ChangeReviewedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ChangeReviewedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ChangeReviewedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ChangeReviewedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ChangeReviewedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ChangeReviewedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ChangeReviewedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ChangeReviewedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ChangeReviewedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ChangeReviewedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ChangeReviewedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ChangeReviewedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ChangeReviewedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ChangeReviewedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ChangeReviewedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ChangeReviewedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ChangeReviewedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ChangeReviewedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ChangeReviewedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ChangeReviewedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ChangeReviewedEventV0_2_0) SetSubjectRepository(repository *Reference) { + e.Subject.Content.Repository = repository +} + +// New creates a new ChangeReviewedEventV0_2_0 +func NewChangeReviewedEventV0_2_0(specVersion string) (*ChangeReviewedEventV0_2_0, error) { + e := &ChangeReviewedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ChangeReviewedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ChangeReviewedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "change", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_changeupdated_0_1_2.go b/pkg/api/zz_changeupdated_0_1_2.go index 50eafb6..f49b2c8 100644 --- a/pkg/api/zz_changeupdated_0_1_2.go +++ b/pkg/api/zz_changeupdated_0_1_2.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var changeupdatedschema0_1_2 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/change-updated-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.change.updated.0.1.2"],"default":"dev.cdevents.change.updated.0.1.2"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["change"],"default":"change"},"content":{"properties":{"repository":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ChangeUpdated event type v0.1.2 @@ -36,22 +35,22 @@ var ( } ) -type ChangeUpdatedSubjectContent struct { +type ChangeUpdatedSubjectContentV0_1_2 struct { Repository *Reference `json:"repository,omitempty"` } -type ChangeUpdatedSubject struct { +type ChangeUpdatedSubjectV0_1_2 struct { SubjectBase - Content ChangeUpdatedSubjectContent `json:"content"` + Content ChangeUpdatedSubjectContentV0_1_2 `json:"content"` } -func (sc ChangeUpdatedSubject) GetSubjectType() SubjectType { +func (sc ChangeUpdatedSubjectV0_1_2) GetSubjectType() SubjectType { return "change" } type ChangeUpdatedEventV0_1_2 struct { - Context Context `json:"context"` - Subject ChangeUpdatedSubject `json:"subject"` + Context Context `json:"context"` + Subject ChangeUpdatedSubjectV0_1_2 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *ChangeUpdatedEventV0_1_2) SetCustomData(contentType string, data interf return nil } -func (e ChangeUpdatedEventV0_1_2) GetSchema() (string, string) { +func (e ChangeUpdatedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), changeupdatedschema0_1_2 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewChangeUpdatedEventV0_1_2(specVersion string) (*ChangeUpdatedEventV0_1_2, Type: ChangeUpdatedEventTypeV0_1_2, Version: specVersion, }, - Subject: ChangeUpdatedSubject{ + Subject: ChangeUpdatedSubjectV0_1_2{ SubjectBase: SubjectBase{ Type: "change", }, diff --git a/pkg/api/zz_changeupdated_0_2_0.go b/pkg/api/zz_changeupdated_0_2_0.go new file mode 100644 index 0000000..081fac1 --- /dev/null +++ b/pkg/api/zz_changeupdated_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ChangeUpdated event type v0.2.0 + ChangeUpdatedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "change", + Predicate: "updated", + Version: "0.2.0", + } +) + +type ChangeUpdatedSubjectContentV0_2_0 struct { + Repository *Reference `json:"repository,omitempty"` +} + +type ChangeUpdatedSubjectV0_2_0 struct { + SubjectBase + Content ChangeUpdatedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ChangeUpdatedSubjectV0_2_0) GetSubjectType() SubjectType { + return "change" +} + +type ChangeUpdatedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ChangeUpdatedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ChangeUpdatedEventV0_2_0) GetType() CDEventType { + return ChangeUpdatedEventTypeV0_2_0 +} + +func (e ChangeUpdatedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ChangeUpdatedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ChangeUpdatedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ChangeUpdatedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ChangeUpdatedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ChangeUpdatedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ChangeUpdatedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ChangeUpdatedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ChangeUpdatedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ChangeUpdatedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ChangeUpdatedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ChangeUpdatedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ChangeUpdatedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ChangeUpdatedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ChangeUpdatedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ChangeUpdatedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ChangeUpdatedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ChangeUpdatedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ChangeUpdatedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ChangeUpdatedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ChangeUpdatedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ChangeUpdatedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ChangeUpdatedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ChangeUpdatedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ChangeUpdatedEventV0_2_0) SetSubjectRepository(repository *Reference) { + e.Subject.Content.Repository = repository +} + +// New creates a new ChangeUpdatedEventV0_2_0 +func NewChangeUpdatedEventV0_2_0(specVersion string) (*ChangeUpdatedEventV0_2_0, error) { + e := &ChangeUpdatedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ChangeUpdatedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ChangeUpdatedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "change", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_environmentcreated_0_1_1.go b/pkg/api/zz_environmentcreated_0_1_1.go index 28bec1f..9f110ef 100644 --- a/pkg/api/zz_environmentcreated_0_1_1.go +++ b/pkg/api/zz_environmentcreated_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var environmentcreatedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/environment-created-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.environment.created.0.1.1"],"default":"dev.cdevents.environment.created.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["environment"],"default":"environment"},"content":{"properties":{"name":{"type":"string"},"url":{"type":"string"}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // EnvironmentCreated event type v0.1.1 @@ -36,24 +35,24 @@ var ( } ) -type EnvironmentCreatedSubjectContent struct { +type EnvironmentCreatedSubjectContentV0_1_1 struct { Name string `json:"name,omitempty"` Url string `json:"url,omitempty"` } -type EnvironmentCreatedSubject struct { +type EnvironmentCreatedSubjectV0_1_1 struct { SubjectBase - Content EnvironmentCreatedSubjectContent `json:"content"` + Content EnvironmentCreatedSubjectContentV0_1_1 `json:"content"` } -func (sc EnvironmentCreatedSubject) GetSubjectType() SubjectType { +func (sc EnvironmentCreatedSubjectV0_1_1) GetSubjectType() SubjectType { return "environment" } type EnvironmentCreatedEventV0_1_1 struct { - Context Context `json:"context"` - Subject EnvironmentCreatedSubject `json:"subject"` + Context Context `json:"context"` + Subject EnvironmentCreatedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -143,9 +142,9 @@ func (e *EnvironmentCreatedEventV0_1_1) SetCustomData(contentType string, data i return nil } -func (e EnvironmentCreatedEventV0_1_1) GetSchema() (string, string) { +func (e EnvironmentCreatedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), environmentcreatedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -165,7 +164,7 @@ func NewEnvironmentCreatedEventV0_1_1(specVersion string) (*EnvironmentCreatedEv Type: EnvironmentCreatedEventTypeV0_1_1, Version: specVersion, }, - Subject: EnvironmentCreatedSubject{ + Subject: EnvironmentCreatedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "environment", }, diff --git a/pkg/api/zz_environmentcreated_0_2_0.go b/pkg/api/zz_environmentcreated_0_2_0.go new file mode 100644 index 0000000..22cd18f --- /dev/null +++ b/pkg/api/zz_environmentcreated_0_2_0.go @@ -0,0 +1,210 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // EnvironmentCreated event type v0.2.0 + EnvironmentCreatedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "environment", + Predicate: "created", + Version: "0.2.0", + } +) + +type EnvironmentCreatedSubjectContentV0_2_0 struct { + Name string `json:"name,omitempty"` + + Url string `json:"url,omitempty"` +} + +type EnvironmentCreatedSubjectV0_2_0 struct { + SubjectBase + Content EnvironmentCreatedSubjectContentV0_2_0 `json:"content"` +} + +func (sc EnvironmentCreatedSubjectV0_2_0) GetSubjectType() SubjectType { + return "environment" +} + +type EnvironmentCreatedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject EnvironmentCreatedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e EnvironmentCreatedEventV0_2_0) GetType() CDEventType { + return EnvironmentCreatedEventTypeV0_2_0 +} + +func (e EnvironmentCreatedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e EnvironmentCreatedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e EnvironmentCreatedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e EnvironmentCreatedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e EnvironmentCreatedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e EnvironmentCreatedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e EnvironmentCreatedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e EnvironmentCreatedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e EnvironmentCreatedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e EnvironmentCreatedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e EnvironmentCreatedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e EnvironmentCreatedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e EnvironmentCreatedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e EnvironmentCreatedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *EnvironmentCreatedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *EnvironmentCreatedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *EnvironmentCreatedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *EnvironmentCreatedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *EnvironmentCreatedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *EnvironmentCreatedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e EnvironmentCreatedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *EnvironmentCreatedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *EnvironmentCreatedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *EnvironmentCreatedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *EnvironmentCreatedEventV0_2_0) SetSubjectName(name string) { + e.Subject.Content.Name = name +} + +func (e *EnvironmentCreatedEventV0_2_0) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +// New creates a new EnvironmentCreatedEventV0_2_0 +func NewEnvironmentCreatedEventV0_2_0(specVersion string) (*EnvironmentCreatedEventV0_2_0, error) { + e := &EnvironmentCreatedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: EnvironmentCreatedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: EnvironmentCreatedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "environment", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_environmentdeleted_0_1_1.go b/pkg/api/zz_environmentdeleted_0_1_1.go index c2f9306..c1299ea 100644 --- a/pkg/api/zz_environmentdeleted_0_1_1.go +++ b/pkg/api/zz_environmentdeleted_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var environmentdeletedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/environment-deleted-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.environment.deleted.0.1.1"],"default":"dev.cdevents.environment.deleted.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["environment"],"default":"environment"},"content":{"properties":{"name":{"type":"string"}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // EnvironmentDeleted event type v0.1.1 @@ -36,22 +35,22 @@ var ( } ) -type EnvironmentDeletedSubjectContent struct { +type EnvironmentDeletedSubjectContentV0_1_1 struct { Name string `json:"name,omitempty"` } -type EnvironmentDeletedSubject struct { +type EnvironmentDeletedSubjectV0_1_1 struct { SubjectBase - Content EnvironmentDeletedSubjectContent `json:"content"` + Content EnvironmentDeletedSubjectContentV0_1_1 `json:"content"` } -func (sc EnvironmentDeletedSubject) GetSubjectType() SubjectType { +func (sc EnvironmentDeletedSubjectV0_1_1) GetSubjectType() SubjectType { return "environment" } type EnvironmentDeletedEventV0_1_1 struct { - Context Context `json:"context"` - Subject EnvironmentDeletedSubject `json:"subject"` + Context Context `json:"context"` + Subject EnvironmentDeletedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *EnvironmentDeletedEventV0_1_1) SetCustomData(contentType string, data i return nil } -func (e EnvironmentDeletedEventV0_1_1) GetSchema() (string, string) { +func (e EnvironmentDeletedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), environmentdeletedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewEnvironmentDeletedEventV0_1_1(specVersion string) (*EnvironmentDeletedEv Type: EnvironmentDeletedEventTypeV0_1_1, Version: specVersion, }, - Subject: EnvironmentDeletedSubject{ + Subject: EnvironmentDeletedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "environment", }, diff --git a/pkg/api/zz_environmentdeleted_0_2_0.go b/pkg/api/zz_environmentdeleted_0_2_0.go new file mode 100644 index 0000000..12c2c44 --- /dev/null +++ b/pkg/api/zz_environmentdeleted_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // EnvironmentDeleted event type v0.2.0 + EnvironmentDeletedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "environment", + Predicate: "deleted", + Version: "0.2.0", + } +) + +type EnvironmentDeletedSubjectContentV0_2_0 struct { + Name string `json:"name,omitempty"` +} + +type EnvironmentDeletedSubjectV0_2_0 struct { + SubjectBase + Content EnvironmentDeletedSubjectContentV0_2_0 `json:"content"` +} + +func (sc EnvironmentDeletedSubjectV0_2_0) GetSubjectType() SubjectType { + return "environment" +} + +type EnvironmentDeletedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject EnvironmentDeletedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e EnvironmentDeletedEventV0_2_0) GetType() CDEventType { + return EnvironmentDeletedEventTypeV0_2_0 +} + +func (e EnvironmentDeletedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e EnvironmentDeletedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e EnvironmentDeletedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e EnvironmentDeletedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e EnvironmentDeletedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e EnvironmentDeletedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e EnvironmentDeletedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e EnvironmentDeletedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e EnvironmentDeletedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e EnvironmentDeletedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e EnvironmentDeletedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e EnvironmentDeletedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e EnvironmentDeletedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e EnvironmentDeletedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *EnvironmentDeletedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *EnvironmentDeletedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *EnvironmentDeletedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *EnvironmentDeletedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *EnvironmentDeletedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *EnvironmentDeletedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e EnvironmentDeletedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *EnvironmentDeletedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *EnvironmentDeletedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *EnvironmentDeletedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *EnvironmentDeletedEventV0_2_0) SetSubjectName(name string) { + e.Subject.Content.Name = name +} + +// New creates a new EnvironmentDeletedEventV0_2_0 +func NewEnvironmentDeletedEventV0_2_0(specVersion string) (*EnvironmentDeletedEventV0_2_0, error) { + e := &EnvironmentDeletedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: EnvironmentDeletedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: EnvironmentDeletedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "environment", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_environmentmodified_0_1_1.go b/pkg/api/zz_environmentmodified_0_1_1.go index 1f24103..b94e791 100644 --- a/pkg/api/zz_environmentmodified_0_1_1.go +++ b/pkg/api/zz_environmentmodified_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var environmentmodifiedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/environment-modified-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.environment.modified.0.1.1"],"default":"dev.cdevents.environment.modified.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["environment"],"default":"environment"},"content":{"properties":{"name":{"type":"string"},"url":{"type":"string"}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // EnvironmentModified event type v0.1.1 @@ -36,24 +35,24 @@ var ( } ) -type EnvironmentModifiedSubjectContent struct { +type EnvironmentModifiedSubjectContentV0_1_1 struct { Name string `json:"name,omitempty"` Url string `json:"url,omitempty"` } -type EnvironmentModifiedSubject struct { +type EnvironmentModifiedSubjectV0_1_1 struct { SubjectBase - Content EnvironmentModifiedSubjectContent `json:"content"` + Content EnvironmentModifiedSubjectContentV0_1_1 `json:"content"` } -func (sc EnvironmentModifiedSubject) GetSubjectType() SubjectType { +func (sc EnvironmentModifiedSubjectV0_1_1) GetSubjectType() SubjectType { return "environment" } type EnvironmentModifiedEventV0_1_1 struct { - Context Context `json:"context"` - Subject EnvironmentModifiedSubject `json:"subject"` + Context Context `json:"context"` + Subject EnvironmentModifiedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -143,9 +142,9 @@ func (e *EnvironmentModifiedEventV0_1_1) SetCustomData(contentType string, data return nil } -func (e EnvironmentModifiedEventV0_1_1) GetSchema() (string, string) { +func (e EnvironmentModifiedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), environmentmodifiedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -165,7 +164,7 @@ func NewEnvironmentModifiedEventV0_1_1(specVersion string) (*EnvironmentModified Type: EnvironmentModifiedEventTypeV0_1_1, Version: specVersion, }, - Subject: EnvironmentModifiedSubject{ + Subject: EnvironmentModifiedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "environment", }, diff --git a/pkg/api/zz_environmentmodified_0_2_0.go b/pkg/api/zz_environmentmodified_0_2_0.go new file mode 100644 index 0000000..90b0934 --- /dev/null +++ b/pkg/api/zz_environmentmodified_0_2_0.go @@ -0,0 +1,210 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // EnvironmentModified event type v0.2.0 + EnvironmentModifiedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "environment", + Predicate: "modified", + Version: "0.2.0", + } +) + +type EnvironmentModifiedSubjectContentV0_2_0 struct { + Name string `json:"name,omitempty"` + + Url string `json:"url,omitempty"` +} + +type EnvironmentModifiedSubjectV0_2_0 struct { + SubjectBase + Content EnvironmentModifiedSubjectContentV0_2_0 `json:"content"` +} + +func (sc EnvironmentModifiedSubjectV0_2_0) GetSubjectType() SubjectType { + return "environment" +} + +type EnvironmentModifiedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject EnvironmentModifiedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e EnvironmentModifiedEventV0_2_0) GetType() CDEventType { + return EnvironmentModifiedEventTypeV0_2_0 +} + +func (e EnvironmentModifiedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e EnvironmentModifiedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e EnvironmentModifiedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e EnvironmentModifiedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e EnvironmentModifiedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e EnvironmentModifiedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e EnvironmentModifiedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e EnvironmentModifiedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e EnvironmentModifiedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e EnvironmentModifiedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e EnvironmentModifiedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e EnvironmentModifiedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e EnvironmentModifiedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e EnvironmentModifiedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *EnvironmentModifiedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *EnvironmentModifiedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *EnvironmentModifiedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *EnvironmentModifiedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *EnvironmentModifiedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *EnvironmentModifiedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e EnvironmentModifiedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *EnvironmentModifiedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *EnvironmentModifiedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *EnvironmentModifiedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *EnvironmentModifiedEventV0_2_0) SetSubjectName(name string) { + e.Subject.Content.Name = name +} + +func (e *EnvironmentModifiedEventV0_2_0) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +// New creates a new EnvironmentModifiedEventV0_2_0 +func NewEnvironmentModifiedEventV0_2_0(specVersion string) (*EnvironmentModifiedEventV0_2_0, error) { + e := &EnvironmentModifiedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: EnvironmentModifiedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: EnvironmentModifiedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "environment", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_incidentdetected_0_1_0.go b/pkg/api/zz_incidentdetected_0_1_0.go index 0250806..e13d70d 100644 --- a/pkg/api/zz_incidentdetected_0_1_0.go +++ b/pkg/api/zz_incidentdetected_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var incidentdetectedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/incident-detected-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.incident.detected.0.1.0"],"default":"dev.cdevents.incident.detected.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["incident"],"default":"incident"},"content":{"properties":{"description":{"type":"string"},"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"service":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"artifactId":{"type":"string","minLength":1}},"additionalProperties":false,"type":"object","required":["environment"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // IncidentDetected event type v0.1.0 @@ -36,7 +35,7 @@ var ( } ) -type IncidentDetectedSubjectContent struct { +type IncidentDetectedSubjectContentV0_1_0 struct { ArtifactId string `json:"artifactId,omitempty" validate:"purl"` Description string `json:"description,omitempty"` @@ -46,18 +45,18 @@ type IncidentDetectedSubjectContent struct { Service *Reference `json:"service,omitempty"` } -type IncidentDetectedSubject struct { +type IncidentDetectedSubjectV0_1_0 struct { SubjectBase - Content IncidentDetectedSubjectContent `json:"content"` + Content IncidentDetectedSubjectContentV0_1_0 `json:"content"` } -func (sc IncidentDetectedSubject) GetSubjectType() SubjectType { +func (sc IncidentDetectedSubjectV0_1_0) GetSubjectType() SubjectType { return "incident" } type IncidentDetectedEventV0_1_0 struct { - Context Context `json:"context"` - Subject IncidentDetectedSubject `json:"subject"` + Context Context `json:"context"` + Subject IncidentDetectedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -147,9 +146,9 @@ func (e *IncidentDetectedEventV0_1_0) SetCustomData(contentType string, data int return nil } -func (e IncidentDetectedEventV0_1_0) GetSchema() (string, string) { +func (e IncidentDetectedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), incidentdetectedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -177,7 +176,7 @@ func NewIncidentDetectedEventV0_1_0(specVersion string) (*IncidentDetectedEventV Type: IncidentDetectedEventTypeV0_1_0, Version: specVersion, }, - Subject: IncidentDetectedSubject{ + Subject: IncidentDetectedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "incident", }, diff --git a/pkg/api/zz_incidentdetected_0_2_0.go b/pkg/api/zz_incidentdetected_0_2_0.go new file mode 100644 index 0000000..ef41adf --- /dev/null +++ b/pkg/api/zz_incidentdetected_0_2_0.go @@ -0,0 +1,222 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // IncidentDetected event type v0.2.0 + IncidentDetectedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "incident", + Predicate: "detected", + Version: "0.2.0", + } +) + +type IncidentDetectedSubjectContentV0_2_0 struct { + ArtifactId string `json:"artifactId,omitempty" validate:"purl"` + + Description string `json:"description,omitempty"` + + Environment *Reference `json:"environment"` + + Service *Reference `json:"service,omitempty"` +} + +type IncidentDetectedSubjectV0_2_0 struct { + SubjectBase + Content IncidentDetectedSubjectContentV0_2_0 `json:"content"` +} + +func (sc IncidentDetectedSubjectV0_2_0) GetSubjectType() SubjectType { + return "incident" +} + +type IncidentDetectedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject IncidentDetectedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e IncidentDetectedEventV0_2_0) GetType() CDEventType { + return IncidentDetectedEventTypeV0_2_0 +} + +func (e IncidentDetectedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e IncidentDetectedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e IncidentDetectedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e IncidentDetectedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e IncidentDetectedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e IncidentDetectedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e IncidentDetectedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e IncidentDetectedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e IncidentDetectedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e IncidentDetectedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e IncidentDetectedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e IncidentDetectedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e IncidentDetectedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e IncidentDetectedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *IncidentDetectedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *IncidentDetectedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *IncidentDetectedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *IncidentDetectedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *IncidentDetectedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *IncidentDetectedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e IncidentDetectedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *IncidentDetectedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *IncidentDetectedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *IncidentDetectedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *IncidentDetectedEventV0_2_0) SetSubjectArtifactId(artifactId string) { + e.Subject.Content.ArtifactId = artifactId +} + +func (e *IncidentDetectedEventV0_2_0) SetSubjectDescription(description string) { + e.Subject.Content.Description = description +} + +func (e *IncidentDetectedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +func (e *IncidentDetectedEventV0_2_0) SetSubjectService(service *Reference) { + e.Subject.Content.Service = service +} + +// New creates a new IncidentDetectedEventV0_2_0 +func NewIncidentDetectedEventV0_2_0(specVersion string) (*IncidentDetectedEventV0_2_0, error) { + e := &IncidentDetectedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: IncidentDetectedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: IncidentDetectedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "incident", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_incidentreported_0_1_0.go b/pkg/api/zz_incidentreported_0_1_0.go index 0bde775..a3a4f23 100644 --- a/pkg/api/zz_incidentreported_0_1_0.go +++ b/pkg/api/zz_incidentreported_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var incidentreportedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/incident-reported-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.incident.reported.0.1.0"],"default":"dev.cdevents.incident.reported.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["incident"],"default":"incident"},"content":{"properties":{"description":{"type":"string"},"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"ticketURI":{"type":"string","format":"uri","minLength":1},"service":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"artifactId":{"type":"string","minLength":1}},"additionalProperties":false,"type":"object","required":["environment","ticketURI"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // IncidentReported event type v0.1.0 @@ -36,7 +35,7 @@ var ( } ) -type IncidentReportedSubjectContent struct { +type IncidentReportedSubjectContentV0_1_0 struct { ArtifactId string `json:"artifactId,omitempty" validate:"purl"` Description string `json:"description,omitempty"` @@ -48,18 +47,18 @@ type IncidentReportedSubjectContent struct { TicketURI string `json:"ticketURI"` } -type IncidentReportedSubject struct { +type IncidentReportedSubjectV0_1_0 struct { SubjectBase - Content IncidentReportedSubjectContent `json:"content"` + Content IncidentReportedSubjectContentV0_1_0 `json:"content"` } -func (sc IncidentReportedSubject) GetSubjectType() SubjectType { +func (sc IncidentReportedSubjectV0_1_0) GetSubjectType() SubjectType { return "incident" } type IncidentReportedEventV0_1_0 struct { - Context Context `json:"context"` - Subject IncidentReportedSubject `json:"subject"` + Context Context `json:"context"` + Subject IncidentReportedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -149,9 +148,9 @@ func (e *IncidentReportedEventV0_1_0) SetCustomData(contentType string, data int return nil } -func (e IncidentReportedEventV0_1_0) GetSchema() (string, string) { +func (e IncidentReportedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), incidentreportedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -183,7 +182,7 @@ func NewIncidentReportedEventV0_1_0(specVersion string) (*IncidentReportedEventV Type: IncidentReportedEventTypeV0_1_0, Version: specVersion, }, - Subject: IncidentReportedSubject{ + Subject: IncidentReportedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "incident", }, diff --git a/pkg/api/zz_incidentreported_0_2_0.go b/pkg/api/zz_incidentreported_0_2_0.go new file mode 100644 index 0000000..ca0f1d6 --- /dev/null +++ b/pkg/api/zz_incidentreported_0_2_0.go @@ -0,0 +1,228 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // IncidentReported event type v0.2.0 + IncidentReportedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "incident", + Predicate: "reported", + Version: "0.2.0", + } +) + +type IncidentReportedSubjectContentV0_2_0 struct { + ArtifactId string `json:"artifactId,omitempty" validate:"purl"` + + Description string `json:"description,omitempty"` + + Environment *Reference `json:"environment"` + + Service *Reference `json:"service,omitempty"` + + TicketURI string `json:"ticketURI"` +} + +type IncidentReportedSubjectV0_2_0 struct { + SubjectBase + Content IncidentReportedSubjectContentV0_2_0 `json:"content"` +} + +func (sc IncidentReportedSubjectV0_2_0) GetSubjectType() SubjectType { + return "incident" +} + +type IncidentReportedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject IncidentReportedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e IncidentReportedEventV0_2_0) GetType() CDEventType { + return IncidentReportedEventTypeV0_2_0 +} + +func (e IncidentReportedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e IncidentReportedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e IncidentReportedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e IncidentReportedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e IncidentReportedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e IncidentReportedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e IncidentReportedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e IncidentReportedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e IncidentReportedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e IncidentReportedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e IncidentReportedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e IncidentReportedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e IncidentReportedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e IncidentReportedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *IncidentReportedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *IncidentReportedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *IncidentReportedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *IncidentReportedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *IncidentReportedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *IncidentReportedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e IncidentReportedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *IncidentReportedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *IncidentReportedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *IncidentReportedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *IncidentReportedEventV0_2_0) SetSubjectArtifactId(artifactId string) { + e.Subject.Content.ArtifactId = artifactId +} + +func (e *IncidentReportedEventV0_2_0) SetSubjectDescription(description string) { + e.Subject.Content.Description = description +} + +func (e *IncidentReportedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +func (e *IncidentReportedEventV0_2_0) SetSubjectService(service *Reference) { + e.Subject.Content.Service = service +} + +func (e *IncidentReportedEventV0_2_0) SetSubjectTicketURI(ticketURI string) { + e.Subject.Content.TicketURI = ticketURI +} + +// New creates a new IncidentReportedEventV0_2_0 +func NewIncidentReportedEventV0_2_0(specVersion string) (*IncidentReportedEventV0_2_0, error) { + e := &IncidentReportedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: IncidentReportedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: IncidentReportedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "incident", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_incidentresolved_0_1_0.go b/pkg/api/zz_incidentresolved_0_1_0.go index 0ef1371..96a7d0b 100644 --- a/pkg/api/zz_incidentresolved_0_1_0.go +++ b/pkg/api/zz_incidentresolved_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var incidentresolvedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/incident-resolved-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.incident.resolved.0.1.0"],"default":"dev.cdevents.incident.resolved.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["incident"],"default":"incident"},"content":{"properties":{"description":{"type":"string"},"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"service":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"artifactId":{"type":"string","minLength":1}},"additionalProperties":false,"type":"object","required":["environment"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // IncidentResolved event type v0.1.0 @@ -36,7 +35,7 @@ var ( } ) -type IncidentResolvedSubjectContent struct { +type IncidentResolvedSubjectContentV0_1_0 struct { ArtifactId string `json:"artifactId,omitempty" validate:"purl"` Description string `json:"description,omitempty"` @@ -46,18 +45,18 @@ type IncidentResolvedSubjectContent struct { Service *Reference `json:"service,omitempty"` } -type IncidentResolvedSubject struct { +type IncidentResolvedSubjectV0_1_0 struct { SubjectBase - Content IncidentResolvedSubjectContent `json:"content"` + Content IncidentResolvedSubjectContentV0_1_0 `json:"content"` } -func (sc IncidentResolvedSubject) GetSubjectType() SubjectType { +func (sc IncidentResolvedSubjectV0_1_0) GetSubjectType() SubjectType { return "incident" } type IncidentResolvedEventV0_1_0 struct { - Context Context `json:"context"` - Subject IncidentResolvedSubject `json:"subject"` + Context Context `json:"context"` + Subject IncidentResolvedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -147,9 +146,9 @@ func (e *IncidentResolvedEventV0_1_0) SetCustomData(contentType string, data int return nil } -func (e IncidentResolvedEventV0_1_0) GetSchema() (string, string) { +func (e IncidentResolvedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), incidentresolvedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -177,7 +176,7 @@ func NewIncidentResolvedEventV0_1_0(specVersion string) (*IncidentResolvedEventV Type: IncidentResolvedEventTypeV0_1_0, Version: specVersion, }, - Subject: IncidentResolvedSubject{ + Subject: IncidentResolvedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "incident", }, diff --git a/pkg/api/zz_incidentresolved_0_2_0.go b/pkg/api/zz_incidentresolved_0_2_0.go new file mode 100644 index 0000000..72189e4 --- /dev/null +++ b/pkg/api/zz_incidentresolved_0_2_0.go @@ -0,0 +1,222 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // IncidentResolved event type v0.2.0 + IncidentResolvedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "incident", + Predicate: "resolved", + Version: "0.2.0", + } +) + +type IncidentResolvedSubjectContentV0_2_0 struct { + ArtifactId string `json:"artifactId,omitempty" validate:"purl"` + + Description string `json:"description,omitempty"` + + Environment *Reference `json:"environment"` + + Service *Reference `json:"service,omitempty"` +} + +type IncidentResolvedSubjectV0_2_0 struct { + SubjectBase + Content IncidentResolvedSubjectContentV0_2_0 `json:"content"` +} + +func (sc IncidentResolvedSubjectV0_2_0) GetSubjectType() SubjectType { + return "incident" +} + +type IncidentResolvedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject IncidentResolvedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e IncidentResolvedEventV0_2_0) GetType() CDEventType { + return IncidentResolvedEventTypeV0_2_0 +} + +func (e IncidentResolvedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e IncidentResolvedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e IncidentResolvedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e IncidentResolvedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e IncidentResolvedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e IncidentResolvedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e IncidentResolvedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e IncidentResolvedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e IncidentResolvedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e IncidentResolvedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e IncidentResolvedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e IncidentResolvedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e IncidentResolvedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e IncidentResolvedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *IncidentResolvedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *IncidentResolvedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *IncidentResolvedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *IncidentResolvedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *IncidentResolvedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *IncidentResolvedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e IncidentResolvedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *IncidentResolvedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *IncidentResolvedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *IncidentResolvedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *IncidentResolvedEventV0_2_0) SetSubjectArtifactId(artifactId string) { + e.Subject.Content.ArtifactId = artifactId +} + +func (e *IncidentResolvedEventV0_2_0) SetSubjectDescription(description string) { + e.Subject.Content.Description = description +} + +func (e *IncidentResolvedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +func (e *IncidentResolvedEventV0_2_0) SetSubjectService(service *Reference) { + e.Subject.Content.Service = service +} + +// New creates a new IncidentResolvedEventV0_2_0 +func NewIncidentResolvedEventV0_2_0(specVersion string) (*IncidentResolvedEventV0_2_0, error) { + e := &IncidentResolvedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: IncidentResolvedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: IncidentResolvedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "incident", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_pipelinerunfinished_0_1_1.go b/pkg/api/zz_pipelinerunfinished_0_1_1.go index abab925..422eb04 100644 --- a/pkg/api/zz_pipelinerunfinished_0_1_1.go +++ b/pkg/api/zz_pipelinerunfinished_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var pipelinerunfinishedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/pipeline-run-finished-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.pipelinerun.finished.0.1.1"],"default":"dev.cdevents.pipelinerun.finished.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["pipelineRun"],"default":"pipelineRun"},"content":{"properties":{"pipelineName":{"type":"string"},"url":{"type":"string"},"outcome":{"type":"string"},"errors":{"type":"string"}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // PipelineRunFinished event type v0.1.1 @@ -36,7 +35,7 @@ var ( } ) -type PipelineRunFinishedSubjectContent struct { +type PipelineRunFinishedSubjectContentV0_1_1 struct { Errors string `json:"errors,omitempty"` Outcome string `json:"outcome,omitempty"` @@ -46,18 +45,18 @@ type PipelineRunFinishedSubjectContent struct { Url string `json:"url,omitempty"` } -type PipelineRunFinishedSubject struct { +type PipelineRunFinishedSubjectV0_1_1 struct { SubjectBase - Content PipelineRunFinishedSubjectContent `json:"content"` + Content PipelineRunFinishedSubjectContentV0_1_1 `json:"content"` } -func (sc PipelineRunFinishedSubject) GetSubjectType() SubjectType { +func (sc PipelineRunFinishedSubjectV0_1_1) GetSubjectType() SubjectType { return "pipelineRun" } type PipelineRunFinishedEventV0_1_1 struct { - Context Context `json:"context"` - Subject PipelineRunFinishedSubject `json:"subject"` + Context Context `json:"context"` + Subject PipelineRunFinishedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -147,9 +146,9 @@ func (e *PipelineRunFinishedEventV0_1_1) SetCustomData(contentType string, data return nil } -func (e PipelineRunFinishedEventV0_1_1) GetSchema() (string, string) { +func (e PipelineRunFinishedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), pipelinerunfinishedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -177,7 +176,7 @@ func NewPipelineRunFinishedEventV0_1_1(specVersion string) (*PipelineRunFinished Type: PipelineRunFinishedEventTypeV0_1_1, Version: specVersion, }, - Subject: PipelineRunFinishedSubject{ + Subject: PipelineRunFinishedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "pipelineRun", }, diff --git a/pkg/api/zz_pipelinerunfinished_0_2_0.go b/pkg/api/zz_pipelinerunfinished_0_2_0.go new file mode 100644 index 0000000..8a3a59f --- /dev/null +++ b/pkg/api/zz_pipelinerunfinished_0_2_0.go @@ -0,0 +1,222 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // PipelineRunFinished event type v0.2.0 + PipelineRunFinishedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "pipelinerun", + Predicate: "finished", + Version: "0.2.0", + } +) + +type PipelineRunFinishedSubjectContentV0_2_0 struct { + Errors string `json:"errors,omitempty"` + + Outcome string `json:"outcome,omitempty"` + + PipelineName string `json:"pipelineName,omitempty"` + + Url string `json:"url,omitempty"` +} + +type PipelineRunFinishedSubjectV0_2_0 struct { + SubjectBase + Content PipelineRunFinishedSubjectContentV0_2_0 `json:"content"` +} + +func (sc PipelineRunFinishedSubjectV0_2_0) GetSubjectType() SubjectType { + return "pipelineRun" +} + +type PipelineRunFinishedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject PipelineRunFinishedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e PipelineRunFinishedEventV0_2_0) GetType() CDEventType { + return PipelineRunFinishedEventTypeV0_2_0 +} + +func (e PipelineRunFinishedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e PipelineRunFinishedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e PipelineRunFinishedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e PipelineRunFinishedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e PipelineRunFinishedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e PipelineRunFinishedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e PipelineRunFinishedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e PipelineRunFinishedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e PipelineRunFinishedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e PipelineRunFinishedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e PipelineRunFinishedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e PipelineRunFinishedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e PipelineRunFinishedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e PipelineRunFinishedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *PipelineRunFinishedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *PipelineRunFinishedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *PipelineRunFinishedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *PipelineRunFinishedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *PipelineRunFinishedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *PipelineRunFinishedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e PipelineRunFinishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *PipelineRunFinishedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *PipelineRunFinishedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *PipelineRunFinishedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *PipelineRunFinishedEventV0_2_0) SetSubjectErrors(errors string) { + e.Subject.Content.Errors = errors +} + +func (e *PipelineRunFinishedEventV0_2_0) SetSubjectOutcome(outcome string) { + e.Subject.Content.Outcome = outcome +} + +func (e *PipelineRunFinishedEventV0_2_0) SetSubjectPipelineName(pipelineName string) { + e.Subject.Content.PipelineName = pipelineName +} + +func (e *PipelineRunFinishedEventV0_2_0) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +// New creates a new PipelineRunFinishedEventV0_2_0 +func NewPipelineRunFinishedEventV0_2_0(specVersion string) (*PipelineRunFinishedEventV0_2_0, error) { + e := &PipelineRunFinishedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: PipelineRunFinishedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: PipelineRunFinishedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "pipelineRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_pipelinerunqueued_0_1_1.go b/pkg/api/zz_pipelinerunqueued_0_1_1.go index 38241f2..434bfad 100644 --- a/pkg/api/zz_pipelinerunqueued_0_1_1.go +++ b/pkg/api/zz_pipelinerunqueued_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var pipelinerunqueuedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/pipeline-run-queued-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.pipelinerun.queued.0.1.1"],"default":"dev.cdevents.pipelinerun.queued.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["pipelineRun"],"default":"pipelineRun"},"content":{"properties":{"pipelineName":{"type":"string"},"url":{"type":"string"}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // PipelineRunQueued event type v0.1.1 @@ -36,24 +35,24 @@ var ( } ) -type PipelineRunQueuedSubjectContent struct { +type PipelineRunQueuedSubjectContentV0_1_1 struct { PipelineName string `json:"pipelineName,omitempty"` Url string `json:"url,omitempty"` } -type PipelineRunQueuedSubject struct { +type PipelineRunQueuedSubjectV0_1_1 struct { SubjectBase - Content PipelineRunQueuedSubjectContent `json:"content"` + Content PipelineRunQueuedSubjectContentV0_1_1 `json:"content"` } -func (sc PipelineRunQueuedSubject) GetSubjectType() SubjectType { +func (sc PipelineRunQueuedSubjectV0_1_1) GetSubjectType() SubjectType { return "pipelineRun" } type PipelineRunQueuedEventV0_1_1 struct { - Context Context `json:"context"` - Subject PipelineRunQueuedSubject `json:"subject"` + Context Context `json:"context"` + Subject PipelineRunQueuedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -143,9 +142,9 @@ func (e *PipelineRunQueuedEventV0_1_1) SetCustomData(contentType string, data in return nil } -func (e PipelineRunQueuedEventV0_1_1) GetSchema() (string, string) { +func (e PipelineRunQueuedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), pipelinerunqueuedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -165,7 +164,7 @@ func NewPipelineRunQueuedEventV0_1_1(specVersion string) (*PipelineRunQueuedEven Type: PipelineRunQueuedEventTypeV0_1_1, Version: specVersion, }, - Subject: PipelineRunQueuedSubject{ + Subject: PipelineRunQueuedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "pipelineRun", }, diff --git a/pkg/api/zz_pipelinerunqueued_0_2_0.go b/pkg/api/zz_pipelinerunqueued_0_2_0.go new file mode 100644 index 0000000..b24e144 --- /dev/null +++ b/pkg/api/zz_pipelinerunqueued_0_2_0.go @@ -0,0 +1,210 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // PipelineRunQueued event type v0.2.0 + PipelineRunQueuedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "pipelinerun", + Predicate: "queued", + Version: "0.2.0", + } +) + +type PipelineRunQueuedSubjectContentV0_2_0 struct { + PipelineName string `json:"pipelineName,omitempty"` + + Url string `json:"url,omitempty"` +} + +type PipelineRunQueuedSubjectV0_2_0 struct { + SubjectBase + Content PipelineRunQueuedSubjectContentV0_2_0 `json:"content"` +} + +func (sc PipelineRunQueuedSubjectV0_2_0) GetSubjectType() SubjectType { + return "pipelineRun" +} + +type PipelineRunQueuedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject PipelineRunQueuedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e PipelineRunQueuedEventV0_2_0) GetType() CDEventType { + return PipelineRunQueuedEventTypeV0_2_0 +} + +func (e PipelineRunQueuedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e PipelineRunQueuedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e PipelineRunQueuedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e PipelineRunQueuedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e PipelineRunQueuedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e PipelineRunQueuedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e PipelineRunQueuedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e PipelineRunQueuedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e PipelineRunQueuedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e PipelineRunQueuedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e PipelineRunQueuedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e PipelineRunQueuedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e PipelineRunQueuedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e PipelineRunQueuedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *PipelineRunQueuedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *PipelineRunQueuedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *PipelineRunQueuedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *PipelineRunQueuedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *PipelineRunQueuedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *PipelineRunQueuedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e PipelineRunQueuedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *PipelineRunQueuedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *PipelineRunQueuedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *PipelineRunQueuedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *PipelineRunQueuedEventV0_2_0) SetSubjectPipelineName(pipelineName string) { + e.Subject.Content.PipelineName = pipelineName +} + +func (e *PipelineRunQueuedEventV0_2_0) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +// New creates a new PipelineRunQueuedEventV0_2_0 +func NewPipelineRunQueuedEventV0_2_0(specVersion string) (*PipelineRunQueuedEventV0_2_0, error) { + e := &PipelineRunQueuedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: PipelineRunQueuedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: PipelineRunQueuedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "pipelineRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_pipelinerunstarted_0_1_1.go b/pkg/api/zz_pipelinerunstarted_0_1_1.go index f704aae..842d1e8 100644 --- a/pkg/api/zz_pipelinerunstarted_0_1_1.go +++ b/pkg/api/zz_pipelinerunstarted_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var pipelinerunstartedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/pipeline-run-started-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.pipelinerun.started.0.1.1"],"default":"dev.cdevents.pipelinerun.started.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["pipelineRun"],"default":"pipelineRun"},"content":{"properties":{"pipelineName":{"type":"string"},"url":{"type":"string"}},"additionalProperties":false,"type":"object","required":["pipelineName","url"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // PipelineRunStarted event type v0.1.1 @@ -36,24 +35,24 @@ var ( } ) -type PipelineRunStartedSubjectContent struct { +type PipelineRunStartedSubjectContentV0_1_1 struct { PipelineName string `json:"pipelineName"` Url string `json:"url"` } -type PipelineRunStartedSubject struct { +type PipelineRunStartedSubjectV0_1_1 struct { SubjectBase - Content PipelineRunStartedSubjectContent `json:"content"` + Content PipelineRunStartedSubjectContentV0_1_1 `json:"content"` } -func (sc PipelineRunStartedSubject) GetSubjectType() SubjectType { +func (sc PipelineRunStartedSubjectV0_1_1) GetSubjectType() SubjectType { return "pipelineRun" } type PipelineRunStartedEventV0_1_1 struct { - Context Context `json:"context"` - Subject PipelineRunStartedSubject `json:"subject"` + Context Context `json:"context"` + Subject PipelineRunStartedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -143,9 +142,9 @@ func (e *PipelineRunStartedEventV0_1_1) SetCustomData(contentType string, data i return nil } -func (e PipelineRunStartedEventV0_1_1) GetSchema() (string, string) { +func (e PipelineRunStartedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), pipelinerunstartedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -165,7 +164,7 @@ func NewPipelineRunStartedEventV0_1_1(specVersion string) (*PipelineRunStartedEv Type: PipelineRunStartedEventTypeV0_1_1, Version: specVersion, }, - Subject: PipelineRunStartedSubject{ + Subject: PipelineRunStartedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "pipelineRun", }, diff --git a/pkg/api/zz_pipelinerunstarted_0_2_0.go b/pkg/api/zz_pipelinerunstarted_0_2_0.go new file mode 100644 index 0000000..46703c5 --- /dev/null +++ b/pkg/api/zz_pipelinerunstarted_0_2_0.go @@ -0,0 +1,210 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // PipelineRunStarted event type v0.2.0 + PipelineRunStartedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "pipelinerun", + Predicate: "started", + Version: "0.2.0", + } +) + +type PipelineRunStartedSubjectContentV0_2_0 struct { + PipelineName string `json:"pipelineName"` + + Url string `json:"url"` +} + +type PipelineRunStartedSubjectV0_2_0 struct { + SubjectBase + Content PipelineRunStartedSubjectContentV0_2_0 `json:"content"` +} + +func (sc PipelineRunStartedSubjectV0_2_0) GetSubjectType() SubjectType { + return "pipelineRun" +} + +type PipelineRunStartedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject PipelineRunStartedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e PipelineRunStartedEventV0_2_0) GetType() CDEventType { + return PipelineRunStartedEventTypeV0_2_0 +} + +func (e PipelineRunStartedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e PipelineRunStartedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e PipelineRunStartedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e PipelineRunStartedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e PipelineRunStartedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e PipelineRunStartedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e PipelineRunStartedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e PipelineRunStartedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e PipelineRunStartedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e PipelineRunStartedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e PipelineRunStartedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e PipelineRunStartedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e PipelineRunStartedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e PipelineRunStartedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *PipelineRunStartedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *PipelineRunStartedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *PipelineRunStartedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *PipelineRunStartedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *PipelineRunStartedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *PipelineRunStartedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e PipelineRunStartedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *PipelineRunStartedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *PipelineRunStartedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *PipelineRunStartedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *PipelineRunStartedEventV0_2_0) SetSubjectPipelineName(pipelineName string) { + e.Subject.Content.PipelineName = pipelineName +} + +func (e *PipelineRunStartedEventV0_2_0) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +// New creates a new PipelineRunStartedEventV0_2_0 +func NewPipelineRunStartedEventV0_2_0(specVersion string) (*PipelineRunStartedEventV0_2_0, error) { + e := &PipelineRunStartedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: PipelineRunStartedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: PipelineRunStartedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "pipelineRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_repositorycreated_0_1_1.go b/pkg/api/zz_repositorycreated_0_1_1.go index 8d426ba..32ef75c 100644 --- a/pkg/api/zz_repositorycreated_0_1_1.go +++ b/pkg/api/zz_repositorycreated_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var repositorycreatedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/repository-created-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.repository.created.0.1.1"],"default":"dev.cdevents.repository.created.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["repository"],"default":"repository"},"content":{"properties":{"name":{"type":"string","minLength":1},"owner":{"type":"string"},"url":{"type":"string","minLength":1},"viewUrl":{"type":"string"}},"additionalProperties":false,"type":"object","required":["name","url"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // RepositoryCreated event type v0.1.1 @@ -36,7 +35,7 @@ var ( } ) -type RepositoryCreatedSubjectContent struct { +type RepositoryCreatedSubjectContentV0_1_1 struct { Name string `json:"name"` Owner string `json:"owner,omitempty"` @@ -46,18 +45,18 @@ type RepositoryCreatedSubjectContent struct { ViewUrl string `json:"viewUrl,omitempty"` } -type RepositoryCreatedSubject struct { +type RepositoryCreatedSubjectV0_1_1 struct { SubjectBase - Content RepositoryCreatedSubjectContent `json:"content"` + Content RepositoryCreatedSubjectContentV0_1_1 `json:"content"` } -func (sc RepositoryCreatedSubject) GetSubjectType() SubjectType { +func (sc RepositoryCreatedSubjectV0_1_1) GetSubjectType() SubjectType { return "repository" } type RepositoryCreatedEventV0_1_1 struct { - Context Context `json:"context"` - Subject RepositoryCreatedSubject `json:"subject"` + Context Context `json:"context"` + Subject RepositoryCreatedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -147,9 +146,9 @@ func (e *RepositoryCreatedEventV0_1_1) SetCustomData(contentType string, data in return nil } -func (e RepositoryCreatedEventV0_1_1) GetSchema() (string, string) { +func (e RepositoryCreatedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), repositorycreatedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -177,7 +176,7 @@ func NewRepositoryCreatedEventV0_1_1(specVersion string) (*RepositoryCreatedEven Type: RepositoryCreatedEventTypeV0_1_1, Version: specVersion, }, - Subject: RepositoryCreatedSubject{ + Subject: RepositoryCreatedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "repository", }, diff --git a/pkg/api/zz_repositorycreated_0_2_0.go b/pkg/api/zz_repositorycreated_0_2_0.go new file mode 100644 index 0000000..9c04633 --- /dev/null +++ b/pkg/api/zz_repositorycreated_0_2_0.go @@ -0,0 +1,222 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // RepositoryCreated event type v0.2.0 + RepositoryCreatedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "repository", + Predicate: "created", + Version: "0.2.0", + } +) + +type RepositoryCreatedSubjectContentV0_2_0 struct { + Name string `json:"name"` + + Owner string `json:"owner,omitempty"` + + Url string `json:"url"` + + ViewUrl string `json:"viewUrl,omitempty"` +} + +type RepositoryCreatedSubjectV0_2_0 struct { + SubjectBase + Content RepositoryCreatedSubjectContentV0_2_0 `json:"content"` +} + +func (sc RepositoryCreatedSubjectV0_2_0) GetSubjectType() SubjectType { + return "repository" +} + +type RepositoryCreatedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject RepositoryCreatedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e RepositoryCreatedEventV0_2_0) GetType() CDEventType { + return RepositoryCreatedEventTypeV0_2_0 +} + +func (e RepositoryCreatedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e RepositoryCreatedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e RepositoryCreatedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e RepositoryCreatedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e RepositoryCreatedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e RepositoryCreatedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e RepositoryCreatedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e RepositoryCreatedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e RepositoryCreatedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e RepositoryCreatedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e RepositoryCreatedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e RepositoryCreatedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e RepositoryCreatedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e RepositoryCreatedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *RepositoryCreatedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *RepositoryCreatedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *RepositoryCreatedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *RepositoryCreatedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *RepositoryCreatedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *RepositoryCreatedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e RepositoryCreatedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *RepositoryCreatedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *RepositoryCreatedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *RepositoryCreatedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *RepositoryCreatedEventV0_2_0) SetSubjectName(name string) { + e.Subject.Content.Name = name +} + +func (e *RepositoryCreatedEventV0_2_0) SetSubjectOwner(owner string) { + e.Subject.Content.Owner = owner +} + +func (e *RepositoryCreatedEventV0_2_0) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +func (e *RepositoryCreatedEventV0_2_0) SetSubjectViewUrl(viewUrl string) { + e.Subject.Content.ViewUrl = viewUrl +} + +// New creates a new RepositoryCreatedEventV0_2_0 +func NewRepositoryCreatedEventV0_2_0(specVersion string) (*RepositoryCreatedEventV0_2_0, error) { + e := &RepositoryCreatedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: RepositoryCreatedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: RepositoryCreatedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "repository", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_repositorydeleted_0_1_1.go b/pkg/api/zz_repositorydeleted_0_1_1.go index 26c5c00..acf1d41 100644 --- a/pkg/api/zz_repositorydeleted_0_1_1.go +++ b/pkg/api/zz_repositorydeleted_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var repositorydeletedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/repository-deleted-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.repository.deleted.0.1.1"],"default":"dev.cdevents.repository.deleted.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["repository"],"default":"repository"},"content":{"properties":{"name":{"type":"string"},"owner":{"type":"string"},"url":{"type":"string"},"viewUrl":{"type":"string"}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // RepositoryDeleted event type v0.1.1 @@ -36,7 +35,7 @@ var ( } ) -type RepositoryDeletedSubjectContent struct { +type RepositoryDeletedSubjectContentV0_1_1 struct { Name string `json:"name,omitempty"` Owner string `json:"owner,omitempty"` @@ -46,18 +45,18 @@ type RepositoryDeletedSubjectContent struct { ViewUrl string `json:"viewUrl,omitempty"` } -type RepositoryDeletedSubject struct { +type RepositoryDeletedSubjectV0_1_1 struct { SubjectBase - Content RepositoryDeletedSubjectContent `json:"content"` + Content RepositoryDeletedSubjectContentV0_1_1 `json:"content"` } -func (sc RepositoryDeletedSubject) GetSubjectType() SubjectType { +func (sc RepositoryDeletedSubjectV0_1_1) GetSubjectType() SubjectType { return "repository" } type RepositoryDeletedEventV0_1_1 struct { - Context Context `json:"context"` - Subject RepositoryDeletedSubject `json:"subject"` + Context Context `json:"context"` + Subject RepositoryDeletedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -147,9 +146,9 @@ func (e *RepositoryDeletedEventV0_1_1) SetCustomData(contentType string, data in return nil } -func (e RepositoryDeletedEventV0_1_1) GetSchema() (string, string) { +func (e RepositoryDeletedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), repositorydeletedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -177,7 +176,7 @@ func NewRepositoryDeletedEventV0_1_1(specVersion string) (*RepositoryDeletedEven Type: RepositoryDeletedEventTypeV0_1_1, Version: specVersion, }, - Subject: RepositoryDeletedSubject{ + Subject: RepositoryDeletedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "repository", }, diff --git a/pkg/api/zz_repositorydeleted_0_2_0.go b/pkg/api/zz_repositorydeleted_0_2_0.go new file mode 100644 index 0000000..ac700f8 --- /dev/null +++ b/pkg/api/zz_repositorydeleted_0_2_0.go @@ -0,0 +1,222 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // RepositoryDeleted event type v0.2.0 + RepositoryDeletedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "repository", + Predicate: "deleted", + Version: "0.2.0", + } +) + +type RepositoryDeletedSubjectContentV0_2_0 struct { + Name string `json:"name,omitempty"` + + Owner string `json:"owner,omitempty"` + + Url string `json:"url,omitempty"` + + ViewUrl string `json:"viewUrl,omitempty"` +} + +type RepositoryDeletedSubjectV0_2_0 struct { + SubjectBase + Content RepositoryDeletedSubjectContentV0_2_0 `json:"content"` +} + +func (sc RepositoryDeletedSubjectV0_2_0) GetSubjectType() SubjectType { + return "repository" +} + +type RepositoryDeletedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject RepositoryDeletedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e RepositoryDeletedEventV0_2_0) GetType() CDEventType { + return RepositoryDeletedEventTypeV0_2_0 +} + +func (e RepositoryDeletedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e RepositoryDeletedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e RepositoryDeletedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e RepositoryDeletedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e RepositoryDeletedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e RepositoryDeletedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e RepositoryDeletedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e RepositoryDeletedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e RepositoryDeletedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e RepositoryDeletedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e RepositoryDeletedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e RepositoryDeletedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e RepositoryDeletedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e RepositoryDeletedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *RepositoryDeletedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *RepositoryDeletedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *RepositoryDeletedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *RepositoryDeletedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *RepositoryDeletedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *RepositoryDeletedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e RepositoryDeletedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *RepositoryDeletedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *RepositoryDeletedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *RepositoryDeletedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *RepositoryDeletedEventV0_2_0) SetSubjectName(name string) { + e.Subject.Content.Name = name +} + +func (e *RepositoryDeletedEventV0_2_0) SetSubjectOwner(owner string) { + e.Subject.Content.Owner = owner +} + +func (e *RepositoryDeletedEventV0_2_0) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +func (e *RepositoryDeletedEventV0_2_0) SetSubjectViewUrl(viewUrl string) { + e.Subject.Content.ViewUrl = viewUrl +} + +// New creates a new RepositoryDeletedEventV0_2_0 +func NewRepositoryDeletedEventV0_2_0(specVersion string) (*RepositoryDeletedEventV0_2_0, error) { + e := &RepositoryDeletedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: RepositoryDeletedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: RepositoryDeletedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "repository", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_repositorymodified_0_1_1.go b/pkg/api/zz_repositorymodified_0_1_1.go index e668e39..6d902de 100644 --- a/pkg/api/zz_repositorymodified_0_1_1.go +++ b/pkg/api/zz_repositorymodified_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var repositorymodifiedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/repository-modified-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.repository.modified.0.1.1"],"default":"dev.cdevents.repository.modified.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["repository"],"default":"repository"},"content":{"properties":{"name":{"type":"string"},"owner":{"type":"string"},"url":{"type":"string"},"viewUrl":{"type":"string"}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // RepositoryModified event type v0.1.1 @@ -36,7 +35,7 @@ var ( } ) -type RepositoryModifiedSubjectContent struct { +type RepositoryModifiedSubjectContentV0_1_1 struct { Name string `json:"name,omitempty"` Owner string `json:"owner,omitempty"` @@ -46,18 +45,18 @@ type RepositoryModifiedSubjectContent struct { ViewUrl string `json:"viewUrl,omitempty"` } -type RepositoryModifiedSubject struct { +type RepositoryModifiedSubjectV0_1_1 struct { SubjectBase - Content RepositoryModifiedSubjectContent `json:"content"` + Content RepositoryModifiedSubjectContentV0_1_1 `json:"content"` } -func (sc RepositoryModifiedSubject) GetSubjectType() SubjectType { +func (sc RepositoryModifiedSubjectV0_1_1) GetSubjectType() SubjectType { return "repository" } type RepositoryModifiedEventV0_1_1 struct { - Context Context `json:"context"` - Subject RepositoryModifiedSubject `json:"subject"` + Context Context `json:"context"` + Subject RepositoryModifiedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -147,9 +146,9 @@ func (e *RepositoryModifiedEventV0_1_1) SetCustomData(contentType string, data i return nil } -func (e RepositoryModifiedEventV0_1_1) GetSchema() (string, string) { +func (e RepositoryModifiedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), repositorymodifiedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -177,7 +176,7 @@ func NewRepositoryModifiedEventV0_1_1(specVersion string) (*RepositoryModifiedEv Type: RepositoryModifiedEventTypeV0_1_1, Version: specVersion, }, - Subject: RepositoryModifiedSubject{ + Subject: RepositoryModifiedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "repository", }, diff --git a/pkg/api/zz_repositorymodified_0_2_0.go b/pkg/api/zz_repositorymodified_0_2_0.go new file mode 100644 index 0000000..411211c --- /dev/null +++ b/pkg/api/zz_repositorymodified_0_2_0.go @@ -0,0 +1,222 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // RepositoryModified event type v0.2.0 + RepositoryModifiedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "repository", + Predicate: "modified", + Version: "0.2.0", + } +) + +type RepositoryModifiedSubjectContentV0_2_0 struct { + Name string `json:"name,omitempty"` + + Owner string `json:"owner,omitempty"` + + Url string `json:"url,omitempty"` + + ViewUrl string `json:"viewUrl,omitempty"` +} + +type RepositoryModifiedSubjectV0_2_0 struct { + SubjectBase + Content RepositoryModifiedSubjectContentV0_2_0 `json:"content"` +} + +func (sc RepositoryModifiedSubjectV0_2_0) GetSubjectType() SubjectType { + return "repository" +} + +type RepositoryModifiedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject RepositoryModifiedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e RepositoryModifiedEventV0_2_0) GetType() CDEventType { + return RepositoryModifiedEventTypeV0_2_0 +} + +func (e RepositoryModifiedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e RepositoryModifiedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e RepositoryModifiedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e RepositoryModifiedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e RepositoryModifiedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e RepositoryModifiedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e RepositoryModifiedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e RepositoryModifiedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e RepositoryModifiedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e RepositoryModifiedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e RepositoryModifiedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e RepositoryModifiedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e RepositoryModifiedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e RepositoryModifiedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *RepositoryModifiedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *RepositoryModifiedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *RepositoryModifiedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *RepositoryModifiedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *RepositoryModifiedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *RepositoryModifiedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e RepositoryModifiedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *RepositoryModifiedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *RepositoryModifiedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *RepositoryModifiedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *RepositoryModifiedEventV0_2_0) SetSubjectName(name string) { + e.Subject.Content.Name = name +} + +func (e *RepositoryModifiedEventV0_2_0) SetSubjectOwner(owner string) { + e.Subject.Content.Owner = owner +} + +func (e *RepositoryModifiedEventV0_2_0) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +func (e *RepositoryModifiedEventV0_2_0) SetSubjectViewUrl(viewUrl string) { + e.Subject.Content.ViewUrl = viewUrl +} + +// New creates a new RepositoryModifiedEventV0_2_0 +func NewRepositoryModifiedEventV0_2_0(specVersion string) (*RepositoryModifiedEventV0_2_0, error) { + e := &RepositoryModifiedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: RepositoryModifiedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: RepositoryModifiedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "repository", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_servicedeployed_0_1_1.go b/pkg/api/zz_servicedeployed_0_1_1.go index 3d0101c..0d14fc3 100644 --- a/pkg/api/zz_servicedeployed_0_1_1.go +++ b/pkg/api/zz_servicedeployed_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var servicedeployedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/service-deployed-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.service.deployed.0.1.1"],"default":"dev.cdevents.service.deployed.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["service"],"default":"service"},"content":{"properties":{"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"artifactId":{"type":"string","minLength":1}},"additionalProperties":false,"type":"object","required":["environment","artifactId"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ServiceDeployed event type v0.1.1 @@ -36,24 +35,24 @@ var ( } ) -type ServiceDeployedSubjectContent struct { +type ServiceDeployedSubjectContentV0_1_1 struct { ArtifactId string `json:"artifactId" validate:"purl"` Environment *Reference `json:"environment"` } -type ServiceDeployedSubject struct { +type ServiceDeployedSubjectV0_1_1 struct { SubjectBase - Content ServiceDeployedSubjectContent `json:"content"` + Content ServiceDeployedSubjectContentV0_1_1 `json:"content"` } -func (sc ServiceDeployedSubject) GetSubjectType() SubjectType { +func (sc ServiceDeployedSubjectV0_1_1) GetSubjectType() SubjectType { return "service" } type ServiceDeployedEventV0_1_1 struct { - Context Context `json:"context"` - Subject ServiceDeployedSubject `json:"subject"` + Context Context `json:"context"` + Subject ServiceDeployedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -143,9 +142,9 @@ func (e *ServiceDeployedEventV0_1_1) SetCustomData(contentType string, data inte return nil } -func (e ServiceDeployedEventV0_1_1) GetSchema() (string, string) { +func (e ServiceDeployedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), servicedeployedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -165,7 +164,7 @@ func NewServiceDeployedEventV0_1_1(specVersion string) (*ServiceDeployedEventV0_ Type: ServiceDeployedEventTypeV0_1_1, Version: specVersion, }, - Subject: ServiceDeployedSubject{ + Subject: ServiceDeployedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "service", }, diff --git a/pkg/api/zz_servicedeployed_0_2_0.go b/pkg/api/zz_servicedeployed_0_2_0.go new file mode 100644 index 0000000..e7c1a75 --- /dev/null +++ b/pkg/api/zz_servicedeployed_0_2_0.go @@ -0,0 +1,210 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ServiceDeployed event type v0.2.0 + ServiceDeployedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "service", + Predicate: "deployed", + Version: "0.2.0", + } +) + +type ServiceDeployedSubjectContentV0_2_0 struct { + ArtifactId string `json:"artifactId" validate:"purl"` + + Environment *Reference `json:"environment"` +} + +type ServiceDeployedSubjectV0_2_0 struct { + SubjectBase + Content ServiceDeployedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ServiceDeployedSubjectV0_2_0) GetSubjectType() SubjectType { + return "service" +} + +type ServiceDeployedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ServiceDeployedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ServiceDeployedEventV0_2_0) GetType() CDEventType { + return ServiceDeployedEventTypeV0_2_0 +} + +func (e ServiceDeployedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ServiceDeployedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ServiceDeployedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ServiceDeployedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ServiceDeployedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ServiceDeployedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ServiceDeployedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ServiceDeployedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ServiceDeployedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ServiceDeployedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ServiceDeployedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ServiceDeployedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ServiceDeployedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ServiceDeployedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ServiceDeployedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ServiceDeployedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ServiceDeployedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ServiceDeployedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ServiceDeployedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ServiceDeployedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ServiceDeployedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ServiceDeployedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ServiceDeployedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ServiceDeployedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ServiceDeployedEventV0_2_0) SetSubjectArtifactId(artifactId string) { + e.Subject.Content.ArtifactId = artifactId +} + +func (e *ServiceDeployedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +// New creates a new ServiceDeployedEventV0_2_0 +func NewServiceDeployedEventV0_2_0(specVersion string) (*ServiceDeployedEventV0_2_0, error) { + e := &ServiceDeployedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ServiceDeployedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ServiceDeployedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "service", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_servicepublished_0_1_1.go b/pkg/api/zz_servicepublished_0_1_1.go index a98d611..a1483b2 100644 --- a/pkg/api/zz_servicepublished_0_1_1.go +++ b/pkg/api/zz_servicepublished_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var servicepublishedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/service-published-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.service.published.0.1.1"],"default":"dev.cdevents.service.published.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["service"],"default":"service"},"content":{"properties":{"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ServicePublished event type v0.1.1 @@ -36,22 +35,22 @@ var ( } ) -type ServicePublishedSubjectContent struct { +type ServicePublishedSubjectContentV0_1_1 struct { Environment *Reference `json:"environment,omitempty"` } -type ServicePublishedSubject struct { +type ServicePublishedSubjectV0_1_1 struct { SubjectBase - Content ServicePublishedSubjectContent `json:"content"` + Content ServicePublishedSubjectContentV0_1_1 `json:"content"` } -func (sc ServicePublishedSubject) GetSubjectType() SubjectType { +func (sc ServicePublishedSubjectV0_1_1) GetSubjectType() SubjectType { return "service" } type ServicePublishedEventV0_1_1 struct { - Context Context `json:"context"` - Subject ServicePublishedSubject `json:"subject"` + Context Context `json:"context"` + Subject ServicePublishedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *ServicePublishedEventV0_1_1) SetCustomData(contentType string, data int return nil } -func (e ServicePublishedEventV0_1_1) GetSchema() (string, string) { +func (e ServicePublishedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), servicepublishedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewServicePublishedEventV0_1_1(specVersion string) (*ServicePublishedEventV Type: ServicePublishedEventTypeV0_1_1, Version: specVersion, }, - Subject: ServicePublishedSubject{ + Subject: ServicePublishedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "service", }, diff --git a/pkg/api/zz_servicepublished_0_2_0.go b/pkg/api/zz_servicepublished_0_2_0.go new file mode 100644 index 0000000..81c88b6 --- /dev/null +++ b/pkg/api/zz_servicepublished_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ServicePublished event type v0.2.0 + ServicePublishedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "service", + Predicate: "published", + Version: "0.2.0", + } +) + +type ServicePublishedSubjectContentV0_2_0 struct { + Environment *Reference `json:"environment,omitempty"` +} + +type ServicePublishedSubjectV0_2_0 struct { + SubjectBase + Content ServicePublishedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ServicePublishedSubjectV0_2_0) GetSubjectType() SubjectType { + return "service" +} + +type ServicePublishedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ServicePublishedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ServicePublishedEventV0_2_0) GetType() CDEventType { + return ServicePublishedEventTypeV0_2_0 +} + +func (e ServicePublishedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ServicePublishedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ServicePublishedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ServicePublishedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ServicePublishedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ServicePublishedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ServicePublishedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ServicePublishedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ServicePublishedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ServicePublishedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ServicePublishedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ServicePublishedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ServicePublishedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ServicePublishedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ServicePublishedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ServicePublishedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ServicePublishedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ServicePublishedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ServicePublishedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ServicePublishedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ServicePublishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ServicePublishedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ServicePublishedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ServicePublishedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ServicePublishedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +// New creates a new ServicePublishedEventV0_2_0 +func NewServicePublishedEventV0_2_0(specVersion string) (*ServicePublishedEventV0_2_0, error) { + e := &ServicePublishedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ServicePublishedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ServicePublishedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "service", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_serviceremoved_0_1_1.go b/pkg/api/zz_serviceremoved_0_1_1.go index 063e7e1..7292271 100644 --- a/pkg/api/zz_serviceremoved_0_1_1.go +++ b/pkg/api/zz_serviceremoved_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var serviceremovedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/service-removed-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.service.removed.0.1.1"],"default":"dev.cdevents.service.removed.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["service"],"default":"service"},"content":{"properties":{"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ServiceRemoved event type v0.1.1 @@ -36,22 +35,22 @@ var ( } ) -type ServiceRemovedSubjectContent struct { +type ServiceRemovedSubjectContentV0_1_1 struct { Environment *Reference `json:"environment,omitempty"` } -type ServiceRemovedSubject struct { +type ServiceRemovedSubjectV0_1_1 struct { SubjectBase - Content ServiceRemovedSubjectContent `json:"content"` + Content ServiceRemovedSubjectContentV0_1_1 `json:"content"` } -func (sc ServiceRemovedSubject) GetSubjectType() SubjectType { +func (sc ServiceRemovedSubjectV0_1_1) GetSubjectType() SubjectType { return "service" } type ServiceRemovedEventV0_1_1 struct { - Context Context `json:"context"` - Subject ServiceRemovedSubject `json:"subject"` + Context Context `json:"context"` + Subject ServiceRemovedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -141,9 +140,9 @@ func (e *ServiceRemovedEventV0_1_1) SetCustomData(contentType string, data inter return nil } -func (e ServiceRemovedEventV0_1_1) GetSchema() (string, string) { +func (e ServiceRemovedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), serviceremovedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -159,7 +158,7 @@ func NewServiceRemovedEventV0_1_1(specVersion string) (*ServiceRemovedEventV0_1_ Type: ServiceRemovedEventTypeV0_1_1, Version: specVersion, }, - Subject: ServiceRemovedSubject{ + Subject: ServiceRemovedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "service", }, diff --git a/pkg/api/zz_serviceremoved_0_2_0.go b/pkg/api/zz_serviceremoved_0_2_0.go new file mode 100644 index 0000000..82d6021 --- /dev/null +++ b/pkg/api/zz_serviceremoved_0_2_0.go @@ -0,0 +1,204 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ServiceRemoved event type v0.2.0 + ServiceRemovedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "service", + Predicate: "removed", + Version: "0.2.0", + } +) + +type ServiceRemovedSubjectContentV0_2_0 struct { + Environment *Reference `json:"environment,omitempty"` +} + +type ServiceRemovedSubjectV0_2_0 struct { + SubjectBase + Content ServiceRemovedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ServiceRemovedSubjectV0_2_0) GetSubjectType() SubjectType { + return "service" +} + +type ServiceRemovedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ServiceRemovedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ServiceRemovedEventV0_2_0) GetType() CDEventType { + return ServiceRemovedEventTypeV0_2_0 +} + +func (e ServiceRemovedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ServiceRemovedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ServiceRemovedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ServiceRemovedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ServiceRemovedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ServiceRemovedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ServiceRemovedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ServiceRemovedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ServiceRemovedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ServiceRemovedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ServiceRemovedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ServiceRemovedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ServiceRemovedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ServiceRemovedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ServiceRemovedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ServiceRemovedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ServiceRemovedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ServiceRemovedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ServiceRemovedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ServiceRemovedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ServiceRemovedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ServiceRemovedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ServiceRemovedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ServiceRemovedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ServiceRemovedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +// New creates a new ServiceRemovedEventV0_2_0 +func NewServiceRemovedEventV0_2_0(specVersion string) (*ServiceRemovedEventV0_2_0, error) { + e := &ServiceRemovedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ServiceRemovedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ServiceRemovedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "service", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_servicerolledback_0_1_1.go b/pkg/api/zz_servicerolledback_0_1_1.go index 0d71bdf..0d0106f 100644 --- a/pkg/api/zz_servicerolledback_0_1_1.go +++ b/pkg/api/zz_servicerolledback_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var servicerolledbackschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/service-rolledback-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.service.rolledback.0.1.1"],"default":"dev.cdevents.service.rolledback.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["service"],"default":"service"},"content":{"properties":{"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"artifactId":{"type":"string","minLength":1}},"additionalProperties":false,"type":"object","required":["environment","artifactId"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ServiceRolledback event type v0.1.1 @@ -36,24 +35,24 @@ var ( } ) -type ServiceRolledbackSubjectContent struct { +type ServiceRolledbackSubjectContentV0_1_1 struct { ArtifactId string `json:"artifactId" validate:"purl"` Environment *Reference `json:"environment"` } -type ServiceRolledbackSubject struct { +type ServiceRolledbackSubjectV0_1_1 struct { SubjectBase - Content ServiceRolledbackSubjectContent `json:"content"` + Content ServiceRolledbackSubjectContentV0_1_1 `json:"content"` } -func (sc ServiceRolledbackSubject) GetSubjectType() SubjectType { +func (sc ServiceRolledbackSubjectV0_1_1) GetSubjectType() SubjectType { return "service" } type ServiceRolledbackEventV0_1_1 struct { - Context Context `json:"context"` - Subject ServiceRolledbackSubject `json:"subject"` + Context Context `json:"context"` + Subject ServiceRolledbackSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -143,9 +142,9 @@ func (e *ServiceRolledbackEventV0_1_1) SetCustomData(contentType string, data in return nil } -func (e ServiceRolledbackEventV0_1_1) GetSchema() (string, string) { +func (e ServiceRolledbackEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), servicerolledbackschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -165,7 +164,7 @@ func NewServiceRolledbackEventV0_1_1(specVersion string) (*ServiceRolledbackEven Type: ServiceRolledbackEventTypeV0_1_1, Version: specVersion, }, - Subject: ServiceRolledbackSubject{ + Subject: ServiceRolledbackSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "service", }, diff --git a/pkg/api/zz_servicerolledback_0_2_0.go b/pkg/api/zz_servicerolledback_0_2_0.go new file mode 100644 index 0000000..cf3865f --- /dev/null +++ b/pkg/api/zz_servicerolledback_0_2_0.go @@ -0,0 +1,210 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ServiceRolledback event type v0.2.0 + ServiceRolledbackEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "service", + Predicate: "rolledback", + Version: "0.2.0", + } +) + +type ServiceRolledbackSubjectContentV0_2_0 struct { + ArtifactId string `json:"artifactId" validate:"purl"` + + Environment *Reference `json:"environment"` +} + +type ServiceRolledbackSubjectV0_2_0 struct { + SubjectBase + Content ServiceRolledbackSubjectContentV0_2_0 `json:"content"` +} + +func (sc ServiceRolledbackSubjectV0_2_0) GetSubjectType() SubjectType { + return "service" +} + +type ServiceRolledbackEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ServiceRolledbackSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ServiceRolledbackEventV0_2_0) GetType() CDEventType { + return ServiceRolledbackEventTypeV0_2_0 +} + +func (e ServiceRolledbackEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ServiceRolledbackEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ServiceRolledbackEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ServiceRolledbackEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ServiceRolledbackEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ServiceRolledbackEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ServiceRolledbackEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ServiceRolledbackEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ServiceRolledbackEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ServiceRolledbackEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ServiceRolledbackEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ServiceRolledbackEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ServiceRolledbackEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ServiceRolledbackEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ServiceRolledbackEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ServiceRolledbackEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ServiceRolledbackEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ServiceRolledbackEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ServiceRolledbackEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ServiceRolledbackEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ServiceRolledbackEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ServiceRolledbackEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ServiceRolledbackEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ServiceRolledbackEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ServiceRolledbackEventV0_2_0) SetSubjectArtifactId(artifactId string) { + e.Subject.Content.ArtifactId = artifactId +} + +func (e *ServiceRolledbackEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +// New creates a new ServiceRolledbackEventV0_2_0 +func NewServiceRolledbackEventV0_2_0(specVersion string) (*ServiceRolledbackEventV0_2_0, error) { + e := &ServiceRolledbackEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ServiceRolledbackEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ServiceRolledbackSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "service", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_serviceupgraded_0_1_1.go b/pkg/api/zz_serviceupgraded_0_1_1.go index 5fd709e..8ad1013 100644 --- a/pkg/api/zz_serviceupgraded_0_1_1.go +++ b/pkg/api/zz_serviceupgraded_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var serviceupgradedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/service-upgraded-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.service.upgraded.0.1.1"],"default":"dev.cdevents.service.upgraded.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["service"],"default":"service"},"content":{"properties":{"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"artifactId":{"type":"string","minLength":1}},"additionalProperties":false,"type":"object","required":["environment","artifactId"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // ServiceUpgraded event type v0.1.1 @@ -36,24 +35,24 @@ var ( } ) -type ServiceUpgradedSubjectContent struct { +type ServiceUpgradedSubjectContentV0_1_1 struct { ArtifactId string `json:"artifactId" validate:"purl"` Environment *Reference `json:"environment"` } -type ServiceUpgradedSubject struct { +type ServiceUpgradedSubjectV0_1_1 struct { SubjectBase - Content ServiceUpgradedSubjectContent `json:"content"` + Content ServiceUpgradedSubjectContentV0_1_1 `json:"content"` } -func (sc ServiceUpgradedSubject) GetSubjectType() SubjectType { +func (sc ServiceUpgradedSubjectV0_1_1) GetSubjectType() SubjectType { return "service" } type ServiceUpgradedEventV0_1_1 struct { - Context Context `json:"context"` - Subject ServiceUpgradedSubject `json:"subject"` + Context Context `json:"context"` + Subject ServiceUpgradedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -143,9 +142,9 @@ func (e *ServiceUpgradedEventV0_1_1) SetCustomData(contentType string, data inte return nil } -func (e ServiceUpgradedEventV0_1_1) GetSchema() (string, string) { +func (e ServiceUpgradedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), serviceupgradedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -165,7 +164,7 @@ func NewServiceUpgradedEventV0_1_1(specVersion string) (*ServiceUpgradedEventV0_ Type: ServiceUpgradedEventTypeV0_1_1, Version: specVersion, }, - Subject: ServiceUpgradedSubject{ + Subject: ServiceUpgradedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "service", }, diff --git a/pkg/api/zz_serviceupgraded_0_2_0.go b/pkg/api/zz_serviceupgraded_0_2_0.go new file mode 100644 index 0000000..2cabff0 --- /dev/null +++ b/pkg/api/zz_serviceupgraded_0_2_0.go @@ -0,0 +1,210 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // ServiceUpgraded event type v0.2.0 + ServiceUpgradedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "service", + Predicate: "upgraded", + Version: "0.2.0", + } +) + +type ServiceUpgradedSubjectContentV0_2_0 struct { + ArtifactId string `json:"artifactId" validate:"purl"` + + Environment *Reference `json:"environment"` +} + +type ServiceUpgradedSubjectV0_2_0 struct { + SubjectBase + Content ServiceUpgradedSubjectContentV0_2_0 `json:"content"` +} + +func (sc ServiceUpgradedSubjectV0_2_0) GetSubjectType() SubjectType { + return "service" +} + +type ServiceUpgradedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject ServiceUpgradedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e ServiceUpgradedEventV0_2_0) GetType() CDEventType { + return ServiceUpgradedEventTypeV0_2_0 +} + +func (e ServiceUpgradedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ServiceUpgradedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e ServiceUpgradedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e ServiceUpgradedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ServiceUpgradedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e ServiceUpgradedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ServiceUpgradedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e ServiceUpgradedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e ServiceUpgradedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e ServiceUpgradedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e ServiceUpgradedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e ServiceUpgradedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e ServiceUpgradedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e ServiceUpgradedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *ServiceUpgradedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *ServiceUpgradedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ServiceUpgradedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ServiceUpgradedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ServiceUpgradedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *ServiceUpgradedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e ServiceUpgradedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *ServiceUpgradedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *ServiceUpgradedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *ServiceUpgradedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *ServiceUpgradedEventV0_2_0) SetSubjectArtifactId(artifactId string) { + e.Subject.Content.ArtifactId = artifactId +} + +func (e *ServiceUpgradedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +// New creates a new ServiceUpgradedEventV0_2_0 +func NewServiceUpgradedEventV0_2_0(specVersion string) (*ServiceUpgradedEventV0_2_0, error) { + e := &ServiceUpgradedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: ServiceUpgradedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: ServiceUpgradedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "service", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_taskrunfinished_0_1_1.go b/pkg/api/zz_taskrunfinished_0_1_1.go index ced0e15..fb3eaf8 100644 --- a/pkg/api/zz_taskrunfinished_0_1_1.go +++ b/pkg/api/zz_taskrunfinished_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var taskrunfinishedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/task-run-finished-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.taskrun.finished.0.1.1"],"default":"dev.cdevents.taskrun.finished.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["taskRun"],"default":"taskRun"},"content":{"properties":{"taskName":{"type":"string"},"url":{"type":"string"},"pipelineRun":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"outcome":{"type":"string"},"errors":{"type":"string"}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // TaskRunFinished event type v0.1.1 @@ -36,7 +35,7 @@ var ( } ) -type TaskRunFinishedSubjectContent struct { +type TaskRunFinishedSubjectContentV0_1_1 struct { Errors string `json:"errors,omitempty"` Outcome string `json:"outcome,omitempty"` @@ -48,18 +47,18 @@ type TaskRunFinishedSubjectContent struct { Url string `json:"url,omitempty"` } -type TaskRunFinishedSubject struct { +type TaskRunFinishedSubjectV0_1_1 struct { SubjectBase - Content TaskRunFinishedSubjectContent `json:"content"` + Content TaskRunFinishedSubjectContentV0_1_1 `json:"content"` } -func (sc TaskRunFinishedSubject) GetSubjectType() SubjectType { +func (sc TaskRunFinishedSubjectV0_1_1) GetSubjectType() SubjectType { return "taskRun" } type TaskRunFinishedEventV0_1_1 struct { - Context Context `json:"context"` - Subject TaskRunFinishedSubject `json:"subject"` + Context Context `json:"context"` + Subject TaskRunFinishedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -149,9 +148,9 @@ func (e *TaskRunFinishedEventV0_1_1) SetCustomData(contentType string, data inte return nil } -func (e TaskRunFinishedEventV0_1_1) GetSchema() (string, string) { +func (e TaskRunFinishedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), taskrunfinishedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -183,7 +182,7 @@ func NewTaskRunFinishedEventV0_1_1(specVersion string) (*TaskRunFinishedEventV0_ Type: TaskRunFinishedEventTypeV0_1_1, Version: specVersion, }, - Subject: TaskRunFinishedSubject{ + Subject: TaskRunFinishedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "taskRun", }, diff --git a/pkg/api/zz_taskrunfinished_0_2_0.go b/pkg/api/zz_taskrunfinished_0_2_0.go new file mode 100644 index 0000000..2d5e380 --- /dev/null +++ b/pkg/api/zz_taskrunfinished_0_2_0.go @@ -0,0 +1,228 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TaskRunFinished event type v0.2.0 + TaskRunFinishedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "taskrun", + Predicate: "finished", + Version: "0.2.0", + } +) + +type TaskRunFinishedSubjectContentV0_2_0 struct { + Errors string `json:"errors,omitempty"` + + Outcome string `json:"outcome,omitempty"` + + PipelineRun *Reference `json:"pipelineRun,omitempty"` + + TaskName string `json:"taskName,omitempty"` + + Url string `json:"url,omitempty"` +} + +type TaskRunFinishedSubjectV0_2_0 struct { + SubjectBase + Content TaskRunFinishedSubjectContentV0_2_0 `json:"content"` +} + +func (sc TaskRunFinishedSubjectV0_2_0) GetSubjectType() SubjectType { + return "taskRun" +} + +type TaskRunFinishedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject TaskRunFinishedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TaskRunFinishedEventV0_2_0) GetType() CDEventType { + return TaskRunFinishedEventTypeV0_2_0 +} + +func (e TaskRunFinishedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TaskRunFinishedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e TaskRunFinishedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e TaskRunFinishedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TaskRunFinishedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TaskRunFinishedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TaskRunFinishedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e TaskRunFinishedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TaskRunFinishedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TaskRunFinishedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TaskRunFinishedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TaskRunFinishedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TaskRunFinishedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TaskRunFinishedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TaskRunFinishedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TaskRunFinishedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TaskRunFinishedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TaskRunFinishedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TaskRunFinishedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TaskRunFinishedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TaskRunFinishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TaskRunFinishedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TaskRunFinishedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TaskRunFinishedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TaskRunFinishedEventV0_2_0) SetSubjectErrors(errors string) { + e.Subject.Content.Errors = errors +} + +func (e *TaskRunFinishedEventV0_2_0) SetSubjectOutcome(outcome string) { + e.Subject.Content.Outcome = outcome +} + +func (e *TaskRunFinishedEventV0_2_0) SetSubjectPipelineRun(pipelineRun *Reference) { + e.Subject.Content.PipelineRun = pipelineRun +} + +func (e *TaskRunFinishedEventV0_2_0) SetSubjectTaskName(taskName string) { + e.Subject.Content.TaskName = taskName +} + +func (e *TaskRunFinishedEventV0_2_0) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +// New creates a new TaskRunFinishedEventV0_2_0 +func NewTaskRunFinishedEventV0_2_0(specVersion string) (*TaskRunFinishedEventV0_2_0, error) { + e := &TaskRunFinishedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: TaskRunFinishedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TaskRunFinishedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "taskRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_taskrunstarted_0_1_1.go b/pkg/api/zz_taskrunstarted_0_1_1.go index cab87ac..570a77b 100644 --- a/pkg/api/zz_taskrunstarted_0_1_1.go +++ b/pkg/api/zz_taskrunstarted_0_1_1.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var taskrunstartedschema0_1_1 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/task-run-started-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.taskrun.started.0.1.1"],"default":"dev.cdevents.taskrun.started.0.1.1"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["taskRun"],"default":"taskRun"},"content":{"properties":{"taskName":{"type":"string"},"url":{"type":"string"},"pipelineRun":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object"}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // TaskRunStarted event type v0.1.1 @@ -36,7 +35,7 @@ var ( } ) -type TaskRunStartedSubjectContent struct { +type TaskRunStartedSubjectContentV0_1_1 struct { PipelineRun *Reference `json:"pipelineRun,omitempty"` TaskName string `json:"taskName,omitempty"` @@ -44,18 +43,18 @@ type TaskRunStartedSubjectContent struct { Url string `json:"url,omitempty"` } -type TaskRunStartedSubject struct { +type TaskRunStartedSubjectV0_1_1 struct { SubjectBase - Content TaskRunStartedSubjectContent `json:"content"` + Content TaskRunStartedSubjectContentV0_1_1 `json:"content"` } -func (sc TaskRunStartedSubject) GetSubjectType() SubjectType { +func (sc TaskRunStartedSubjectV0_1_1) GetSubjectType() SubjectType { return "taskRun" } type TaskRunStartedEventV0_1_1 struct { - Context Context `json:"context"` - Subject TaskRunStartedSubject `json:"subject"` + Context Context `json:"context"` + Subject TaskRunStartedSubjectV0_1_1 `json:"subject"` CDEventCustomData } @@ -145,9 +144,9 @@ func (e *TaskRunStartedEventV0_1_1) SetCustomData(contentType string, data inter return nil } -func (e TaskRunStartedEventV0_1_1) GetSchema() (string, string) { +func (e TaskRunStartedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), taskrunstartedschema0_1_1 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -171,7 +170,7 @@ func NewTaskRunStartedEventV0_1_1(specVersion string) (*TaskRunStartedEventV0_1_ Type: TaskRunStartedEventTypeV0_1_1, Version: specVersion, }, - Subject: TaskRunStartedSubject{ + Subject: TaskRunStartedSubjectV0_1_1{ SubjectBase: SubjectBase{ Type: "taskRun", }, diff --git a/pkg/api/zz_taskrunstarted_0_2_0.go b/pkg/api/zz_taskrunstarted_0_2_0.go new file mode 100644 index 0000000..5df39c7 --- /dev/null +++ b/pkg/api/zz_taskrunstarted_0_2_0.go @@ -0,0 +1,216 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TaskRunStarted event type v0.2.0 + TaskRunStartedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "taskrun", + Predicate: "started", + Version: "0.2.0", + } +) + +type TaskRunStartedSubjectContentV0_2_0 struct { + PipelineRun *Reference `json:"pipelineRun,omitempty"` + + TaskName string `json:"taskName,omitempty"` + + Url string `json:"url,omitempty"` +} + +type TaskRunStartedSubjectV0_2_0 struct { + SubjectBase + Content TaskRunStartedSubjectContentV0_2_0 `json:"content"` +} + +func (sc TaskRunStartedSubjectV0_2_0) GetSubjectType() SubjectType { + return "taskRun" +} + +type TaskRunStartedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject TaskRunStartedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TaskRunStartedEventV0_2_0) GetType() CDEventType { + return TaskRunStartedEventTypeV0_2_0 +} + +func (e TaskRunStartedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TaskRunStartedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e TaskRunStartedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e TaskRunStartedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TaskRunStartedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TaskRunStartedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TaskRunStartedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e TaskRunStartedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TaskRunStartedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TaskRunStartedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TaskRunStartedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TaskRunStartedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TaskRunStartedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TaskRunStartedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TaskRunStartedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TaskRunStartedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TaskRunStartedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TaskRunStartedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TaskRunStartedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TaskRunStartedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TaskRunStartedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TaskRunStartedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TaskRunStartedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TaskRunStartedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TaskRunStartedEventV0_2_0) SetSubjectPipelineRun(pipelineRun *Reference) { + e.Subject.Content.PipelineRun = pipelineRun +} + +func (e *TaskRunStartedEventV0_2_0) SetSubjectTaskName(taskName string) { + e.Subject.Content.TaskName = taskName +} + +func (e *TaskRunStartedEventV0_2_0) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +// New creates a new TaskRunStartedEventV0_2_0 +func NewTaskRunStartedEventV0_2_0(specVersion string) (*TaskRunStartedEventV0_2_0, error) { + e := &TaskRunStartedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: TaskRunStartedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TaskRunStartedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "taskRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_testcaserunfinished_0_1_0.go b/pkg/api/zz_testcaserunfinished_0_1_0.go index 24b29ea..43bd44b 100644 --- a/pkg/api/zz_testcaserunfinished_0_1_0.go +++ b/pkg/api/zz_testcaserunfinished_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var testcaserunfinishedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/test-case-run-finished-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1},"type":{"type":"string","enum":["dev.cdevents.testcaserun.finished.0.1.0"],"default":"dev.cdevents.testcaserun.finished.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"},"type":{"type":"string","minLength":1,"enum":["testCaseRun"],"default":"testCaseRun"},"content":{"properties":{"outcome":{"type":"string","enum":["pass","fail","cancel","error"]},"severity":{"type":"string","enum":["low","medium","high","critical"]},"reason":{"type":"string"},"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"testSuiteRun":{"type":"object","properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"}},"additionalProperties":false,"required":["id"]},"testCase":{"type":"object","additionalProperties":false,"required":["id"],"properties":{"id":{"type":"string","minLength":1},"version":{"type":"string"},"name":{"type":"string"},"type":{"type":"string","enum":["performance","functional","unit","security","compliance","integration","e2e","other"]},"uri":{"type":"string","format":"uri"}}}},"additionalProperties":false,"type":"object","required":["outcome","environment"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // TestCaseRunFinished event type v0.1.0 @@ -36,7 +35,7 @@ var ( } ) -type TestCaseRunFinishedSubjectContent struct { +type TestCaseRunFinishedSubjectContentV0_1_0 struct { Environment *Reference `json:"environment"` Outcome string `json:"outcome"` @@ -45,23 +44,23 @@ type TestCaseRunFinishedSubjectContent struct { Severity string `json:"severity,omitempty"` - TestCase *TestCaseRunFinishedSubjectContentTestCase `json:"testCase,omitempty"` + TestCase *TestCaseRunFinishedSubjectContentTestCaseV0_1_0 `json:"testCase,omitempty"` TestSuiteRun *Reference `json:"testSuiteRun,omitempty"` } -type TestCaseRunFinishedSubject struct { +type TestCaseRunFinishedSubjectV0_1_0 struct { SubjectBase - Content TestCaseRunFinishedSubjectContent `json:"content"` + Content TestCaseRunFinishedSubjectContentV0_1_0 `json:"content"` } -func (sc TestCaseRunFinishedSubject) GetSubjectType() SubjectType { +func (sc TestCaseRunFinishedSubjectV0_1_0) GetSubjectType() SubjectType { return "testCaseRun" } type TestCaseRunFinishedEventV0_1_0 struct { - Context Context `json:"context"` - Subject TestCaseRunFinishedSubject `json:"subject"` + Context Context `json:"context"` + Subject TestCaseRunFinishedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -151,9 +150,9 @@ func (e *TestCaseRunFinishedEventV0_1_0) SetCustomData(contentType string, data return nil } -func (e TestCaseRunFinishedEventV0_1_0) GetSchema() (string, string) { +func (e TestCaseRunFinishedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), testcaserunfinishedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -174,7 +173,7 @@ func (e *TestCaseRunFinishedEventV0_1_0) SetSubjectSeverity(severity string) { e.Subject.Content.Severity = severity } -func (e *TestCaseRunFinishedEventV0_1_0) SetSubjectTestCase(testCase *TestCaseRunFinishedSubjectContentTestCase) { +func (e *TestCaseRunFinishedEventV0_1_0) SetSubjectTestCase(testCase *TestCaseRunFinishedSubjectContentTestCaseV0_1_0) { e.Subject.Content.TestCase = testCase } @@ -189,7 +188,7 @@ func NewTestCaseRunFinishedEventV0_1_0(specVersion string) (*TestCaseRunFinished Type: TestCaseRunFinishedEventTypeV0_1_0, Version: specVersion, }, - Subject: TestCaseRunFinishedSubject{ + Subject: TestCaseRunFinishedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "testCaseRun", }, @@ -202,8 +201,8 @@ func NewTestCaseRunFinishedEventV0_1_0(specVersion string) (*TestCaseRunFinished return e, nil } -// TestCaseRunFinishedSubjectContentTestCase holds the content of a TestCase field in the content -type TestCaseRunFinishedSubjectContentTestCase struct { +// TestCaseRunFinishedSubjectContentTestCaseV0_1_0 holds the content of a TestCase field in the content +type TestCaseRunFinishedSubjectContentTestCaseV0_1_0 struct { Id string `json:"id"` Name string `json:"name,omitempty"` diff --git a/pkg/api/zz_testcaserunfinished_0_2_0.go b/pkg/api/zz_testcaserunfinished_0_2_0.go new file mode 100644 index 0000000..2232257 --- /dev/null +++ b/pkg/api/zz_testcaserunfinished_0_2_0.go @@ -0,0 +1,247 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TestCaseRunFinished event type v0.2.0 + TestCaseRunFinishedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "testcaserun", + Predicate: "finished", + Version: "0.2.0", + } +) + +type TestCaseRunFinishedSubjectContentV0_2_0 struct { + Environment *Reference `json:"environment"` + + Outcome string `json:"outcome"` + + Reason string `json:"reason,omitempty"` + + Severity string `json:"severity,omitempty"` + + TestCase *TestCaseRunFinishedSubjectContentTestCaseV0_2_0 `json:"testCase,omitempty"` + + TestSuiteRun *Reference `json:"testSuiteRun,omitempty"` +} + +type TestCaseRunFinishedSubjectV0_2_0 struct { + SubjectBase + Content TestCaseRunFinishedSubjectContentV0_2_0 `json:"content"` +} + +func (sc TestCaseRunFinishedSubjectV0_2_0) GetSubjectType() SubjectType { + return "testCaseRun" +} + +type TestCaseRunFinishedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject TestCaseRunFinishedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TestCaseRunFinishedEventV0_2_0) GetType() CDEventType { + return TestCaseRunFinishedEventTypeV0_2_0 +} + +func (e TestCaseRunFinishedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestCaseRunFinishedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e TestCaseRunFinishedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e TestCaseRunFinishedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestCaseRunFinishedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestCaseRunFinishedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestCaseRunFinishedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e TestCaseRunFinishedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TestCaseRunFinishedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TestCaseRunFinishedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TestCaseRunFinishedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TestCaseRunFinishedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TestCaseRunFinishedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TestCaseRunFinishedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TestCaseRunFinishedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TestCaseRunFinishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TestCaseRunFinishedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TestCaseRunFinishedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetSubjectOutcome(outcome string) { + e.Subject.Content.Outcome = outcome +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetSubjectReason(reason string) { + e.Subject.Content.Reason = reason +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetSubjectSeverity(severity string) { + e.Subject.Content.Severity = severity +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetSubjectTestCase(testCase *TestCaseRunFinishedSubjectContentTestCaseV0_2_0) { + e.Subject.Content.TestCase = testCase +} + +func (e *TestCaseRunFinishedEventV0_2_0) SetSubjectTestSuiteRun(testSuiteRun *Reference) { + e.Subject.Content.TestSuiteRun = testSuiteRun +} + +// New creates a new TestCaseRunFinishedEventV0_2_0 +func NewTestCaseRunFinishedEventV0_2_0(specVersion string) (*TestCaseRunFinishedEventV0_2_0, error) { + e := &TestCaseRunFinishedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: TestCaseRunFinishedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TestCaseRunFinishedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "testCaseRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} + +// TestCaseRunFinishedSubjectContentTestCaseV0_2_0 holds the content of a TestCase field in the content +type TestCaseRunFinishedSubjectContentTestCaseV0_2_0 struct { + Id string `json:"id"` + + Name string `json:"name,omitempty"` + + Type string `json:"type,omitempty"` + + Uri string `json:"uri,omitempty"` + + Version string `json:"version,omitempty"` +} diff --git a/pkg/api/zz_testcaserunqueued_0_1_0.go b/pkg/api/zz_testcaserunqueued_0_1_0.go index 836ab71..70a564a 100644 --- a/pkg/api/zz_testcaserunqueued_0_1_0.go +++ b/pkg/api/zz_testcaserunqueued_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var testcaserunqueuedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/test-case-run-queued-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1},"type":{"type":"string","enum":["dev.cdevents.testcaserun.queued.0.1.0"],"default":"dev.cdevents.testcaserun.queued.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"},"type":{"type":"string","minLength":1,"enum":["testCaseRun"],"default":"testCaseRun"},"content":{"properties":{"trigger":{"type":"object","properties":{"type":{"type":"string","enum":["manual","pipeline","event","schedule","other"]},"uri":{"type":"string","format":"uri"}}},"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"testSuiteRun":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"}},"additionalProperties":false,"type":"object","required":["id"]},"testCase":{"type":"object","additionalProperties":false,"required":["id"],"properties":{"id":{"type":"string","minLength":1},"version":{"type":"string"},"name":{"type":"string"},"type":{"type":"string","enum":["performance","functional","unit","security","compliance","integration","e2e","other"]},"uri":{"type":"string","format":"uri"}}}},"additionalProperties":false,"type":"object","required":["environment"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // TestCaseRunQueued event type v0.1.0 @@ -36,28 +35,28 @@ var ( } ) -type TestCaseRunQueuedSubjectContent struct { +type TestCaseRunQueuedSubjectContentV0_1_0 struct { Environment *Reference `json:"environment"` - TestCase *TestCaseRunQueuedSubjectContentTestCase `json:"testCase,omitempty"` + TestCase *TestCaseRunQueuedSubjectContentTestCaseV0_1_0 `json:"testCase,omitempty"` TestSuiteRun *Reference `json:"testSuiteRun,omitempty"` - Trigger *TestCaseRunQueuedSubjectContentTrigger `json:"trigger,omitempty"` + Trigger *TestCaseRunQueuedSubjectContentTriggerV0_1_0 `json:"trigger,omitempty"` } -type TestCaseRunQueuedSubject struct { +type TestCaseRunQueuedSubjectV0_1_0 struct { SubjectBase - Content TestCaseRunQueuedSubjectContent `json:"content"` + Content TestCaseRunQueuedSubjectContentV0_1_0 `json:"content"` } -func (sc TestCaseRunQueuedSubject) GetSubjectType() SubjectType { +func (sc TestCaseRunQueuedSubjectV0_1_0) GetSubjectType() SubjectType { return "testCaseRun" } type TestCaseRunQueuedEventV0_1_0 struct { - Context Context `json:"context"` - Subject TestCaseRunQueuedSubject `json:"subject"` + Context Context `json:"context"` + Subject TestCaseRunQueuedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -147,9 +146,9 @@ func (e *TestCaseRunQueuedEventV0_1_0) SetCustomData(contentType string, data in return nil } -func (e TestCaseRunQueuedEventV0_1_0) GetSchema() (string, string) { +func (e TestCaseRunQueuedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), testcaserunqueuedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -158,7 +157,7 @@ func (e *TestCaseRunQueuedEventV0_1_0) SetSubjectEnvironment(environment *Refere e.Subject.Content.Environment = environment } -func (e *TestCaseRunQueuedEventV0_1_0) SetSubjectTestCase(testCase *TestCaseRunQueuedSubjectContentTestCase) { +func (e *TestCaseRunQueuedEventV0_1_0) SetSubjectTestCase(testCase *TestCaseRunQueuedSubjectContentTestCaseV0_1_0) { e.Subject.Content.TestCase = testCase } @@ -166,7 +165,7 @@ func (e *TestCaseRunQueuedEventV0_1_0) SetSubjectTestSuiteRun(testSuiteRun *Refe e.Subject.Content.TestSuiteRun = testSuiteRun } -func (e *TestCaseRunQueuedEventV0_1_0) SetSubjectTrigger(trigger *TestCaseRunQueuedSubjectContentTrigger) { +func (e *TestCaseRunQueuedEventV0_1_0) SetSubjectTrigger(trigger *TestCaseRunQueuedSubjectContentTriggerV0_1_0) { e.Subject.Content.Trigger = trigger } @@ -177,7 +176,7 @@ func NewTestCaseRunQueuedEventV0_1_0(specVersion string) (*TestCaseRunQueuedEven Type: TestCaseRunQueuedEventTypeV0_1_0, Version: specVersion, }, - Subject: TestCaseRunQueuedSubject{ + Subject: TestCaseRunQueuedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "testCaseRun", }, @@ -190,8 +189,8 @@ func NewTestCaseRunQueuedEventV0_1_0(specVersion string) (*TestCaseRunQueuedEven return e, nil } -// TestCaseRunQueuedSubjectContentTestCase holds the content of a TestCase field in the content -type TestCaseRunQueuedSubjectContentTestCase struct { +// TestCaseRunQueuedSubjectContentTestCaseV0_1_0 holds the content of a TestCase field in the content +type TestCaseRunQueuedSubjectContentTestCaseV0_1_0 struct { Id string `json:"id"` Name string `json:"name,omitempty"` @@ -203,8 +202,8 @@ type TestCaseRunQueuedSubjectContentTestCase struct { Version string `json:"version,omitempty"` } -// TestCaseRunQueuedSubjectContentTrigger holds the content of a Trigger field in the content -type TestCaseRunQueuedSubjectContentTrigger struct { +// TestCaseRunQueuedSubjectContentTriggerV0_1_0 holds the content of a Trigger field in the content +type TestCaseRunQueuedSubjectContentTriggerV0_1_0 struct { Type string `json:"type,omitempty"` Uri string `json:"uri,omitempty"` diff --git a/pkg/api/zz_testcaserunqueued_0_2_0.go b/pkg/api/zz_testcaserunqueued_0_2_0.go new file mode 100644 index 0000000..fe5d978 --- /dev/null +++ b/pkg/api/zz_testcaserunqueued_0_2_0.go @@ -0,0 +1,242 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TestCaseRunQueued event type v0.2.0 + TestCaseRunQueuedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "testcaserun", + Predicate: "queued", + Version: "0.2.0", + } +) + +type TestCaseRunQueuedSubjectContentV0_2_0 struct { + Environment *Reference `json:"environment"` + + TestCase *TestCaseRunQueuedSubjectContentTestCaseV0_2_0 `json:"testCase,omitempty"` + + TestSuiteRun *Reference `json:"testSuiteRun,omitempty"` + + Trigger *TestCaseRunQueuedSubjectContentTriggerV0_2_0 `json:"trigger,omitempty"` +} + +type TestCaseRunQueuedSubjectV0_2_0 struct { + SubjectBase + Content TestCaseRunQueuedSubjectContentV0_2_0 `json:"content"` +} + +func (sc TestCaseRunQueuedSubjectV0_2_0) GetSubjectType() SubjectType { + return "testCaseRun" +} + +type TestCaseRunQueuedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject TestCaseRunQueuedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TestCaseRunQueuedEventV0_2_0) GetType() CDEventType { + return TestCaseRunQueuedEventTypeV0_2_0 +} + +func (e TestCaseRunQueuedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestCaseRunQueuedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e TestCaseRunQueuedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e TestCaseRunQueuedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestCaseRunQueuedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestCaseRunQueuedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestCaseRunQueuedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e TestCaseRunQueuedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TestCaseRunQueuedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TestCaseRunQueuedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TestCaseRunQueuedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TestCaseRunQueuedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TestCaseRunQueuedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TestCaseRunQueuedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TestCaseRunQueuedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TestCaseRunQueuedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestCaseRunQueuedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestCaseRunQueuedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestCaseRunQueuedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TestCaseRunQueuedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TestCaseRunQueuedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TestCaseRunQueuedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TestCaseRunQueuedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TestCaseRunQueuedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TestCaseRunQueuedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +func (e *TestCaseRunQueuedEventV0_2_0) SetSubjectTestCase(testCase *TestCaseRunQueuedSubjectContentTestCaseV0_2_0) { + e.Subject.Content.TestCase = testCase +} + +func (e *TestCaseRunQueuedEventV0_2_0) SetSubjectTestSuiteRun(testSuiteRun *Reference) { + e.Subject.Content.TestSuiteRun = testSuiteRun +} + +func (e *TestCaseRunQueuedEventV0_2_0) SetSubjectTrigger(trigger *TestCaseRunQueuedSubjectContentTriggerV0_2_0) { + e.Subject.Content.Trigger = trigger +} + +// New creates a new TestCaseRunQueuedEventV0_2_0 +func NewTestCaseRunQueuedEventV0_2_0(specVersion string) (*TestCaseRunQueuedEventV0_2_0, error) { + e := &TestCaseRunQueuedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: TestCaseRunQueuedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TestCaseRunQueuedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "testCaseRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} + +// TestCaseRunQueuedSubjectContentTestCaseV0_2_0 holds the content of a TestCase field in the content +type TestCaseRunQueuedSubjectContentTestCaseV0_2_0 struct { + Id string `json:"id"` + + Name string `json:"name,omitempty"` + + Type string `json:"type,omitempty"` + + Uri string `json:"uri,omitempty"` + + Version string `json:"version,omitempty"` +} + +// TestCaseRunQueuedSubjectContentTriggerV0_2_0 holds the content of a Trigger field in the content +type TestCaseRunQueuedSubjectContentTriggerV0_2_0 struct { + Type string `json:"type,omitempty"` + + Uri string `json:"uri,omitempty"` +} diff --git a/pkg/api/zz_testcaserunskipped_0_1_0.go b/pkg/api/zz_testcaserunskipped_0_1_0.go new file mode 100644 index 0000000..166f349 --- /dev/null +++ b/pkg/api/zz_testcaserunskipped_0_1_0.go @@ -0,0 +1,235 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TestCaseRunSkipped event type v0.1.0 + TestCaseRunSkippedEventTypeV0_1_0 CDEventType = CDEventType{ + Subject: "testcaserun", + Predicate: "skipped", + Version: "0.1.0", + } +) + +type TestCaseRunSkippedSubjectContentV0_1_0 struct { + Environment *Reference `json:"environment,omitempty"` + + Reason string `json:"reason,omitempty"` + + TestCase *TestCaseRunSkippedSubjectContentTestCaseV0_1_0 `json:"testCase,omitempty"` + + TestSuiteRun *Reference `json:"testSuiteRun,omitempty"` +} + +type TestCaseRunSkippedSubjectV0_1_0 struct { + SubjectBase + Content TestCaseRunSkippedSubjectContentV0_1_0 `json:"content"` +} + +func (sc TestCaseRunSkippedSubjectV0_1_0) GetSubjectType() SubjectType { + return "testCaseRun" +} + +type TestCaseRunSkippedEventV0_1_0 struct { + Context ContextV04 `json:"context"` + Subject TestCaseRunSkippedSubjectV0_1_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TestCaseRunSkippedEventV0_1_0) GetType() CDEventType { + return TestCaseRunSkippedEventTypeV0_1_0 +} + +func (e TestCaseRunSkippedEventV0_1_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestCaseRunSkippedEventV0_1_0) GetId() string { + return e.Context.Id +} + +func (e TestCaseRunSkippedEventV0_1_0) GetSource() string { + return e.Context.Source +} + +func (e TestCaseRunSkippedEventV0_1_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestCaseRunSkippedEventV0_1_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestCaseRunSkippedEventV0_1_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestCaseRunSkippedEventV0_1_0) GetSubject() Subject { + return e.Subject +} + +func (e TestCaseRunSkippedEventV0_1_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TestCaseRunSkippedEventV0_1_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TestCaseRunSkippedEventV0_1_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TestCaseRunSkippedEventV0_1_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TestCaseRunSkippedEventV0_1_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TestCaseRunSkippedEventV0_1_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TestCaseRunSkippedEventV0_1_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TestCaseRunSkippedEventV0_1_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TestCaseRunSkippedEventV0_1_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestCaseRunSkippedEventV0_1_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestCaseRunSkippedEventV0_1_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestCaseRunSkippedEventV0_1_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TestCaseRunSkippedEventV0_1_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TestCaseRunSkippedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TestCaseRunSkippedEventV0_1_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TestCaseRunSkippedEventV0_1_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TestCaseRunSkippedEventV0_1_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TestCaseRunSkippedEventV0_1_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +func (e *TestCaseRunSkippedEventV0_1_0) SetSubjectReason(reason string) { + e.Subject.Content.Reason = reason +} + +func (e *TestCaseRunSkippedEventV0_1_0) SetSubjectTestCase(testCase *TestCaseRunSkippedSubjectContentTestCaseV0_1_0) { + e.Subject.Content.TestCase = testCase +} + +func (e *TestCaseRunSkippedEventV0_1_0) SetSubjectTestSuiteRun(testSuiteRun *Reference) { + e.Subject.Content.TestSuiteRun = testSuiteRun +} + +// New creates a new TestCaseRunSkippedEventV0_1_0 +func NewTestCaseRunSkippedEventV0_1_0(specVersion string) (*TestCaseRunSkippedEventV0_1_0, error) { + e := &TestCaseRunSkippedEventV0_1_0{ + Context: ContextV04{ + Context{ + Type: TestCaseRunSkippedEventTypeV0_1_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TestCaseRunSkippedSubjectV0_1_0{ + SubjectBase: SubjectBase{ + Type: "testCaseRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} + +// TestCaseRunSkippedSubjectContentTestCaseV0_1_0 holds the content of a TestCase field in the content +type TestCaseRunSkippedSubjectContentTestCaseV0_1_0 struct { + Id string `json:"id"` + + Name string `json:"name,omitempty"` + + Type string `json:"type,omitempty"` + + Uri string `json:"uri,omitempty"` + + Version string `json:"version,omitempty"` +} diff --git a/pkg/api/zz_testcaserunstarted_0_1_0.go b/pkg/api/zz_testcaserunstarted_0_1_0.go index f559615..d0e748f 100644 --- a/pkg/api/zz_testcaserunstarted_0_1_0.go +++ b/pkg/api/zz_testcaserunstarted_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var testcaserunstartedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/test-case-run-started-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1},"type":{"type":"string","enum":["dev.cdevents.testcaserun.started.0.1.0"],"default":"dev.cdevents.testcaserun.started.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"},"type":{"type":"string","minLength":1,"enum":["testCaseRun"],"default":"testCaseRun"},"content":{"properties":{"trigger":{"type":"object","properties":{"type":{"type":"string","enum":["manual","pipeline","event","schedule","other"]},"uri":{"type":"string","format":"uri"}}},"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"testSuiteRun":{"type":"object","properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"}},"additionalProperties":false,"required":["id"]},"testCase":{"properties":{"id":{"type":"string","minLength":1},"version":{"type":"string"},"name":{"type":"string"},"type":{"type":"string","enum":["performance","functional","unit","security","compliance","integration","e2e","other"]},"uri":{"type":"string","format":"uri"}},"additionalProperties":false,"type":"object","required":["id"]}},"additionalProperties":false,"type":"object","required":["environment"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // TestCaseRunStarted event type v0.1.0 @@ -36,28 +35,28 @@ var ( } ) -type TestCaseRunStartedSubjectContent struct { +type TestCaseRunStartedSubjectContentV0_1_0 struct { Environment *Reference `json:"environment"` - TestCase *TestCaseRunStartedSubjectContentTestCase `json:"testCase,omitempty"` + TestCase *TestCaseRunStartedSubjectContentTestCaseV0_1_0 `json:"testCase,omitempty"` TestSuiteRun *Reference `json:"testSuiteRun,omitempty"` - Trigger *TestCaseRunStartedSubjectContentTrigger `json:"trigger,omitempty"` + Trigger *TestCaseRunStartedSubjectContentTriggerV0_1_0 `json:"trigger,omitempty"` } -type TestCaseRunStartedSubject struct { +type TestCaseRunStartedSubjectV0_1_0 struct { SubjectBase - Content TestCaseRunStartedSubjectContent `json:"content"` + Content TestCaseRunStartedSubjectContentV0_1_0 `json:"content"` } -func (sc TestCaseRunStartedSubject) GetSubjectType() SubjectType { +func (sc TestCaseRunStartedSubjectV0_1_0) GetSubjectType() SubjectType { return "testCaseRun" } type TestCaseRunStartedEventV0_1_0 struct { - Context Context `json:"context"` - Subject TestCaseRunStartedSubject `json:"subject"` + Context Context `json:"context"` + Subject TestCaseRunStartedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -147,9 +146,9 @@ func (e *TestCaseRunStartedEventV0_1_0) SetCustomData(contentType string, data i return nil } -func (e TestCaseRunStartedEventV0_1_0) GetSchema() (string, string) { +func (e TestCaseRunStartedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), testcaserunstartedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -158,7 +157,7 @@ func (e *TestCaseRunStartedEventV0_1_0) SetSubjectEnvironment(environment *Refer e.Subject.Content.Environment = environment } -func (e *TestCaseRunStartedEventV0_1_0) SetSubjectTestCase(testCase *TestCaseRunStartedSubjectContentTestCase) { +func (e *TestCaseRunStartedEventV0_1_0) SetSubjectTestCase(testCase *TestCaseRunStartedSubjectContentTestCaseV0_1_0) { e.Subject.Content.TestCase = testCase } @@ -166,7 +165,7 @@ func (e *TestCaseRunStartedEventV0_1_0) SetSubjectTestSuiteRun(testSuiteRun *Ref e.Subject.Content.TestSuiteRun = testSuiteRun } -func (e *TestCaseRunStartedEventV0_1_0) SetSubjectTrigger(trigger *TestCaseRunStartedSubjectContentTrigger) { +func (e *TestCaseRunStartedEventV0_1_0) SetSubjectTrigger(trigger *TestCaseRunStartedSubjectContentTriggerV0_1_0) { e.Subject.Content.Trigger = trigger } @@ -177,7 +176,7 @@ func NewTestCaseRunStartedEventV0_1_0(specVersion string) (*TestCaseRunStartedEv Type: TestCaseRunStartedEventTypeV0_1_0, Version: specVersion, }, - Subject: TestCaseRunStartedSubject{ + Subject: TestCaseRunStartedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "testCaseRun", }, @@ -190,8 +189,8 @@ func NewTestCaseRunStartedEventV0_1_0(specVersion string) (*TestCaseRunStartedEv return e, nil } -// TestCaseRunStartedSubjectContentTestCase holds the content of a TestCase field in the content -type TestCaseRunStartedSubjectContentTestCase struct { +// TestCaseRunStartedSubjectContentTestCaseV0_1_0 holds the content of a TestCase field in the content +type TestCaseRunStartedSubjectContentTestCaseV0_1_0 struct { Id string `json:"id"` Name string `json:"name,omitempty"` @@ -203,8 +202,8 @@ type TestCaseRunStartedSubjectContentTestCase struct { Version string `json:"version,omitempty"` } -// TestCaseRunStartedSubjectContentTrigger holds the content of a Trigger field in the content -type TestCaseRunStartedSubjectContentTrigger struct { +// TestCaseRunStartedSubjectContentTriggerV0_1_0 holds the content of a Trigger field in the content +type TestCaseRunStartedSubjectContentTriggerV0_1_0 struct { Type string `json:"type,omitempty"` Uri string `json:"uri,omitempty"` diff --git a/pkg/api/zz_testcaserunstarted_0_2_0.go b/pkg/api/zz_testcaserunstarted_0_2_0.go new file mode 100644 index 0000000..87832fe --- /dev/null +++ b/pkg/api/zz_testcaserunstarted_0_2_0.go @@ -0,0 +1,242 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TestCaseRunStarted event type v0.2.0 + TestCaseRunStartedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "testcaserun", + Predicate: "started", + Version: "0.2.0", + } +) + +type TestCaseRunStartedSubjectContentV0_2_0 struct { + Environment *Reference `json:"environment"` + + TestCase *TestCaseRunStartedSubjectContentTestCaseV0_2_0 `json:"testCase,omitempty"` + + TestSuiteRun *Reference `json:"testSuiteRun,omitempty"` + + Trigger *TestCaseRunStartedSubjectContentTriggerV0_2_0 `json:"trigger,omitempty"` +} + +type TestCaseRunStartedSubjectV0_2_0 struct { + SubjectBase + Content TestCaseRunStartedSubjectContentV0_2_0 `json:"content"` +} + +func (sc TestCaseRunStartedSubjectV0_2_0) GetSubjectType() SubjectType { + return "testCaseRun" +} + +type TestCaseRunStartedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject TestCaseRunStartedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TestCaseRunStartedEventV0_2_0) GetType() CDEventType { + return TestCaseRunStartedEventTypeV0_2_0 +} + +func (e TestCaseRunStartedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestCaseRunStartedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e TestCaseRunStartedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e TestCaseRunStartedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestCaseRunStartedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestCaseRunStartedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestCaseRunStartedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e TestCaseRunStartedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TestCaseRunStartedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TestCaseRunStartedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TestCaseRunStartedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TestCaseRunStartedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TestCaseRunStartedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TestCaseRunStartedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TestCaseRunStartedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TestCaseRunStartedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestCaseRunStartedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestCaseRunStartedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestCaseRunStartedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TestCaseRunStartedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TestCaseRunStartedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TestCaseRunStartedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TestCaseRunStartedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TestCaseRunStartedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TestCaseRunStartedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +func (e *TestCaseRunStartedEventV0_2_0) SetSubjectTestCase(testCase *TestCaseRunStartedSubjectContentTestCaseV0_2_0) { + e.Subject.Content.TestCase = testCase +} + +func (e *TestCaseRunStartedEventV0_2_0) SetSubjectTestSuiteRun(testSuiteRun *Reference) { + e.Subject.Content.TestSuiteRun = testSuiteRun +} + +func (e *TestCaseRunStartedEventV0_2_0) SetSubjectTrigger(trigger *TestCaseRunStartedSubjectContentTriggerV0_2_0) { + e.Subject.Content.Trigger = trigger +} + +// New creates a new TestCaseRunStartedEventV0_2_0 +func NewTestCaseRunStartedEventV0_2_0(specVersion string) (*TestCaseRunStartedEventV0_2_0, error) { + e := &TestCaseRunStartedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: TestCaseRunStartedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TestCaseRunStartedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "testCaseRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} + +// TestCaseRunStartedSubjectContentTestCaseV0_2_0 holds the content of a TestCase field in the content +type TestCaseRunStartedSubjectContentTestCaseV0_2_0 struct { + Id string `json:"id"` + + Name string `json:"name,omitempty"` + + Type string `json:"type,omitempty"` + + Uri string `json:"uri,omitempty"` + + Version string `json:"version,omitempty"` +} + +// TestCaseRunStartedSubjectContentTriggerV0_2_0 holds the content of a Trigger field in the content +type TestCaseRunStartedSubjectContentTriggerV0_2_0 struct { + Type string `json:"type,omitempty"` + + Uri string `json:"uri,omitempty"` +} diff --git a/pkg/api/zz_testoutputpublished_0_1_0.go b/pkg/api/zz_testoutputpublished_0_1_0.go index f1c0f24..1ba1f8a 100644 --- a/pkg/api/zz_testoutputpublished_0_1_0.go +++ b/pkg/api/zz_testoutputpublished_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var testoutputpublishedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/test-output-published-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1},"type":{"type":"string","enum":["dev.cdevents.testoutput.published.0.1.0"],"default":"dev.cdevents.testoutput.published.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"},"type":{"type":"string","minLength":1,"enum":["testOutput"],"default":"testOutput"},"content":{"properties":{"outputType":{"type":"string","enum":["report","video","image","log","other"]},"format":{"type":"string","example":"application/pdf"},"uri":{"type":"string","format":"uri"},"testCaseRun":{"type":"object","properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"}},"additionalProperties":false,"required":["id"]}},"additionalProperties":false,"type":"object","required":["outputType","format"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // TestOutputPublished event type v0.1.0 @@ -36,7 +35,7 @@ var ( } ) -type TestOutputPublishedSubjectContent struct { +type TestOutputPublishedSubjectContentV0_1_0 struct { Format string `json:"format"` OutputType string `json:"outputType"` @@ -46,18 +45,18 @@ type TestOutputPublishedSubjectContent struct { Uri string `json:"uri,omitempty"` } -type TestOutputPublishedSubject struct { +type TestOutputPublishedSubjectV0_1_0 struct { SubjectBase - Content TestOutputPublishedSubjectContent `json:"content"` + Content TestOutputPublishedSubjectContentV0_1_0 `json:"content"` } -func (sc TestOutputPublishedSubject) GetSubjectType() SubjectType { +func (sc TestOutputPublishedSubjectV0_1_0) GetSubjectType() SubjectType { return "testOutput" } type TestOutputPublishedEventV0_1_0 struct { - Context Context `json:"context"` - Subject TestOutputPublishedSubject `json:"subject"` + Context Context `json:"context"` + Subject TestOutputPublishedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -147,9 +146,9 @@ func (e *TestOutputPublishedEventV0_1_0) SetCustomData(contentType string, data return nil } -func (e TestOutputPublishedEventV0_1_0) GetSchema() (string, string) { +func (e TestOutputPublishedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), testoutputpublishedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -177,7 +176,7 @@ func NewTestOutputPublishedEventV0_1_0(specVersion string) (*TestOutputPublished Type: TestOutputPublishedEventTypeV0_1_0, Version: specVersion, }, - Subject: TestOutputPublishedSubject{ + Subject: TestOutputPublishedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "testOutput", }, diff --git a/pkg/api/zz_testoutputpublished_0_2_0.go b/pkg/api/zz_testoutputpublished_0_2_0.go new file mode 100644 index 0000000..d508352 --- /dev/null +++ b/pkg/api/zz_testoutputpublished_0_2_0.go @@ -0,0 +1,222 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TestOutputPublished event type v0.2.0 + TestOutputPublishedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "testoutput", + Predicate: "published", + Version: "0.2.0", + } +) + +type TestOutputPublishedSubjectContentV0_2_0 struct { + Format string `json:"format"` + + OutputType string `json:"outputType"` + + TestCaseRun *Reference `json:"testCaseRun,omitempty"` + + Uri string `json:"uri,omitempty"` +} + +type TestOutputPublishedSubjectV0_2_0 struct { + SubjectBase + Content TestOutputPublishedSubjectContentV0_2_0 `json:"content"` +} + +func (sc TestOutputPublishedSubjectV0_2_0) GetSubjectType() SubjectType { + return "testOutput" +} + +type TestOutputPublishedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject TestOutputPublishedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TestOutputPublishedEventV0_2_0) GetType() CDEventType { + return TestOutputPublishedEventTypeV0_2_0 +} + +func (e TestOutputPublishedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestOutputPublishedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e TestOutputPublishedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e TestOutputPublishedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestOutputPublishedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestOutputPublishedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestOutputPublishedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e TestOutputPublishedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TestOutputPublishedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TestOutputPublishedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TestOutputPublishedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TestOutputPublishedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TestOutputPublishedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TestOutputPublishedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TestOutputPublishedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TestOutputPublishedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestOutputPublishedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestOutputPublishedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestOutputPublishedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TestOutputPublishedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TestOutputPublishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TestOutputPublishedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TestOutputPublishedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TestOutputPublishedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TestOutputPublishedEventV0_2_0) SetSubjectFormat(format string) { + e.Subject.Content.Format = format +} + +func (e *TestOutputPublishedEventV0_2_0) SetSubjectOutputType(outputType string) { + e.Subject.Content.OutputType = outputType +} + +func (e *TestOutputPublishedEventV0_2_0) SetSubjectTestCaseRun(testCaseRun *Reference) { + e.Subject.Content.TestCaseRun = testCaseRun +} + +func (e *TestOutputPublishedEventV0_2_0) SetSubjectUri(uri string) { + e.Subject.Content.Uri = uri +} + +// New creates a new TestOutputPublishedEventV0_2_0 +func NewTestOutputPublishedEventV0_2_0(specVersion string) (*TestOutputPublishedEventV0_2_0, error) { + e := &TestOutputPublishedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: TestOutputPublishedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TestOutputPublishedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "testOutput", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_testsuiterunfinished_0_1_0.go b/pkg/api/zz_testsuiterunfinished_0_1_0.go index 73f1716..aea7ea5 100644 --- a/pkg/api/zz_testsuiterunfinished_0_1_0.go +++ b/pkg/api/zz_testsuiterunfinished_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var testsuiterunfinishedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/test-suite-finished-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1},"type":{"type":"string","enum":["dev.cdevents.testsuiterun.finished.0.1.0"],"default":"dev.cdevents.testsuiterun.finished.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"},"type":{"type":"string","minLength":1,"enum":["testSuiteRun"],"default":"testSuiteRun"},"content":{"properties":{"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"testSuite":{"type":"object","additionalProperties":false,"required":["id"],"properties":{"id":{"type":"string","minLength":1},"version":{"type":"string"},"name":{"type":"string"},"uri":{"type":"string","format":"uri"}}},"outcome":{"type":"string","enum":["pass","fail","cancel","error"]},"severity":{"type":"string","enum":["low","medium","high","critical"]},"reason":{"type":"string"}},"additionalProperties":false,"type":"object","required":["outcome","environment"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // TestSuiteRunFinished event type v0.1.0 @@ -36,7 +35,7 @@ var ( } ) -type TestSuiteRunFinishedSubjectContent struct { +type TestSuiteRunFinishedSubjectContentV0_1_0 struct { Environment *Reference `json:"environment"` Outcome string `json:"outcome"` @@ -45,21 +44,21 @@ type TestSuiteRunFinishedSubjectContent struct { Severity string `json:"severity,omitempty"` - TestSuite *TestSuiteRunFinishedSubjectContentTestSuite `json:"testSuite,omitempty"` + TestSuite *TestSuiteRunFinishedSubjectContentTestSuiteV0_1_0 `json:"testSuite,omitempty"` } -type TestSuiteRunFinishedSubject struct { +type TestSuiteRunFinishedSubjectV0_1_0 struct { SubjectBase - Content TestSuiteRunFinishedSubjectContent `json:"content"` + Content TestSuiteRunFinishedSubjectContentV0_1_0 `json:"content"` } -func (sc TestSuiteRunFinishedSubject) GetSubjectType() SubjectType { +func (sc TestSuiteRunFinishedSubjectV0_1_0) GetSubjectType() SubjectType { return "testSuiteRun" } type TestSuiteRunFinishedEventV0_1_0 struct { - Context Context `json:"context"` - Subject TestSuiteRunFinishedSubject `json:"subject"` + Context Context `json:"context"` + Subject TestSuiteRunFinishedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -149,9 +148,9 @@ func (e *TestSuiteRunFinishedEventV0_1_0) SetCustomData(contentType string, data return nil } -func (e TestSuiteRunFinishedEventV0_1_0) GetSchema() (string, string) { +func (e TestSuiteRunFinishedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), testsuiterunfinishedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -172,7 +171,7 @@ func (e *TestSuiteRunFinishedEventV0_1_0) SetSubjectSeverity(severity string) { e.Subject.Content.Severity = severity } -func (e *TestSuiteRunFinishedEventV0_1_0) SetSubjectTestSuite(testSuite *TestSuiteRunFinishedSubjectContentTestSuite) { +func (e *TestSuiteRunFinishedEventV0_1_0) SetSubjectTestSuite(testSuite *TestSuiteRunFinishedSubjectContentTestSuiteV0_1_0) { e.Subject.Content.TestSuite = testSuite } @@ -183,7 +182,7 @@ func NewTestSuiteRunFinishedEventV0_1_0(specVersion string) (*TestSuiteRunFinish Type: TestSuiteRunFinishedEventTypeV0_1_0, Version: specVersion, }, - Subject: TestSuiteRunFinishedSubject{ + Subject: TestSuiteRunFinishedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "testSuiteRun", }, @@ -196,8 +195,8 @@ func NewTestSuiteRunFinishedEventV0_1_0(specVersion string) (*TestSuiteRunFinish return e, nil } -// TestSuiteRunFinishedSubjectContentTestSuite holds the content of a TestSuite field in the content -type TestSuiteRunFinishedSubjectContentTestSuite struct { +// TestSuiteRunFinishedSubjectContentTestSuiteV0_1_0 holds the content of a TestSuite field in the content +type TestSuiteRunFinishedSubjectContentTestSuiteV0_1_0 struct { Id string `json:"id"` Name string `json:"name,omitempty"` diff --git a/pkg/api/zz_testsuiterunfinished_0_2_0.go b/pkg/api/zz_testsuiterunfinished_0_2_0.go new file mode 100644 index 0000000..70ed2e2 --- /dev/null +++ b/pkg/api/zz_testsuiterunfinished_0_2_0.go @@ -0,0 +1,239 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TestSuiteRunFinished event type v0.2.0 + TestSuiteRunFinishedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "testsuiterun", + Predicate: "finished", + Version: "0.2.0", + } +) + +type TestSuiteRunFinishedSubjectContentV0_2_0 struct { + Environment *Reference `json:"environment"` + + Outcome string `json:"outcome"` + + Reason string `json:"reason,omitempty"` + + Severity string `json:"severity,omitempty"` + + TestSuite *TestSuiteRunFinishedSubjectContentTestSuiteV0_2_0 `json:"testSuite,omitempty"` +} + +type TestSuiteRunFinishedSubjectV0_2_0 struct { + SubjectBase + Content TestSuiteRunFinishedSubjectContentV0_2_0 `json:"content"` +} + +func (sc TestSuiteRunFinishedSubjectV0_2_0) GetSubjectType() SubjectType { + return "testSuiteRun" +} + +type TestSuiteRunFinishedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject TestSuiteRunFinishedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TestSuiteRunFinishedEventV0_2_0) GetType() CDEventType { + return TestSuiteRunFinishedEventTypeV0_2_0 +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TestSuiteRunFinishedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TestSuiteRunFinishedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TestSuiteRunFinishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TestSuiteRunFinishedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TestSuiteRunFinishedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetSubjectOutcome(outcome string) { + e.Subject.Content.Outcome = outcome +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetSubjectReason(reason string) { + e.Subject.Content.Reason = reason +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetSubjectSeverity(severity string) { + e.Subject.Content.Severity = severity +} + +func (e *TestSuiteRunFinishedEventV0_2_0) SetSubjectTestSuite(testSuite *TestSuiteRunFinishedSubjectContentTestSuiteV0_2_0) { + e.Subject.Content.TestSuite = testSuite +} + +// New creates a new TestSuiteRunFinishedEventV0_2_0 +func NewTestSuiteRunFinishedEventV0_2_0(specVersion string) (*TestSuiteRunFinishedEventV0_2_0, error) { + e := &TestSuiteRunFinishedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: TestSuiteRunFinishedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TestSuiteRunFinishedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "testSuiteRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} + +// TestSuiteRunFinishedSubjectContentTestSuiteV0_2_0 holds the content of a TestSuite field in the content +type TestSuiteRunFinishedSubjectContentTestSuiteV0_2_0 struct { + Id string `json:"id"` + + Name string `json:"name,omitempty"` + + Uri string `json:"uri,omitempty"` + + Version string `json:"version,omitempty"` +} diff --git a/pkg/api/zz_testsuiterunqueued_0_1_0.go b/pkg/api/zz_testsuiterunqueued_0_1_0.go index 054a1f2..c1c16a7 100644 --- a/pkg/api/zz_testsuiterunqueued_0_1_0.go +++ b/pkg/api/zz_testsuiterunqueued_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var testsuiterunqueuedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/test-suite-run-queued-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1},"type":{"type":"string","enum":["dev.cdevents.testsuiterun.queued.0.1.0"],"default":"dev.cdevents.testsuiterun.queued.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"},"type":{"type":"string","minLength":1,"enum":["testSuiteRun"],"default":"testSuiteRun"},"content":{"properties":{"trigger":{"type":"object","properties":{"type":{"type":"string","enum":["manual","pipeline","event","schedule","other"]},"uri":{"type":"string","format":"uri"}}},"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"testSuite":{"type":"object","additionalProperties":false,"required":["id"],"properties":{"id":{"type":"string","minLength":1},"version":{"type":"string"},"name":{"type":"string"},"url":{"type":"string","format":"uri"}}}},"additionalProperties":false,"type":"object","required":["environment"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // TestSuiteRunQueued event type v0.1.0 @@ -36,26 +35,26 @@ var ( } ) -type TestSuiteRunQueuedSubjectContent struct { +type TestSuiteRunQueuedSubjectContentV0_1_0 struct { Environment *Reference `json:"environment"` - TestSuite *TestSuiteRunQueuedSubjectContentTestSuite `json:"testSuite,omitempty"` + TestSuite *TestSuiteRunQueuedSubjectContentTestSuiteV0_1_0 `json:"testSuite,omitempty"` - Trigger *TestSuiteRunQueuedSubjectContentTrigger `json:"trigger,omitempty"` + Trigger *TestSuiteRunQueuedSubjectContentTriggerV0_1_0 `json:"trigger,omitempty"` } -type TestSuiteRunQueuedSubject struct { +type TestSuiteRunQueuedSubjectV0_1_0 struct { SubjectBase - Content TestSuiteRunQueuedSubjectContent `json:"content"` + Content TestSuiteRunQueuedSubjectContentV0_1_0 `json:"content"` } -func (sc TestSuiteRunQueuedSubject) GetSubjectType() SubjectType { +func (sc TestSuiteRunQueuedSubjectV0_1_0) GetSubjectType() SubjectType { return "testSuiteRun" } type TestSuiteRunQueuedEventV0_1_0 struct { - Context Context `json:"context"` - Subject TestSuiteRunQueuedSubject `json:"subject"` + Context Context `json:"context"` + Subject TestSuiteRunQueuedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -145,9 +144,9 @@ func (e *TestSuiteRunQueuedEventV0_1_0) SetCustomData(contentType string, data i return nil } -func (e TestSuiteRunQueuedEventV0_1_0) GetSchema() (string, string) { +func (e TestSuiteRunQueuedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), testsuiterunqueuedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -156,11 +155,11 @@ func (e *TestSuiteRunQueuedEventV0_1_0) SetSubjectEnvironment(environment *Refer e.Subject.Content.Environment = environment } -func (e *TestSuiteRunQueuedEventV0_1_0) SetSubjectTestSuite(testSuite *TestSuiteRunQueuedSubjectContentTestSuite) { +func (e *TestSuiteRunQueuedEventV0_1_0) SetSubjectTestSuite(testSuite *TestSuiteRunQueuedSubjectContentTestSuiteV0_1_0) { e.Subject.Content.TestSuite = testSuite } -func (e *TestSuiteRunQueuedEventV0_1_0) SetSubjectTrigger(trigger *TestSuiteRunQueuedSubjectContentTrigger) { +func (e *TestSuiteRunQueuedEventV0_1_0) SetSubjectTrigger(trigger *TestSuiteRunQueuedSubjectContentTriggerV0_1_0) { e.Subject.Content.Trigger = trigger } @@ -171,7 +170,7 @@ func NewTestSuiteRunQueuedEventV0_1_0(specVersion string) (*TestSuiteRunQueuedEv Type: TestSuiteRunQueuedEventTypeV0_1_0, Version: specVersion, }, - Subject: TestSuiteRunQueuedSubject{ + Subject: TestSuiteRunQueuedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "testSuiteRun", }, @@ -184,8 +183,8 @@ func NewTestSuiteRunQueuedEventV0_1_0(specVersion string) (*TestSuiteRunQueuedEv return e, nil } -// TestSuiteRunQueuedSubjectContentTestSuite holds the content of a TestSuite field in the content -type TestSuiteRunQueuedSubjectContentTestSuite struct { +// TestSuiteRunQueuedSubjectContentTestSuiteV0_1_0 holds the content of a TestSuite field in the content +type TestSuiteRunQueuedSubjectContentTestSuiteV0_1_0 struct { Id string `json:"id"` Name string `json:"name,omitempty"` @@ -195,8 +194,8 @@ type TestSuiteRunQueuedSubjectContentTestSuite struct { Version string `json:"version,omitempty"` } -// TestSuiteRunQueuedSubjectContentTrigger holds the content of a Trigger field in the content -type TestSuiteRunQueuedSubjectContentTrigger struct { +// TestSuiteRunQueuedSubjectContentTriggerV0_1_0 holds the content of a Trigger field in the content +type TestSuiteRunQueuedSubjectContentTriggerV0_1_0 struct { Type string `json:"type,omitempty"` Uri string `json:"uri,omitempty"` diff --git a/pkg/api/zz_testsuiterunqueued_0_2_0.go b/pkg/api/zz_testsuiterunqueued_0_2_0.go new file mode 100644 index 0000000..50fba0a --- /dev/null +++ b/pkg/api/zz_testsuiterunqueued_0_2_0.go @@ -0,0 +1,234 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TestSuiteRunQueued event type v0.2.0 + TestSuiteRunQueuedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "testsuiterun", + Predicate: "queued", + Version: "0.2.0", + } +) + +type TestSuiteRunQueuedSubjectContentV0_2_0 struct { + Environment *Reference `json:"environment"` + + TestSuite *TestSuiteRunQueuedSubjectContentTestSuiteV0_2_0 `json:"testSuite,omitempty"` + + Trigger *TestSuiteRunQueuedSubjectContentTriggerV0_2_0 `json:"trigger,omitempty"` +} + +type TestSuiteRunQueuedSubjectV0_2_0 struct { + SubjectBase + Content TestSuiteRunQueuedSubjectContentV0_2_0 `json:"content"` +} + +func (sc TestSuiteRunQueuedSubjectV0_2_0) GetSubjectType() SubjectType { + return "testSuiteRun" +} + +type TestSuiteRunQueuedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject TestSuiteRunQueuedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TestSuiteRunQueuedEventV0_2_0) GetType() CDEventType { + return TestSuiteRunQueuedEventTypeV0_2_0 +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TestSuiteRunQueuedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TestSuiteRunQueuedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TestSuiteRunQueuedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestSuiteRunQueuedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestSuiteRunQueuedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestSuiteRunQueuedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TestSuiteRunQueuedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TestSuiteRunQueuedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TestSuiteRunQueuedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TestSuiteRunQueuedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TestSuiteRunQueuedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TestSuiteRunQueuedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +func (e *TestSuiteRunQueuedEventV0_2_0) SetSubjectTestSuite(testSuite *TestSuiteRunQueuedSubjectContentTestSuiteV0_2_0) { + e.Subject.Content.TestSuite = testSuite +} + +func (e *TestSuiteRunQueuedEventV0_2_0) SetSubjectTrigger(trigger *TestSuiteRunQueuedSubjectContentTriggerV0_2_0) { + e.Subject.Content.Trigger = trigger +} + +// New creates a new TestSuiteRunQueuedEventV0_2_0 +func NewTestSuiteRunQueuedEventV0_2_0(specVersion string) (*TestSuiteRunQueuedEventV0_2_0, error) { + e := &TestSuiteRunQueuedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: TestSuiteRunQueuedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TestSuiteRunQueuedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "testSuiteRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} + +// TestSuiteRunQueuedSubjectContentTestSuiteV0_2_0 holds the content of a TestSuite field in the content +type TestSuiteRunQueuedSubjectContentTestSuiteV0_2_0 struct { + Id string `json:"id"` + + Name string `json:"name,omitempty"` + + Url string `json:"url,omitempty"` + + Version string `json:"version,omitempty"` +} + +// TestSuiteRunQueuedSubjectContentTriggerV0_2_0 holds the content of a Trigger field in the content +type TestSuiteRunQueuedSubjectContentTriggerV0_2_0 struct { + Type string `json:"type,omitempty"` + + Uri string `json:"uri,omitempty"` +} diff --git a/pkg/api/zz_testsuiterunstarted_0_1_0.go b/pkg/api/zz_testsuiterunstarted_0_1_0.go index c84d69f..28b3c9b 100644 --- a/pkg/api/zz_testsuiterunstarted_0_1_0.go +++ b/pkg/api/zz_testsuiterunstarted_0_1_0.go @@ -21,11 +21,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var testsuiterunstartedschema0_1_0 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/0.3.0/schema/test-suite-run-started-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1},"type":{"type":"string","enum":["dev.cdevents.testsuiterun.started.0.1.0"],"default":"dev.cdevents.testsuiterun.started.0.1.0"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string"},"type":{"type":"string","minLength":1,"enum":["testSuiteRun"],"default":"testSuiteRun"},"content":{"properties":{"trigger":{"type":"object","properties":{"type":{"type":"string","enum":["manual","pipeline","event","schedule","other"]},"uri":{"type":"string","format":"uri"}}},"environment":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"testSuite":{"type":"object","additionalProperties":false,"required":["id"],"properties":{"id":{"type":"string","minLength":1},"version":{"type":"string"},"name":{"type":"string"},"uri":{"type":"string","format":"uri"}}}},"additionalProperties":false,"type":"object","required":["environment"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // TestSuiteRunStarted event type v0.1.0 @@ -36,26 +35,26 @@ var ( } ) -type TestSuiteRunStartedSubjectContent struct { +type TestSuiteRunStartedSubjectContentV0_1_0 struct { Environment *Reference `json:"environment"` - TestSuite *TestSuiteRunStartedSubjectContentTestSuite `json:"testSuite,omitempty"` + TestSuite *TestSuiteRunStartedSubjectContentTestSuiteV0_1_0 `json:"testSuite,omitempty"` - Trigger *TestSuiteRunStartedSubjectContentTrigger `json:"trigger,omitempty"` + Trigger *TestSuiteRunStartedSubjectContentTriggerV0_1_0 `json:"trigger,omitempty"` } -type TestSuiteRunStartedSubject struct { +type TestSuiteRunStartedSubjectV0_1_0 struct { SubjectBase - Content TestSuiteRunStartedSubjectContent `json:"content"` + Content TestSuiteRunStartedSubjectContentV0_1_0 `json:"content"` } -func (sc TestSuiteRunStartedSubject) GetSubjectType() SubjectType { +func (sc TestSuiteRunStartedSubjectV0_1_0) GetSubjectType() SubjectType { return "testSuiteRun" } type TestSuiteRunStartedEventV0_1_0 struct { - Context Context `json:"context"` - Subject TestSuiteRunStartedSubject `json:"subject"` + Context Context `json:"context"` + Subject TestSuiteRunStartedSubjectV0_1_0 `json:"subject"` CDEventCustomData } @@ -145,9 +144,9 @@ func (e *TestSuiteRunStartedEventV0_1_0) SetCustomData(contentType string, data return nil } -func (e TestSuiteRunStartedEventV0_1_0) GetSchema() (string, string) { +func (e TestSuiteRunStartedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), testsuiterunstartedschema0_1_0 + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) } // Set subject custom fields @@ -156,11 +155,11 @@ func (e *TestSuiteRunStartedEventV0_1_0) SetSubjectEnvironment(environment *Refe e.Subject.Content.Environment = environment } -func (e *TestSuiteRunStartedEventV0_1_0) SetSubjectTestSuite(testSuite *TestSuiteRunStartedSubjectContentTestSuite) { +func (e *TestSuiteRunStartedEventV0_1_0) SetSubjectTestSuite(testSuite *TestSuiteRunStartedSubjectContentTestSuiteV0_1_0) { e.Subject.Content.TestSuite = testSuite } -func (e *TestSuiteRunStartedEventV0_1_0) SetSubjectTrigger(trigger *TestSuiteRunStartedSubjectContentTrigger) { +func (e *TestSuiteRunStartedEventV0_1_0) SetSubjectTrigger(trigger *TestSuiteRunStartedSubjectContentTriggerV0_1_0) { e.Subject.Content.Trigger = trigger } @@ -171,7 +170,7 @@ func NewTestSuiteRunStartedEventV0_1_0(specVersion string) (*TestSuiteRunStarted Type: TestSuiteRunStartedEventTypeV0_1_0, Version: specVersion, }, - Subject: TestSuiteRunStartedSubject{ + Subject: TestSuiteRunStartedSubjectV0_1_0{ SubjectBase: SubjectBase{ Type: "testSuiteRun", }, @@ -184,8 +183,8 @@ func NewTestSuiteRunStartedEventV0_1_0(specVersion string) (*TestSuiteRunStarted return e, nil } -// TestSuiteRunStartedSubjectContentTestSuite holds the content of a TestSuite field in the content -type TestSuiteRunStartedSubjectContentTestSuite struct { +// TestSuiteRunStartedSubjectContentTestSuiteV0_1_0 holds the content of a TestSuite field in the content +type TestSuiteRunStartedSubjectContentTestSuiteV0_1_0 struct { Id string `json:"id"` Name string `json:"name,omitempty"` @@ -195,8 +194,8 @@ type TestSuiteRunStartedSubjectContentTestSuite struct { Version string `json:"version,omitempty"` } -// TestSuiteRunStartedSubjectContentTrigger holds the content of a Trigger field in the content -type TestSuiteRunStartedSubjectContentTrigger struct { +// TestSuiteRunStartedSubjectContentTriggerV0_1_0 holds the content of a Trigger field in the content +type TestSuiteRunStartedSubjectContentTriggerV0_1_0 struct { Type string `json:"type,omitempty"` Uri string `json:"uri,omitempty"` diff --git a/pkg/api/zz_testsuiterunstarted_0_2_0.go b/pkg/api/zz_testsuiterunstarted_0_2_0.go new file mode 100644 index 0000000..72d3a86 --- /dev/null +++ b/pkg/api/zz_testsuiterunstarted_0_2_0.go @@ -0,0 +1,234 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TestSuiteRunStarted event type v0.2.0 + TestSuiteRunStartedEventTypeV0_2_0 CDEventType = CDEventType{ + Subject: "testsuiterun", + Predicate: "started", + Version: "0.2.0", + } +) + +type TestSuiteRunStartedSubjectContentV0_2_0 struct { + Environment *Reference `json:"environment"` + + TestSuite *TestSuiteRunStartedSubjectContentTestSuiteV0_2_0 `json:"testSuite,omitempty"` + + Trigger *TestSuiteRunStartedSubjectContentTriggerV0_2_0 `json:"trigger,omitempty"` +} + +type TestSuiteRunStartedSubjectV0_2_0 struct { + SubjectBase + Content TestSuiteRunStartedSubjectContentV0_2_0 `json:"content"` +} + +func (sc TestSuiteRunStartedSubjectV0_2_0) GetSubjectType() SubjectType { + return "testSuiteRun" +} + +type TestSuiteRunStartedEventV0_2_0 struct { + Context ContextV04 `json:"context"` + Subject TestSuiteRunStartedSubjectV0_2_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TestSuiteRunStartedEventV0_2_0) GetType() CDEventType { + return TestSuiteRunStartedEventTypeV0_2_0 +} + +func (e TestSuiteRunStartedEventV0_2_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestSuiteRunStartedEventV0_2_0) GetId() string { + return e.Context.Id +} + +func (e TestSuiteRunStartedEventV0_2_0) GetSource() string { + return e.Context.Source +} + +func (e TestSuiteRunStartedEventV0_2_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestSuiteRunStartedEventV0_2_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestSuiteRunStartedEventV0_2_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestSuiteRunStartedEventV0_2_0) GetSubject() Subject { + return e.Subject +} + +func (e TestSuiteRunStartedEventV0_2_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TestSuiteRunStartedEventV0_2_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TestSuiteRunStartedEventV0_2_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TestSuiteRunStartedEventV0_2_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TestSuiteRunStartedEventV0_2_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TestSuiteRunStartedEventV0_2_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TestSuiteRunStartedEventV0_2_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TestSuiteRunStartedEventV0_2_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TestSuiteRunStartedEventV0_2_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestSuiteRunStartedEventV0_2_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestSuiteRunStartedEventV0_2_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestSuiteRunStartedEventV0_2_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TestSuiteRunStartedEventV0_2_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TestSuiteRunStartedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TestSuiteRunStartedEventV0_2_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TestSuiteRunStartedEventV0_2_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TestSuiteRunStartedEventV0_2_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TestSuiteRunStartedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { + e.Subject.Content.Environment = environment +} + +func (e *TestSuiteRunStartedEventV0_2_0) SetSubjectTestSuite(testSuite *TestSuiteRunStartedSubjectContentTestSuiteV0_2_0) { + e.Subject.Content.TestSuite = testSuite +} + +func (e *TestSuiteRunStartedEventV0_2_0) SetSubjectTrigger(trigger *TestSuiteRunStartedSubjectContentTriggerV0_2_0) { + e.Subject.Content.Trigger = trigger +} + +// New creates a new TestSuiteRunStartedEventV0_2_0 +func NewTestSuiteRunStartedEventV0_2_0(specVersion string) (*TestSuiteRunStartedEventV0_2_0, error) { + e := &TestSuiteRunStartedEventV0_2_0{ + Context: ContextV04{ + Context{ + Type: TestSuiteRunStartedEventTypeV0_2_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TestSuiteRunStartedSubjectV0_2_0{ + SubjectBase: SubjectBase{ + Type: "testSuiteRun", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} + +// TestSuiteRunStartedSubjectContentTestSuiteV0_2_0 holds the content of a TestSuite field in the content +type TestSuiteRunStartedSubjectContentTestSuiteV0_2_0 struct { + Id string `json:"id"` + + Name string `json:"name,omitempty"` + + Uri string `json:"uri,omitempty"` + + Version string `json:"version,omitempty"` +} + +// TestSuiteRunStartedSubjectContentTriggerV0_2_0 holds the content of a Trigger field in the content +type TestSuiteRunStartedSubjectContentTriggerV0_2_0 struct { + Type string `json:"type,omitempty"` + + Uri string `json:"uri,omitempty"` +} diff --git a/pkg/api/zz_ticketclosed_0_1_0.go b/pkg/api/zz_ticketclosed_0_1_0.go new file mode 100644 index 0000000..f6dda86 --- /dev/null +++ b/pkg/api/zz_ticketclosed_0_1_0.go @@ -0,0 +1,264 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TicketClosed event type v0.1.0 + TicketClosedEventTypeV0_1_0 CDEventType = CDEventType{ + Subject: "ticket", + Predicate: "closed", + Version: "0.1.0", + } +) + +type TicketClosedSubjectContentV0_1_0 struct { + Assignees []string `json:"assignees,omitempty"` + + Creator string `json:"creator,omitempty"` + + Group string `json:"group,omitempty"` + + Labels []string `json:"labels,omitempty"` + + Milestone string `json:"milestone,omitempty"` + + Priority string `json:"priority,omitempty"` + + Resolution string `json:"resolution"` + + Summary string `json:"summary,omitempty"` + + TicketType string `json:"ticketType,omitempty"` + + UpdatedBy string `json:"updatedBy,omitempty"` + + Uri string `json:"uri"` +} + +type TicketClosedSubjectV0_1_0 struct { + SubjectBase + Content TicketClosedSubjectContentV0_1_0 `json:"content"` +} + +func (sc TicketClosedSubjectV0_1_0) GetSubjectType() SubjectType { + return "ticket" +} + +type TicketClosedEventV0_1_0 struct { + Context ContextV04 `json:"context"` + Subject TicketClosedSubjectV0_1_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TicketClosedEventV0_1_0) GetType() CDEventType { + return TicketClosedEventTypeV0_1_0 +} + +func (e TicketClosedEventV0_1_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TicketClosedEventV0_1_0) GetId() string { + return e.Context.Id +} + +func (e TicketClosedEventV0_1_0) GetSource() string { + return e.Context.Source +} + +func (e TicketClosedEventV0_1_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TicketClosedEventV0_1_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TicketClosedEventV0_1_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TicketClosedEventV0_1_0) GetSubject() Subject { + return e.Subject +} + +func (e TicketClosedEventV0_1_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TicketClosedEventV0_1_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TicketClosedEventV0_1_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TicketClosedEventV0_1_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TicketClosedEventV0_1_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TicketClosedEventV0_1_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TicketClosedEventV0_1_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TicketClosedEventV0_1_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TicketClosedEventV0_1_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TicketClosedEventV0_1_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TicketClosedEventV0_1_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TicketClosedEventV0_1_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TicketClosedEventV0_1_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TicketClosedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TicketClosedEventV0_1_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TicketClosedEventV0_1_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TicketClosedEventV0_1_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TicketClosedEventV0_1_0) SetSubjectAssignees(assignees []string) { + e.Subject.Content.Assignees = assignees +} + +func (e *TicketClosedEventV0_1_0) SetSubjectCreator(creator string) { + e.Subject.Content.Creator = creator +} + +func (e *TicketClosedEventV0_1_0) SetSubjectGroup(group string) { + e.Subject.Content.Group = group +} + +func (e *TicketClosedEventV0_1_0) SetSubjectLabels(labels []string) { + e.Subject.Content.Labels = labels +} + +func (e *TicketClosedEventV0_1_0) SetSubjectMilestone(milestone string) { + e.Subject.Content.Milestone = milestone +} + +func (e *TicketClosedEventV0_1_0) SetSubjectPriority(priority string) { + e.Subject.Content.Priority = priority +} + +func (e *TicketClosedEventV0_1_0) SetSubjectResolution(resolution string) { + e.Subject.Content.Resolution = resolution +} + +func (e *TicketClosedEventV0_1_0) SetSubjectSummary(summary string) { + e.Subject.Content.Summary = summary +} + +func (e *TicketClosedEventV0_1_0) SetSubjectTicketType(ticketType string) { + e.Subject.Content.TicketType = ticketType +} + +func (e *TicketClosedEventV0_1_0) SetSubjectUpdatedBy(updatedBy string) { + e.Subject.Content.UpdatedBy = updatedBy +} + +func (e *TicketClosedEventV0_1_0) SetSubjectUri(uri string) { + e.Subject.Content.Uri = uri +} + +// New creates a new TicketClosedEventV0_1_0 +func NewTicketClosedEventV0_1_0(specVersion string) (*TicketClosedEventV0_1_0, error) { + e := &TicketClosedEventV0_1_0{ + Context: ContextV04{ + Context{ + Type: TicketClosedEventTypeV0_1_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TicketClosedSubjectV0_1_0{ + SubjectBase: SubjectBase{ + Type: "ticket", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_ticketcreated_0_1_0.go b/pkg/api/zz_ticketcreated_0_1_0.go new file mode 100644 index 0000000..bbde39b --- /dev/null +++ b/pkg/api/zz_ticketcreated_0_1_0.go @@ -0,0 +1,252 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TicketCreated event type v0.1.0 + TicketCreatedEventTypeV0_1_0 CDEventType = CDEventType{ + Subject: "ticket", + Predicate: "created", + Version: "0.1.0", + } +) + +type TicketCreatedSubjectContentV0_1_0 struct { + Assignees []string `json:"assignees,omitempty"` + + Creator string `json:"creator"` + + Group string `json:"group,omitempty"` + + Labels []string `json:"labels,omitempty"` + + Milestone string `json:"milestone,omitempty"` + + Priority string `json:"priority,omitempty"` + + Summary string `json:"summary"` + + TicketType string `json:"ticketType,omitempty"` + + Uri string `json:"uri"` +} + +type TicketCreatedSubjectV0_1_0 struct { + SubjectBase + Content TicketCreatedSubjectContentV0_1_0 `json:"content"` +} + +func (sc TicketCreatedSubjectV0_1_0) GetSubjectType() SubjectType { + return "ticket" +} + +type TicketCreatedEventV0_1_0 struct { + Context ContextV04 `json:"context"` + Subject TicketCreatedSubjectV0_1_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TicketCreatedEventV0_1_0) GetType() CDEventType { + return TicketCreatedEventTypeV0_1_0 +} + +func (e TicketCreatedEventV0_1_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TicketCreatedEventV0_1_0) GetId() string { + return e.Context.Id +} + +func (e TicketCreatedEventV0_1_0) GetSource() string { + return e.Context.Source +} + +func (e TicketCreatedEventV0_1_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TicketCreatedEventV0_1_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TicketCreatedEventV0_1_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TicketCreatedEventV0_1_0) GetSubject() Subject { + return e.Subject +} + +func (e TicketCreatedEventV0_1_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TicketCreatedEventV0_1_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TicketCreatedEventV0_1_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TicketCreatedEventV0_1_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TicketCreatedEventV0_1_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TicketCreatedEventV0_1_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TicketCreatedEventV0_1_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TicketCreatedEventV0_1_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TicketCreatedEventV0_1_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TicketCreatedEventV0_1_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TicketCreatedEventV0_1_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TicketCreatedEventV0_1_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TicketCreatedEventV0_1_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TicketCreatedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TicketCreatedEventV0_1_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TicketCreatedEventV0_1_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TicketCreatedEventV0_1_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TicketCreatedEventV0_1_0) SetSubjectAssignees(assignees []string) { + e.Subject.Content.Assignees = assignees +} + +func (e *TicketCreatedEventV0_1_0) SetSubjectCreator(creator string) { + e.Subject.Content.Creator = creator +} + +func (e *TicketCreatedEventV0_1_0) SetSubjectGroup(group string) { + e.Subject.Content.Group = group +} + +func (e *TicketCreatedEventV0_1_0) SetSubjectLabels(labels []string) { + e.Subject.Content.Labels = labels +} + +func (e *TicketCreatedEventV0_1_0) SetSubjectMilestone(milestone string) { + e.Subject.Content.Milestone = milestone +} + +func (e *TicketCreatedEventV0_1_0) SetSubjectPriority(priority string) { + e.Subject.Content.Priority = priority +} + +func (e *TicketCreatedEventV0_1_0) SetSubjectSummary(summary string) { + e.Subject.Content.Summary = summary +} + +func (e *TicketCreatedEventV0_1_0) SetSubjectTicketType(ticketType string) { + e.Subject.Content.TicketType = ticketType +} + +func (e *TicketCreatedEventV0_1_0) SetSubjectUri(uri string) { + e.Subject.Content.Uri = uri +} + +// New creates a new TicketCreatedEventV0_1_0 +func NewTicketCreatedEventV0_1_0(specVersion string) (*TicketCreatedEventV0_1_0, error) { + e := &TicketCreatedEventV0_1_0{ + Context: ContextV04{ + Context{ + Type: TicketCreatedEventTypeV0_1_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TicketCreatedSubjectV0_1_0{ + SubjectBase: SubjectBase{ + Type: "ticket", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_ticketupdated_0_1_0.go b/pkg/api/zz_ticketupdated_0_1_0.go new file mode 100644 index 0000000..cd7b149 --- /dev/null +++ b/pkg/api/zz_ticketupdated_0_1_0.go @@ -0,0 +1,258 @@ +// Code generated by tools/generator. DO NOT EDIT. + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // TicketUpdated event type v0.1.0 + TicketUpdatedEventTypeV0_1_0 CDEventType = CDEventType{ + Subject: "ticket", + Predicate: "updated", + Version: "0.1.0", + } +) + +type TicketUpdatedSubjectContentV0_1_0 struct { + Assignees []string `json:"assignees,omitempty"` + + Creator string `json:"creator,omitempty"` + + Group string `json:"group,omitempty"` + + Labels []string `json:"labels,omitempty"` + + Milestone string `json:"milestone,omitempty"` + + Priority string `json:"priority,omitempty"` + + Summary string `json:"summary,omitempty"` + + TicketType string `json:"ticketType,omitempty"` + + UpdatedBy string `json:"updatedBy,omitempty"` + + Uri string `json:"uri"` +} + +type TicketUpdatedSubjectV0_1_0 struct { + SubjectBase + Content TicketUpdatedSubjectContentV0_1_0 `json:"content"` +} + +func (sc TicketUpdatedSubjectV0_1_0) GetSubjectType() SubjectType { + return "ticket" +} + +type TicketUpdatedEventV0_1_0 struct { + Context ContextV04 `json:"context"` + Subject TicketUpdatedSubjectV0_1_0 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e TicketUpdatedEventV0_1_0) GetType() CDEventType { + return TicketUpdatedEventTypeV0_1_0 +} + +func (e TicketUpdatedEventV0_1_0) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TicketUpdatedEventV0_1_0) GetId() string { + return e.Context.Id +} + +func (e TicketUpdatedEventV0_1_0) GetSource() string { + return e.Context.Source +} + +func (e TicketUpdatedEventV0_1_0) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TicketUpdatedEventV0_1_0) GetSubjectId() string { + return e.Subject.Id +} + +func (e TicketUpdatedEventV0_1_0) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TicketUpdatedEventV0_1_0) GetSubject() Subject { + return e.Subject +} + +func (e TicketUpdatedEventV0_1_0) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e TicketUpdatedEventV0_1_0) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e TicketUpdatedEventV0_1_0) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e TicketUpdatedEventV0_1_0) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e TicketUpdatedEventV0_1_0) GetChainId() string { + return e.Context.ChainId +} + +func (e TicketUpdatedEventV0_1_0) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e TicketUpdatedEventV0_1_0) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *TicketUpdatedEventV0_1_0) SetId(id string) { + e.Context.Id = id +} + +func (e *TicketUpdatedEventV0_1_0) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TicketUpdatedEventV0_1_0) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *TicketUpdatedEventV0_1_0) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e TicketUpdatedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *TicketUpdatedEventV0_1_0) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *TicketUpdatedEventV0_1_0) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *TicketUpdatedEventV0_1_0) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *TicketUpdatedEventV0_1_0) SetSubjectAssignees(assignees []string) { + e.Subject.Content.Assignees = assignees +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectCreator(creator string) { + e.Subject.Content.Creator = creator +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectGroup(group string) { + e.Subject.Content.Group = group +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectLabels(labels []string) { + e.Subject.Content.Labels = labels +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectMilestone(milestone string) { + e.Subject.Content.Milestone = milestone +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectPriority(priority string) { + e.Subject.Content.Priority = priority +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectSummary(summary string) { + e.Subject.Content.Summary = summary +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectTicketType(ticketType string) { + e.Subject.Content.TicketType = ticketType +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectUpdatedBy(updatedBy string) { + e.Subject.Content.UpdatedBy = updatedBy +} + +func (e *TicketUpdatedEventV0_1_0) SetSubjectUri(uri string) { + e.Subject.Content.Uri = uri +} + +// New creates a new TicketUpdatedEventV0_1_0 +func NewTicketUpdatedEventV0_1_0(specVersion string) (*TicketUpdatedEventV0_1_0, error) { + e := &TicketUpdatedEventV0_1_0{ + Context: ContextV04{ + Context{ + Type: TicketUpdatedEventTypeV0_1_0, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: TicketUpdatedSubjectV0_1_0{ + SubjectBase: SubjectBase{ + Type: "ticket", + }, + }, + } + _, err := initCDEvent(e) + if err != nil { + return nil, err + } + return e, nil +} diff --git a/pkg/api/zz_ztest_foosubjectbarpredicate_1_2_3.go b/pkg/api/zz_ztest_foosubjectbarpredicate_1_2_3.go index 6793087..e72ef6e 100644 --- a/pkg/api/zz_ztest_foosubjectbarpredicate_1_2_3.go +++ b/pkg/api/zz_ztest_foosubjectbarpredicate_1_2_3.go @@ -23,11 +23,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" "time" -) -var foosubjectbarpredicateschema1_2_3 = `{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://cdevents.dev/99.0.0/schema/foosubject-barpredicate-event","properties":{"context":{"properties":{"version":{"type":"string","minLength":1},"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","enum":["dev.cdevents.foosubject.barpredicate.1.2.3"],"default":"dev.cdevents.foosubject.barpredicate.1.2.3"},"timestamp":{"type":"string","format":"date-time"}},"additionalProperties":false,"type":"object","required":["version","id","source","type","timestamp"]},"subject":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"},"type":{"type":"string","minLength":1,"enum":["fooSubject"],"default":"fooSubject"},"content":{"properties":{"plainField":{"type":"string","minLength":1},"referenceField":{"properties":{"id":{"type":"string","minLength":1},"source":{"type":"string","minLength":1,"format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["id"]},"artifactId":{"type":"string"},"objectField":{"properties":{"required":{"type":"string","minLength":1},"optional":{"type":"string","format":"uri-reference"}},"additionalProperties":false,"type":"object","required":["required"]}},"additionalProperties":false,"type":"object","required":["plainField","referenceField"]}},"additionalProperties":false,"type":"object","required":["id","type","content"]},"customData":{"oneOf":[{"type":"object"},{"type":"string","contentEncoding":"base64"}]},"customDataContentType":{"type":"string"}},"additionalProperties":false,"type":"object","required":["context","subject"]}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // FooSubjectBarPredicate event type v1.2.3 @@ -38,28 +37,28 @@ var ( } ) -type FooSubjectBarPredicateSubjectContent struct { +type FooSubjectBarPredicateSubjectContentV1_2_3 struct { ArtifactId string `json:"artifactId,omitempty" validate:"purl"` - ObjectField *FooSubjectBarPredicateSubjectContentObjectField `json:"objectField,omitempty"` + ObjectField *FooSubjectBarPredicateSubjectContentObjectFieldV1_2_3 `json:"objectField,omitempty"` PlainField string `json:"plainField"` ReferenceField *Reference `json:"referenceField"` } -type FooSubjectBarPredicateSubject struct { +type FooSubjectBarPredicateSubjectV1_2_3 struct { SubjectBase - Content FooSubjectBarPredicateSubjectContent `json:"content"` + Content FooSubjectBarPredicateSubjectContentV1_2_3 `json:"content"` } -func (sc FooSubjectBarPredicateSubject) GetSubjectType() SubjectType { +func (sc FooSubjectBarPredicateSubjectV1_2_3) GetSubjectType() SubjectType { return "fooSubject" } type FooSubjectBarPredicateEventV1_2_3 struct { - Context Context `json:"context"` - Subject FooSubjectBarPredicateSubject `json:"subject"` + Context ContextV04 `json:"context"` + Subject FooSubjectBarPredicateSubjectV1_2_3 `json:"subject"` CDEventCustomData } @@ -113,6 +112,20 @@ func (e FooSubjectBarPredicateEventV1_2_3) GetCustomDataContentType() string { return e.CustomDataContentType } +// CDEventsReaderV04 implementation + +func (e FooSubjectBarPredicateEventV1_2_3) GetChainId() string { + return e.Context.ChainId +} + +func (e FooSubjectBarPredicateEventV1_2_3) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e FooSubjectBarPredicateEventV1_2_3) GetSchemaUri() string { + return e.Context.SchemaUri +} + // CDEventsWriter implementation func (e *FooSubjectBarPredicateEventV1_2_3) SetId(id string) { @@ -149,9 +162,23 @@ func (e *FooSubjectBarPredicateEventV1_2_3) SetCustomData(contentType string, da return nil } -func (e FooSubjectBarPredicateEventV1_2_3) GetSchema() (string, string) { +func (e FooSubjectBarPredicateEventV1_2_3) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), foosubjectbarpredicateschema1_2_3 + return TestCompiledSchemas.GetBySpecSubjectPredicate("99.0.0", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *FooSubjectBarPredicateEventV1_2_3) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *FooSubjectBarPredicateEventV1_2_3) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *FooSubjectBarPredicateEventV1_2_3) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema } // Set subject custom fields @@ -160,7 +187,7 @@ func (e *FooSubjectBarPredicateEventV1_2_3) SetSubjectArtifactId(artifactId stri e.Subject.Content.ArtifactId = artifactId } -func (e *FooSubjectBarPredicateEventV1_2_3) SetSubjectObjectField(objectField *FooSubjectBarPredicateSubjectContentObjectField) { +func (e *FooSubjectBarPredicateEventV1_2_3) SetSubjectObjectField(objectField *FooSubjectBarPredicateSubjectContentObjectFieldV1_2_3) { e.Subject.Content.ObjectField = objectField } @@ -175,11 +202,15 @@ func (e *FooSubjectBarPredicateEventV1_2_3) SetSubjectReferenceField(referenceFi // New creates a new FooSubjectBarPredicateEventV1_2_3 func NewFooSubjectBarPredicateEventV1_2_3(specVersion string) (*FooSubjectBarPredicateEventV1_2_3, error) { e := &FooSubjectBarPredicateEventV1_2_3{ - Context: Context{ - Type: FooSubjectBarPredicateEventTypeV1_2_3, - Version: specVersion, + Context: ContextV04{ + Context{ + Type: FooSubjectBarPredicateEventTypeV1_2_3, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, }, - Subject: FooSubjectBarPredicateSubject{ + Subject: FooSubjectBarPredicateSubjectV1_2_3{ SubjectBase: SubjectBase{ Type: "fooSubject", }, @@ -192,8 +223,8 @@ func NewFooSubjectBarPredicateEventV1_2_3(specVersion string) (*FooSubjectBarPre return e, nil } -// FooSubjectBarPredicateSubjectContentObjectField holds the content of a ObjectField field in the content -type FooSubjectBarPredicateSubjectContentObjectField struct { +// FooSubjectBarPredicateSubjectContentObjectFieldV1_2_3 holds the content of a ObjectField field in the content +type FooSubjectBarPredicateSubjectContentObjectFieldV1_2_3 struct { Optional string `json:"optional,omitempty"` Required string `json:"required"` diff --git a/pkg/api/zz_ztest_foosubjectbarpredicate_2_2_3.go b/pkg/api/zz_ztest_foosubjectbarpredicate_2_2_3.go new file mode 100644 index 0000000..5e5794c --- /dev/null +++ b/pkg/api/zz_ztest_foosubjectbarpredicate_2_2_3.go @@ -0,0 +1,231 @@ +// Code generated by tools/generator. DO NOT EDIT. + +//go:build testonly + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +var ( + // FooSubjectBarPredicate event type v2.2.3 + FooSubjectBarPredicateEventTypeV2_2_3 CDEventType = CDEventType{ + Subject: "foosubject", + Predicate: "barpredicate", + Version: "2.2.3", + } +) + +type FooSubjectBarPredicateSubjectContentV2_2_3 struct { + ArtifactId string `json:"artifactId,omitempty" validate:"purl"` + + ObjectField *FooSubjectBarPredicateSubjectContentObjectFieldV2_2_3 `json:"objectField,omitempty"` + + PlainField string `json:"plainField"` + + ReferenceField *Reference `json:"referenceField"` +} + +type FooSubjectBarPredicateSubjectV2_2_3 struct { + SubjectBase + Content FooSubjectBarPredicateSubjectContentV2_2_3 `json:"content"` +} + +func (sc FooSubjectBarPredicateSubjectV2_2_3) GetSubjectType() SubjectType { + return "fooSubject" +} + +type FooSubjectBarPredicateEventV2_2_3 struct { + Context ContextV04 `json:"context"` + Subject FooSubjectBarPredicateSubjectV2_2_3 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e FooSubjectBarPredicateEventV2_2_3) GetType() CDEventType { + return FooSubjectBarPredicateEventTypeV2_2_3 +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetVersion() string { + return CDEventsSpecVersion +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetId() string { + return e.Context.Id +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetSource() string { + return e.Context.Source +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetSubjectId() string { + return e.Subject.Id +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetSubjectSource() string { + return e.Subject.Source +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetSubject() Subject { + return e.Subject +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e FooSubjectBarPredicateEventV2_2_3) GetChainId() string { + return e.Context.ChainId +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *FooSubjectBarPredicateEventV2_2_3) SetId(id string) { + e.Context.Id = id +} + +func (e *FooSubjectBarPredicateEventV2_2_3) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *FooSubjectBarPredicateEventV2_2_3) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *FooSubjectBarPredicateEventV2_2_3) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *FooSubjectBarPredicateEventV2_2_3) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *FooSubjectBarPredicateEventV2_2_3) SetCustomData(contentType string, data interface{}) error { + err := CheckCustomData(contentType, data) + if err != nil { + return err + } + e.CustomData = data + e.CustomDataContentType = contentType + return nil +} + +func (e FooSubjectBarPredicateEventV2_2_3) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return TestCompiledSchemas.GetBySpecSubjectPredicate("99.1.0", eType.Subject, eType.Predicate) +} + +// CDEventsWriterV04 implementation + +func (e *FooSubjectBarPredicateEventV2_2_3) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *FooSubjectBarPredicateEventV2_2_3) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *FooSubjectBarPredicateEventV2_2_3) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +// Set subject custom fields + +func (e *FooSubjectBarPredicateEventV2_2_3) SetSubjectArtifactId(artifactId string) { + e.Subject.Content.ArtifactId = artifactId +} + +func (e *FooSubjectBarPredicateEventV2_2_3) SetSubjectObjectField(objectField *FooSubjectBarPredicateSubjectContentObjectFieldV2_2_3) { + e.Subject.Content.ObjectField = objectField +} + +func (e *FooSubjectBarPredicateEventV2_2_3) SetSubjectPlainField(plainField string) { + e.Subject.Content.PlainField = plainField +} + +func (e *FooSubjectBarPredicateEventV2_2_3) SetSubjectReferenceField(referenceField *Reference) { + e.Subject.Content.ReferenceField = referenceField +} + +// New creates a new FooSubjectBarPredicateEventV2_2_3 +func NewFooSubjectBarPredicateEventV2_2_3(specVersion string) (*FooSubjectBarPredicateEventV2_2_3, error) { + e := &FooSubjectBarPredicateEventV2_2_3{ + Context: ContextV04{ + Context{ + Type: FooSubjectBarPredicateEventTypeV2_2_3, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: FooSubjectBarPredicateSubjectV2_2_3{ + SubjectBase: SubjectBase{ + Type: "fooSubject", + }, + }, + } + // Pre-seeded with test data + t, _ := time.Parse(time.RFC3339Nano, "2023-03-20T14:27:05.315384Z") + e.SetTimestamp(t) + e.SetId("271069a8-fc18-44f1-b38f-9d70a1695819") + return e, nil +} + +// FooSubjectBarPredicateSubjectContentObjectFieldV2_2_3 holds the content of a ObjectField field in the content +type FooSubjectBarPredicateSubjectContentObjectFieldV2_2_3 struct { + Optional string `json:"optional,omitempty"` + + Required string `json:"required"` +} diff --git a/tools/generator.go b/tools/generator.go index e0f788b..0a5984a 100644 --- a/tools/generator.go +++ b/tools/generator.go @@ -28,13 +28,12 @@ import ( "log" "os" "path/filepath" + "regexp" "sort" "strings" "text/template" - cdevents "github.com/cdevents/sdk-go/pkg/api" - jsonschema "github.com/santhosh-tekuri/jsonschema/v5" - _ "github.com/santhosh-tekuri/jsonschema/v5/httploader" // loads the HTTP loader + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" "golang.org/x/mod/semver" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -49,9 +48,13 @@ var ( CODE_FOLDER string GEN_CODE_FOLDER string SPEC_FOLDER_PREFIX = "spec-" - SPEC_VERSIONS = []string{"0.3.0"} + TEST_FOLDER_PREFIX = "tests-" + SPEC_VERSIONS = []string{"0.3.0", "0.4.1"} + TEST_VERSIONS = []string{"99.0.0", "99.1.0"} SCHEMA_FOLDER = "schemas" - TEST_SCHEMA_FOLDER = "tests" + LINKS_FOLDER = filepath.Join(SCHEMA_FOLDER, "links") + SCHEMA_FOLDERS = []string{LINKS_FOLDER, SCHEMA_FOLDER, CUSTOM_FOLDER} + CUSTOM_FOLDER = "custom" TEST_OUTPUT_PREFIX = "ztest_" GO_TYPES_NAMES = map[string]string{ @@ -67,20 +70,41 @@ var ( "barpredicate": "BarPredicate", } + JSON_SCHEMA_NAMES = map[string]string{ + "task-run": "taskrun", + "pipeline-run": "pipelinerun", + "test-case-run": "testcaserun", + "test-suite-run": "testsuiterun", + "test-output": "testoutput", + "test-suite-started": "testsuiterun-started", // Workaround to a bug in v0.3.0 + "test-suite-finished": "testsuiterun-finished", // Workaround to a bug in v0.3.0 + } + // Templates eventTemplateFileName = "event.go.tmpl" typesTemplateFileName = "types.go.tmpl" examplesTestsTemplateFileNames = []string{ "examples_test.go.tmpl", "factory_test.go.tmpl", + "shared_test.go.tmpl", } - specTemplateFileName = "docs.go.tmpl" + specTemplateFileName = "docs.go.tmpl" + schemaTemplateFileName = "schemas.go.tmpl" // Tool capitalizer cases.Caser // Flags RESOURCES_PATH = flag.String("resources", "", "the path to the generator resources root folder") + + // Schema DB and compiler + schemas Schemas + testSchemas Schemas + compiler jsonschema.Compiler + + // CDEvents types + cdeventsTypeRegex = "^dev\\.cdevents\\.(?P[a-z]+)\\.(?P[a-z]+)\\.(?P.*)$" + cdeventsTypeCRegex = regexp.MustCompile(cdeventsTypeRegex) ) const REFERENCE_TYPE = "Reference" @@ -113,6 +137,12 @@ type Data struct { Prefix string Schema string IsTestData bool + SpecVersion string +} + +type Schemas struct { + Data map[string][]byte + IsTestData bool } type AllData struct { @@ -129,6 +159,14 @@ func (d Data) OutputFile() string { func init() { capitalizer = cases.Title(language.English, cases.NoLower) + pathLoader := PathLoader{} + loader := jsonschema.SchemeURLLoader{ + "file": jsonschema.FileLoader{}, + "http": pathLoader, + "https": pathLoader, + } + compiler = *jsonschema.NewCompiler() + compiler.UseLoader(loader) } // GoTypeName returns the name to be used when building Go types @@ -143,6 +181,39 @@ func GoTypeName(schemaName string, mappings map[string]string) string { } } +type cdeventType struct { + Subject string + Predicate string + Version string +} + +func cdeventTypeFromString(cdet string) (cdeventType, error) { + parts := cdeventsTypeCRegex.FindStringSubmatch(cdet) + if len(parts) != 4 { + return cdeventType{}, fmt.Errorf("cannot parse event type %s", cdet) + } + return cdeventType{ + Subject: parts[1], + Predicate: parts[2], + Version: parts[3], + }, nil +} + +type PathLoader struct{} + +// LoadSchema loads schemas from the local database (global variable) +func (pl PathLoader) Load(url string) (any, error) { + var loaded map[string]interface{} + if schemaBytes, found := schemas.Data[url]; found { + err := json.Unmarshal(schemaBytes, &loaded) + if err != nil { + return nil, &jsonschema.LoadURLError{URL: url, Err: err} + } + return loaded, nil + } + return nil, &jsonschema.LoadURLError{URL: url, Err: fmt.Errorf("$id %s not found in local schema DB", url)} +} + func main() { var err error var ex string @@ -166,27 +237,92 @@ func main() { CODE_FOLDER = filepath.Join(*RESOURCES_PATH, CODE) GEN_CODE_FOLDER = filepath.Join(*RESOURCES_PATH, GEN_CODE) + // Load templates + templates, err := template.ParseGlob(TEMPLATES_FOLDER) + if err != nil { + log.Fatalf("%s", err.Error()) + } + + // Load schema files into a slice and run the schemas DB template + schemas = Schemas{ + IsTestData: false, + Data: make(map[string][]byte), + } + for _, version := range SPEC_VERSIONS { + shortVersion := semver.MajorMinor("v" + version) + for _, folder := range SCHEMA_FOLDERS { + versioned_schema_folder := filepath.Join(CODE_FOLDER, SPEC_FOLDER_PREFIX+shortVersion, folder) + err = loadSchemas(versioned_schema_folder, &schemas) + if err != nil { + log.Fatalf("%s", err.Error()) + } + } + } + outputFileName := filepath.Join(GEN_CODE_FOLDER, strings.TrimSuffix(schemaTemplateFileName, filepath.Ext(schemaTemplateFileName))) + err = executeTemplate(templates, schemaTemplateFileName, outputFileName, schemas) + if err != nil { + log.Fatalf("%s", err.Error()) + } + + // Load test schema files into a slice and run the schemas DB template + testSchemas = Schemas{ + IsTestData: true, + Data: make(map[string][]byte), + } + for _, version := range TEST_VERSIONS { + shortVersion := semver.MajorMinor("v" + version) + for _, folder := range SCHEMA_FOLDERS { + versioned_schema_folder := filepath.Join(CODE_FOLDER, TEST_FOLDER_PREFIX+shortVersion, folder) + err = loadSchemas(versioned_schema_folder, &testSchemas) + if err != nil { + log.Fatalf("%s", err.Error()) + } + } + } + testOutputFileName := filepath.Join(GEN_CODE_FOLDER, TEST_OUTPUT_PREFIX+strings.TrimSuffix(schemaTemplateFileName, filepath.Ext(schemaTemplateFileName))) + err = executeTemplate(templates, schemaTemplateFileName, testOutputFileName, testSchemas) + if err != nil { + log.Fatalf("%s", err.Error()) + } + // Generate SDK files for _, version := range SPEC_VERSIONS { shortVersion := semver.MajorMinor("v" + version) versioned_schema_folder := filepath.Join(CODE_FOLDER, SPEC_FOLDER_PREFIX+shortVersion, SCHEMA_FOLDER) log.Printf("Generating SDK files from templates: %s and schemas: %s into %s", TEMPLATES_FOLDER, versioned_schema_folder, GEN_CODE_FOLDER) - err = generate(versioned_schema_folder, GEN_CODE_FOLDER, "", version, GO_TYPES_NAMES, false) + err = generate(versioned_schema_folder, GEN_CODE_FOLDER, "", version, templates, GO_TYPES_NAMES, false) if err != nil { log.Fatalf("%s", err.Error()) } } // Generate SDK test files - test_schema_folder := filepath.Join(CODE_FOLDER, TEST_SCHEMA_FOLDER, SCHEMA_FOLDER) - log.Printf("Generating Test SDK files from templates: %s and schemas: %s into %s", TEMPLATES_FOLDER, test_schema_folder, GEN_CODE_FOLDER) - err = generate(test_schema_folder, GEN_CODE_FOLDER, TEST_OUTPUT_PREFIX, "99.0.0", GO_TYPES_TEST_NAMES, true) - if err != nil { - log.Fatalf("%s", err.Error()) + for _, version := range TEST_VERSIONS { + shortVersion := semver.MajorMinor("v" + version) + versioned_test_schema_folder := filepath.Join(CODE_FOLDER, TEST_FOLDER_PREFIX+shortVersion, SCHEMA_FOLDER) + log.Printf("Generating Test SDK files from templates: %s and schemas: %s into %s", TEMPLATES_FOLDER, versioned_test_schema_folder, GEN_CODE_FOLDER) + err = generate(versioned_test_schema_folder, GEN_CODE_FOLDER, TEST_OUTPUT_PREFIX, version, templates, GO_TYPES_TEST_NAMES, true) + if err != nil { + log.Fatalf("%s", err.Error()) + } } } -func generate(schemaFolder, genFolder, prefix, specVersion string, goTypes map[string]string, isTestMode bool) error { +func loadSchemas(schemaFolder string, schemas *Schemas) error { + // Walk the jsonschemas folder, process each ".json" file + if _, err := os.Stat(schemaFolder); err != nil { + if os.IsNotExist(err) { + // Ignore non-existing folders + return nil + } else { + // Something else went wrong + return fmt.Errorf("error loading schemas from %s: %s", schemaFolder, err) + } + } + return fs.WalkDir(os.DirFS(schemaFolder), ".", getSchemasWalkProcessor(schemaFolder, schemas)) +} + +func generate(schemaFolder, genFolder, prefix, specVersion string, templates *template.Template, goTypes map[string]string, isTestMode bool) error { // allData is used to accumulate data from all jsonschemas // which is then used to run shared templates shortSpecVersion := semver.MajorMinor("v" + specVersion) @@ -198,14 +334,9 @@ func generate(schemaFolder, genFolder, prefix, specVersion string, goTypes map[s IsTestData: isTestMode, } - allTemplates, err := template.ParseGlob(TEMPLATES_FOLDER) - if err != nil { - return err - } - // Walk the jsonschemas folder, process each ".json" file - walkProcessor := getWalkProcessor(schemaFolder, allTemplates, genFolder, goTypes, &allData, prefix, isTestMode) - err = fs.WalkDir(os.DirFS(schemaFolder), ".", walkProcessor) + walkProcessor := getWalkProcessor(schemaFolder, templates, genFolder, goTypes, &allData, prefix, isTestMode) + err := fs.WalkDir(os.DirFS(schemaFolder), ".", walkProcessor) if err != nil { return err } @@ -219,14 +350,14 @@ func generate(schemaFolder, genFolder, prefix, specVersion string, goTypes map[s // Spec types (types.go) outputFileName := filepath.Join(genFolder, allData.SpecVersionName, strings.TrimSuffix(typesTemplateFileName, filepath.Ext(typesTemplateFileName))) - err = executeTemplate(allTemplates, typesTemplateFileName, outputFileName, allData) + err = executeTemplate(templates, typesTemplateFileName, outputFileName, allData) if err != nil { return err } // Spec aliases (docs.go) specFileName := filepath.Join(genFolder, allData.SpecVersionName, strings.TrimSuffix(specTemplateFileName, filepath.Ext(specTemplateFileName))) - err = executeTemplate(allTemplates, specTemplateFileName, specFileName, allData) + err = executeTemplate(templates, specTemplateFileName, specFileName, allData) if err != nil { return err } @@ -234,8 +365,8 @@ func generate(schemaFolder, genFolder, prefix, specVersion string, goTypes map[s // Process example test files - only for real data if !isTestMode { for _, examplesTestsTemplateFileName := range examplesTestsTemplateFileNames { - outputFileName := filepath.Join(genFolder, "zz_"+prefix+strings.TrimSuffix(examplesTestsTemplateFileName, filepath.Ext(examplesTestsTemplateFileName))) - err = executeTemplate(allTemplates, examplesTestsTemplateFileName, outputFileName, allData) + outputFileName := filepath.Join(genFolder, allData.SpecVersionName, "zz_"+prefix+strings.TrimSuffix(examplesTestsTemplateFileName, filepath.Ext(examplesTestsTemplateFileName))) + err = executeTemplate(templates, examplesTestsTemplateFileName, outputFileName, allData) if err != nil { return err } @@ -244,11 +375,11 @@ func generate(schemaFolder, genFolder, prefix, specVersion string, goTypes map[s return nil } -func executeTemplate(allTemplates *template.Template, templateName, outputFileName string, data interface{}) error { +func executeTemplate(templates *template.Template, templateName, outputFileName string, data interface{}) error { // Write the template output to a buffer generated := new(bytes.Buffer) - err := allTemplates.ExecuteTemplate(generated, templateName, data) + err := templates.ExecuteTemplate(generated, templateName, data) if err != nil { return err } @@ -267,6 +398,49 @@ func executeTemplate(allTemplates *template.Template, templateName, outputFileNa return os.WriteFile(outputFileName, src, 0644) } +func getSchemasWalkProcessor(rootDir string, schemas *Schemas) fs.WalkDirFunc { + return func(path string, info fs.DirEntry, err error) error { + if err != nil { + return err + } + // Do not go into sub-folders + if info.IsDir() { + if info.Name() == "." { + return nil + } + return fs.SkipDir + } + if !strings.HasSuffix(info.Name(), ".json") { + // Ignore non-json files + return nil + } + // Set the whole path + schemaPath := filepath.Join(rootDir, path) + schemaBytes, err := os.ReadFile(schemaPath) + if err != nil { + return fmt.Errorf("cannot read schema file at %s: %v", schemaPath, err) + } + schema := struct { + Id string `json:"$id"` + }{} + // Load the jsonschema from the spec + if err := json.Unmarshal(schemaBytes, &schema); err != nil { + return fmt.Errorf("cannot unmarshal schema file at %s: %v", schemaPath, err) + } + // If no $id is defined ignore this file + if schema.Id == "" { + return nil + } + var schemaId = schema.Id + // Rewrite a few irregular schema IDs + for original, fixed := range JSON_SCHEMA_NAMES { + schemaId = strings.Replace(schemaId, original, fixed, 1) + } + (*schemas).Data[schemaId] = schemaBytes + return nil + } +} + func getWalkProcessor(rootDir string, allTemplates *template.Template, genFolder string, goTypes map[string]string, allData *AllData, prefix string, isTestMode bool) fs.WalkDirFunc { return func(path string, info fs.DirEntry, err error) error { if err != nil { @@ -286,7 +460,7 @@ func getWalkProcessor(rootDir string, allTemplates *template.Template, genFolder // Set the whole path schemaPath := filepath.Join(rootDir, path) // Load the jsonschema from the spec - sch, err := jsonschema.Compile(schemaPath) + sch, err := compiler.Compile(schemaPath) if err != nil { return err } @@ -311,11 +485,41 @@ func getWalkProcessor(rootDir string, allTemplates *template.Template, genFolder data.Schema = compressedRawSchema.String() allData.Slice = append(allData.Slice, *data) + data.SpecVersion = allData.SpecVersion // Execute the template return executeTemplate(allTemplates, eventTemplateFileName, filepath.Join(genFolder, data.OutputFile()), data) } } +func validateStringEnumAnyOf(schema *jsonschema.Schema) error { + if len(schema.AnyOf) != 2 { + return fmt.Errorf("only two types allowed when using anyOf for content property in schema %s: %v", schema.Location, schema.Types) + } + foundEnum := false + for _, anyContainer := range schema.AnyOf { + var types = []string{} + if anyContainer.Types != nil { + types = anyContainer.Types.ToStrings() + } + if len(types) != 1 { + return fmt.Errorf("only one type allowed for content property in schema %s: %v", anyContainer.Location, anyContainer.Types) + } + if types[0] != "string" { + return fmt.Errorf("only string allowed when using anyOf for types %s: %v", anyContainer.Location, anyContainer.Types) + } + if anyContainer.Enum != nil { + if foundEnum { + return fmt.Errorf("only one enum allowed when using anyOf for types %s: %v", anyContainer.Location, anyContainer.Types) + } + foundEnum = true + } + } + if !foundEnum { + return fmt.Errorf("one enum required when using anyOf for types %s: %v", schema.Location, schema.Types) + } + return nil +} + func DataFromSchema(schema *jsonschema.Schema, mappings map[string]string) (*Data, error) { // Parse the event type from the context contextSchema, ok := schema.Properties["context"] @@ -326,17 +530,17 @@ func DataFromSchema(schema *jsonschema.Schema, mappings map[string]string) (*Dat if !ok { return nil, fmt.Errorf("no type property in schema %s", eventTypeSchema.Location) } - if len(eventTypeSchema.Enum) == 0 { + if len(eventTypeSchema.Enum.Values) == 0 { return nil, fmt.Errorf("no value defined for type in schema %s", eventTypeSchema.Location) } - eventTypeString, ok := eventTypeSchema.Enum[0].(string) + eventTypeString, ok := eventTypeSchema.Enum.Values[0].(string) if !ok { return nil, fmt.Errorf("non-string value defined for type in schema %s", eventTypeSchema.Location) } if eventTypeString == "" { return nil, fmt.Errorf("empty value defined for type in schema %s", eventTypeSchema.Location) } - eventType, err := cdevents.CDEventTypeFromString(string(eventTypeString)) + eventType, err := cdeventTypeFromString(string(eventTypeString)) if err != nil { return nil, err } @@ -350,10 +554,10 @@ func DataFromSchema(schema *jsonschema.Schema, mappings map[string]string) (*Dat if !ok { return nil, fmt.Errorf("no type property in schema %s", subjectSchema.Location) } - if len(subjectTypeSchema.Enum) == 0 { + if len(subjectTypeSchema.Enum.Values) == 0 { return nil, fmt.Errorf("no value defined for type in schema %s", subjectTypeSchema.Location) } - subjectTypeString, ok := subjectTypeSchema.Enum[0].(string) + subjectTypeString, ok := subjectTypeSchema.Enum.Values[0].(string) if !ok { return nil, fmt.Errorf("non-string value defined for type in schema %s", subjectTypeSchema.Location) } @@ -370,15 +574,37 @@ func DataFromSchema(schema *jsonschema.Schema, mappings map[string]string) (*Dat contentField.NameLower = name contentField.Name = capitalizer.String(name) contentField.Required = false + var contentFieldType string for _, value := range contentSchema.Required { if name == value { contentField.Required = true } } - if len(propertySchema.Types) != 1 { - return nil, fmt.Errorf("only one type allowed for content property in schema %s", propertySchema.Location) + // Handles the case of "anyOf" with string + enum of strings + var types = []string{} + if propertySchema.Types != nil { + types = propertySchema.Types.ToStrings() } - switch propertySchema.Types[0] { + if len(types) == 0 { + if propertySchema.AnyOf != nil { + err = validateStringEnumAnyOf(propertySchema) + if err != nil { + return nil, err + } + contentFieldType = "anyOfStringEnum" + } else { + return nil, fmt.Errorf("one type required or anyOf two string types in schema %s: %v", propertySchema.Location, types) + } + } else { + contentFieldType = types[0] + } + if len(types) > 1 { + return nil, fmt.Errorf("only one type allowed for content property in schema %s: %v", propertySchema.Location, types) + } + if len(types) > 1 { + return nil, fmt.Errorf("only one type allowed for content property in schema %s: %v", propertySchema.Location, types) + } + switch contentFieldType { case "object": contentType, err := typesForSchema(name, propertySchema, mappings) if err != nil { @@ -391,12 +617,22 @@ func DataFromSchema(schema *jsonschema.Schema, mappings map[string]string) (*Dat // If this is not a "Reference" we need to namespace the type name to the event namespacedType = GoTypeName(eventType.Subject, mappings) + GoTypeName(eventType.Predicate, mappings) + "SubjectContent" + - GoTypeName(contentType.Name, mappings) + GoTypeName(contentType.Name, mappings) + "V" + strings.ReplaceAll(eventType.Version, ".", "_") } // We must use pointers here for "omitempty" to work when rendering to JSON contentField.Type = "*" + namespacedType case "string": contentField.Type = "string" + case "array": + if propertySchema.Items2020 != nil && + len(propertySchema.Items2020.Types.ToStrings()) == 1 && + propertySchema.Items2020.Types.ToStrings()[0] == "string" { + contentField.Type = "[]string" + } else { + return nil, fmt.Errorf("content property type %s not allowed in schema %s", contentField.Type, propertySchema.Location) + } + case "anyOfStringEnum": + contentField.Type = "string" default: return nil, fmt.Errorf("content property type %s not allowed in schema %s", contentField.Type, propertySchema.Location) } @@ -435,10 +671,14 @@ func typesForSchema(name string, property *jsonschema.Schema, mappings map[strin default: otherNames = append(otherNames, name) } - if len(propertySchema.Types) != 1 { + var types = []string{} + if propertySchema.Types != nil { + types = propertySchema.Types.ToStrings() + } + if len(types) != 1 { return nil, fmt.Errorf("only one type allowed for content property in schema %s", propertySchema.Location) } - if propertySchema.Types[0] != "string" { + if types[0] != "string" { return nil, fmt.Errorf("only one string type allowed for content property in schema %s", propertySchema.Location) } field := ContentField{ diff --git a/tools/generator_test.go b/tools/generator_test.go index 4248095..c5be95a 100644 --- a/tools/generator_test.go +++ b/tools/generator_test.go @@ -27,18 +27,20 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/santhosh-tekuri/jsonschema/v5" + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" + "golang.org/x/mod/semver" ) -const testSchemaJson = "../pkg/api/tests/schemas/foosubjectbarpredicate.json" +const testSchemaJson = "../pkg/api/tests-v99.1/schemas/foosubjectbarpredicate.json" +const specVersion = "0.4.1" var ( testSchema *jsonschema.Schema testSubject = "FooSubject" testSubjectType = "fooSubject" testPredicate = "BarPredicate" - testVersion = "1.2.3" - testVersionName = "1_2_3" + testVersion = "2.2.3" + testVersionName = "2_2_3" ) func panicOnError(err error) { @@ -49,7 +51,23 @@ func panicOnError(err error) { func init() { var err error - testSchema, err = jsonschema.Compile(testSchemaJson) + pathLoader := PathLoader{} + loader := jsonschema.SchemeURLLoader{ + "file": jsonschema.FileLoader{}, + "http": pathLoader, + "https": pathLoader, + } + compiler = *jsonschema.NewCompiler() + compiler.UseLoader(loader) + schemas = Schemas{ + IsTestData: false, + Data: make(map[string][]byte), + } + shortVersion := semver.MajorMinor("v" + specVersion) + schema_folder := filepath.Join("../pkg/api", SPEC_FOLDER_PREFIX+shortVersion, SCHEMA_FOLDERS[0]) // links + err = loadSchemas(schema_folder, &schemas) + panicOnError(err) + testSchema, err = compiler.Compile(testSchemaJson) panicOnError(err) } @@ -80,7 +98,7 @@ func TestDataFromSchema(t *testing.T) { }, { Name: "ObjectField", NameLower: "objectField", - Type: "*FooSubjectBarPredicateSubjectContentObjectField", + Type: "*FooSubjectBarPredicateSubjectContentObjectFieldV2_2_3", }}, ContentTypes: []ContentType{{ Name: "ObjectField", @@ -200,3 +218,134 @@ func TestExecuteTemplate_Error(t *testing.T) { t.Fatal("expected error executing template, got nil") } } + +// TestValidateStringEnumAnyOf tests the validation of the string enum anyOf case. +func TestValidateStringEnumAnyOf(t *testing.T) { + + var boolType jsonschema.Types = 4 + var stringType jsonschema.Types = 32 + tests := []struct { + name string + schema jsonschema.Schema + wantError string + }{{ + name: "valid", + schema: jsonschema.Schema{ + Location: "test_schema", + AnyOf: []*jsonschema.Schema{ + { + Location: "test_schema#/properties/content/anyOf/0", + Types: &stringType, // []string{"string"}, + Enum: &jsonschema.Enum{ + Values: []interface{}{"foo", "bar"}, + }, + }, + { + Location: "test_schema#/properties/content/anyOf/1", + Types: &stringType, // []string{"string"}, + }, + }, + }, + wantError: "", + }, { + name: "enum missing", + schema: jsonschema.Schema{ + Location: "test_schema", + AnyOf: []*jsonschema.Schema{ + { + Location: "test_schema#/properties/content/anyOf/0", + Types: &stringType, // []string{"string"}, + }, + { + Location: "test_schema#/properties/content/anyOf/1", + Types: &stringType, // []string{"string"}, + }, + }, + }, + wantError: "one enum required when using anyOf for types test_schema: ", + }, { + name: "too many enums", + schema: jsonschema.Schema{ + Location: "test_schema", + AnyOf: []*jsonschema.Schema{ + { + Location: "test_schema#/properties/content/anyOf/0", + Types: &stringType, // []string{"string"}, + Enum: &jsonschema.Enum{ + Values: []interface{}{"foo", "bar"}, + }, + }, + { + Location: "test_schema#/properties/content/anyOf/1", + Types: &stringType, // []string{"string"}, + Enum: &jsonschema.Enum{ + Values: []interface{}{"foo", "bar"}, + }, + }, + }, + }, + wantError: "only one enum allowed when using anyOf for types test_schema#/properties/content/anyOf/1: [string]", + }, { + name: "too many types", + schema: jsonschema.Schema{ + Location: "test_schema", + AnyOf: []*jsonschema.Schema{ + { + Location: "test_schema#/properties/content/anyOf/0", + Types: &stringType, // []string{"string"}, + Enum: &jsonschema.Enum{ + Values: []interface{}{"foo", "bar"}, + }, + }, + { + Location: "test_schema#/properties/content/anyOf/1", + Types: &stringType, // []string{"string"}, + }, + { + Location: "test_schema#/properties/content/anyOf/2", + Types: &stringType, // []string{"string"}, + }, + }, + }, + wantError: "only two types allowed when using anyOf for content property in schema test_schema: ", + }, { + name: "wrong types", + schema: jsonschema.Schema{ + Location: "test_schema", + AnyOf: []*jsonschema.Schema{ + { + Location: "test_schema#/properties/content/anyOf/0", + Types: &stringType, // []string{"string"}, + Enum: &jsonschema.Enum{ + Values: []interface{}{"foo", "bar"}, + }, + }, + { + Location: "test_schema#/properties/content/anyOf/1", + Types: &boolType, // []string{"bool"}, + }, + }, + }, + wantError: "only string allowed when using anyOf for types test_schema#/properties/content/anyOf/1: [boolean]", + }} + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + err := validateStringEnumAnyOf(&tc.schema) + if err != nil { + if tc.wantError == "" { + t.Fatalf("didn't expected it to fail, but it did: %v", err) + } else { + // Check the error is what is expected + if d := cmp.Diff(tc.wantError, err.Error()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } + } + } + if err == nil { + if tc.wantError != "" { + t.Fatalf("expected an error, but go none") + } + } + }) + } +} diff --git a/tools/templates/docs.go.tmpl b/tools/templates/docs.go.tmpl index b795ac0..40f9613 100644 --- a/tools/templates/docs.go.tmpl +++ b/tools/templates/docs.go.tmpl @@ -31,21 +31,32 @@ import "github.com/cdevents/sdk-go/pkg/api" var SpecVersion = "{{.SpecVersion}}" {{- range $i, $data := .Slice }} +{{ $subject := .Subject }} +{{ $predicate := .Predicate }} +{{ $versionName := .VersionName }} type {{.Subject}}{{.Predicate}}Event = api.{{.Subject}}{{.Predicate}}EventV{{.VersionName}} +type {{.Subject}}{{.Predicate}}Subject = api.{{.Subject}}{{.Predicate}}SubjectV{{.VersionName}} +{{ range $i, $type := .ContentTypes }} +// {{$subject}}{{$subject}}SubjectContent{{ .Name }}V{{$versionName}} holds the content of a {{ .Name }} field in the content +type {{$subject}}{{$predicate}}SubjectContent{{ .Name }} = api.{{$subject}}{{$predicate}}SubjectContent{{ .Name }}V{{$versionName}} +{{ end }} func New{{.Subject}}{{.Predicate}}Event() (*{{.Subject}}{{.Predicate}}Event, error) { return api.New{{.Subject}}{{.Predicate}}EventV{{.VersionName}}(SpecVersion) } + +var {{.Subject}}{{.Predicate}}EventType = api.{{.Subject}}{{.Predicate}}EventTypeV{{.VersionName}} + {{- end }} // NewFromJsonBytes builds a new CDEventReader from a JSON string as []bytes // This works by unmarshalling the context first, extracting the event type and using // that to unmarshal the rest of the event into the correct object. // It assumes the context can be unmarshalled in a `Context` object. -func NewFromJsonBytes(event []byte) (api.CDEvent, error) { - return api.NewFromJsonBytesContext[api.Context](event, CDEventsByUnversionedTypes) +func NewFromJsonBytes(event []byte) (api.CDEvent{{if ne .SpecVersion "0.3.0"}}V04{{end}}, error) { + return api.NewFromJsonBytesContext[api.CDEvent{{if ne .SpecVersion "0.3.0"}}V04{{end}}](event, CDEventsByUnversionedTypes) } // Build a new CDEventReader from a JSON string -func NewFromJsonString(event string) (api.CDEvent, error) { +func NewFromJsonString(event string) (api.CDEvent{{if ne .SpecVersion "0.3.0"}}V04{{end}}, error) { return NewFromJsonBytes([]byte(event)) } \ No newline at end of file diff --git a/tools/templates/event.go.tmpl b/tools/templates/event.go.tmpl index 28d590c..0ba2813 100644 --- a/tools/templates/event.go.tmpl +++ b/tools/templates/event.go.tmpl @@ -24,11 +24,10 @@ SPDX-License-Identifier: Apache-2.0 package api import ( - "fmt" - "time" -) + "time" -var {{.SubjectLower}}{{.PredicateLower}}schema{{.VersionName}} = `{{ .Schema }}` + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) var ( // {{.Subject}}{{.Predicate}} event type v{{.Version}} @@ -39,24 +38,28 @@ var ( } ) -type {{.Subject}}{{.Predicate}}SubjectContent struct{ +type {{.Subject}}{{.Predicate}}SubjectContentV{{.VersionName}} struct{ {{ range $i, $field := .Contents }} {{ .Name }} {{ .Type }} `json:"{{ .NameLower }}{{ if not .Required }},omitempty{{ end }}"{{ if eq .Name "ArtifactId" }} validate:"purl"{{ end }}` {{ end }} } -type {{.Subject}}{{.Predicate}}Subject struct { +type {{.Subject}}{{.Predicate}}SubjectV{{.VersionName}} struct { SubjectBase - Content {{.Subject}}{{.Predicate}}SubjectContent `json:"content"` + Content {{.Subject}}{{.Predicate}}SubjectContentV{{.VersionName}} `json:"content"` } -func (sc {{.Subject}}{{.Predicate}}Subject) GetSubjectType() SubjectType { +func (sc {{.Subject}}{{.Predicate}}SubjectV{{.VersionName}}) GetSubjectType() SubjectType { return "{{.SubjectType}}" } type {{.Subject}}{{.Predicate}}EventV{{.VersionName}} struct { +{{- if eq .SpecVersion "0.3.0"}} Context Context `json:"context"` - Subject {{.Subject}}{{.Predicate}}Subject `json:"subject"` +{{- else}} + Context ContextV04 `json:"context"` +{{- end}} + Subject {{.Subject}}{{.Predicate}}SubjectV{{.VersionName}} `json:"subject"` CDEventCustomData } @@ -110,6 +113,22 @@ func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetCustomDataContentTy return e.CustomDataContentType } +{{- if ne .SpecVersion "0.3.0"}} +// CDEventsReaderV04 implementation + +func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetChainId() string { + return e.Context.ChainId +} + +func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetSchemaUri() string { + return e.Context.SchemaUri +} +{{- end}} + // CDEventsWriter implementation func (e *{{.Subject}}{{.Predicate}}EventV{{.VersionName}}) SetId(id string) { @@ -146,11 +165,28 @@ func (e *{{.Subject}}{{.Predicate}}EventV{{.VersionName}}) SetCustomData(content return nil } -func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetSchema() (string, string) { +func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return fmt.Sprintf(CDEventsSchemaURLTemplate, CDEventsSpecVersion, eType.Subject, eType.Predicate), {{.SubjectLower}}{{.PredicateLower}}schema{{.VersionName}} + return {{if .IsTestData }}Test{{end}}CompiledSchemas.GetBySpecSubjectPredicate("{{.SpecVersion}}", eType.Subject, eType.Predicate) } +{{- if ne .SpecVersion "0.3.0"}} +// CDEventsWriterV04 implementation + +func (e *{{.Subject}}{{.Predicate}}EventV{{.VersionName}}) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *{{.Subject}}{{.Predicate}}EventV{{.VersionName}}) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *{{.Subject}}{{.Predicate}}EventV{{.VersionName}}) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} +{{- end}} + + // Set subject custom fields {{ range $i, $field := .Contents }} func (e *{{$.Subject}}{{$.Predicate}}EventV{{$.VersionName}}) SetSubject{{ .Name }}({{ .NameLower }} {{ .Type }}) { @@ -161,11 +197,21 @@ func (e *{{$.Subject}}{{$.Predicate}}EventV{{$.VersionName}}) SetSubject{{ .Name // New creates a new {{.Subject}}{{.Predicate}}EventV{{.VersionName}} func New{{.Subject}}{{.Predicate}}EventV{{.VersionName}}(specVersion string) (*{{.Subject}}{{.Predicate}}EventV{{.VersionName}}, error) { e := &{{.Subject}}{{.Predicate}}EventV{{.VersionName}}{ +{{- if eq .SpecVersion "0.3.0"}} Context: Context{ Type: {{.Subject}}{{.Predicate}}EventTypeV{{.VersionName}}, Version: specVersion, +{{- else}} + Context: ContextV04{ + Context{ + Type: {{.Subject}}{{.Predicate}}EventTypeV{{.VersionName}}, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, +{{- end}} }, - Subject: {{.Subject}}{{.Predicate}}Subject{ + Subject: {{.Subject}}{{.Predicate}}SubjectV{{.VersionName}}{ SubjectBase: SubjectBase{ Type: "{{.SubjectType}}", }, @@ -186,8 +232,8 @@ func New{{.Subject}}{{.Predicate}}EventV{{.VersionName}}(specVersion string) (*{ } {{ range $i, $type := .ContentTypes }} -// {{$.Subject}}{{$.Predicate}}SubjectContent{{ .Name }} holds the content of a {{ .Name }} field in the content -type {{$.Subject}}{{$.Predicate}}SubjectContent{{ .Name }} struct{ +// {{$.Subject}}{{$.Predicate}}SubjectContent{{ .Name }}V{{$.VersionName}} holds the content of a {{ .Name }} field in the content +type {{$.Subject}}{{$.Predicate}}SubjectContent{{ .Name }}V{{$.VersionName}} struct{ {{ range $j, $field := .Fields }} {{ .Name }} {{ .Type }} `json:"{{ .NameLower }}{{ if not .Required }},omitempty{{ end }}"` {{ end }} diff --git a/tools/templates/examples_test.go.tmpl b/tools/templates/examples_test.go.tmpl index 8250941..b19ca39 100644 --- a/tools/templates/examples_test.go.tmpl +++ b/tools/templates/examples_test.go.tmpl @@ -21,7 +21,7 @@ limitations under the License. SPDX-License-Identifier: Apache-2.0 */ -package api_test +package {{.SpecVersionName}}_test import ( "github.com/cdevents/sdk-go/pkg/api" @@ -30,12 +30,38 @@ import ( func init() { // Create events equal to examples in the spec - examplesProduced = make(map[string]api.CDEvent) + examplesProduced = make(map[string]api.CDEvent{{if ne .SpecVersion "0.3.0"}}V04{{end}}) + // Set up test links + tags := api.Tags{ + "foo1": "bar", + "foo2": "bar", + } + reference := api.EventReference{ + ContextId: testContextId, + } + elr := api.NewEmbeddedLinkRelation() + elr.SetTags(tags) + elr.SetLinkKind("TRIGGER") + elr.SetTarget(reference) + elp := api.NewEmbeddedLinkPath() + elp.SetTags(tags) + elp.SetFrom(reference) + ele := api.NewEmbeddedLinkEnd() + ele.SetTags(tags) + ele.SetFrom(reference) + testLinks = api.EmbeddedLinksArray{ + elr, elp, ele, + } + + // Create events for test {{- range $i, $data := .Slice }} // {{ .Subject }}{{ .Predicate }} Event producer new{{ .Subject }}{{ .Predicate }}, _ := spec{{ $.SpecVersionName }}.New{{ .Subject }}{{ .Predicate }}Event() setContext(new{{ .Subject }}{{ .Predicate }}, testSubjectId) +{{- if gt $.SpecVersion "0.3.0"}} + setContextV04(new{{ .Subject }}{{ .Predicate }}, true, true) +{{- end}} example{{ .Subject }}{{ .Predicate }}Event(new{{ .Subject }}{{ .Predicate }}) examplesProduced[new{{ .Subject }}{{ .Predicate }}.GetType().Short()] = new{{ .Subject }}{{ .Predicate }} {{ end }} diff --git a/tools/templates/factory_test.go.tmpl b/tools/templates/factory_test.go.tmpl index c45528f..423a3f8 100644 --- a/tools/templates/factory_test.go.tmpl +++ b/tools/templates/factory_test.go.tmpl @@ -21,9 +21,12 @@ limitations under the License. SPDX-License-Identifier: Apache-2.0 */ -package api_test +package {{.SpecVersionName}}_test -import "github.com/cdevents/sdk-go/pkg/api" +import ( + "github.com/cdevents/sdk-go/pkg/api" + api{{.SpecVersionName}} "github.com/cdevents/sdk-go/pkg/api/{{.SpecVersionName}}" +) func init() { tests = []testNewCDEventType{} @@ -31,15 +34,25 @@ func init() { {{- range $i, $data := .Slice }} tests = append(tests, testNewCDEventType{ name: "{{ .SubjectLower }} {{ .PredicateLower }}", - eventType: api.{{ .Subject }}{{ .Predicate }}EventTypeV{{.VersionName}}.String(), - expectedEvent: &api.{{ .Subject }}{{ .Predicate }}EventV{{.VersionName}}{ + eventType: api{{$.SpecVersionName}}.{{ .Subject }}{{ .Predicate }}EventType.String(), + expectedEvent: &api{{$.SpecVersionName}}.{{ .Subject }}{{ .Predicate }}Event{ +{{- if eq $.SpecVersion "0.3.0"}} + Context: api.Context{ + Type: api{{$.SpecVersionName}}.{{ .Subject }}{{ .Predicate }}EventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "{{ $.SpecVersion }}", +{{- else}} + Context: api.ContextV04{ Context: api.Context{ - Type: api.{{ .Subject }}{{ .Predicate }}EventTypeV{{.VersionName}}, + Type: api{{$.SpecVersionName}}.{{ .Subject }}{{ .Predicate }}EventType, Timestamp: timeNow(), Id: testUUID(), - Version: api.CDEventsSpecVersion, + Version: "{{ $.SpecVersion }}", }, - Subject: api.{{ .Subject }}{{ .Predicate }}Subject{ +{{- end}} + }, + Subject: api{{$.SpecVersionName}}.{{ .Subject }}{{ .Predicate }}Subject{ SubjectBase: api.SubjectBase{ Type: "{{ .SubjectType }}", }, diff --git a/tools/templates/schemas.go.tmpl b/tools/templates/schemas.go.tmpl new file mode 100644 index 0000000..573f50c --- /dev/null +++ b/tools/templates/schemas.go.tmpl @@ -0,0 +1,100 @@ +// Code generated by tools/generator. DO NOT EDIT. +{{if .IsTestData}} +//go:build testonly +{{end}} + +/* +Copyright 2024 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( +{{- if not .IsTestData}} + "fmt" +{{- end}} + "encoding/json" + + jsonschema "github.com/santhosh-tekuri/jsonschema/v6" +) + +{{- if not .IsTestData}} +type SchemaDB map[string]*jsonschema.Schema +{{- end}} + +var ( + // All compiled schemas by Id + {{if .IsTestData}}Test{{end}}CompiledSchemas SchemaDB + + // All schemas as string by Id + {{if .IsTestData}}Test{{end}}SchemasById = map[string]string{ +{{- range $id, $data := .Data }} + "{{ $id }}": `{{ printf "%s" $data }}`, +{{- end }} +} +) + +func init() { + compiler, err := new{{if .IsTestData}}Test{{end}}JsonSchemaCompiler() + panicOnError(err) + {{if .IsTestData}}Test{{end}}CompiledSchemas = make(map[string]*jsonschema.Schema) + {{- if .IsTestData}} + // For tests load non-test schemas first to cover links and custom + for url, _ := range SchemasById { + sch, err := compiler.Compile(url) + panicOnError(err) + TestCompiledSchemas[url] = sch + } + {{- end}} + for url, _ := range {{if .IsTestData}}Test{{end}}SchemasById { + sch, err := compiler.Compile(url) + panicOnError(err) + {{if .IsTestData}}Test{{end}}CompiledSchemas[url] = sch + } +} + +{{- if not .IsTestData}} +func (db SchemaDB) GetBySpecSubjectPredicate(specVersion, subject, predicate string) (string, *jsonschema.Schema, error) { + id := fmt.Sprintf(CDEventsSchemaURLTemplate, specVersion, subject, predicate) + if schemaString, found := db[id]; found { + return id, schemaString, nil + } + return "", nil, fmt.Errorf("event %s/%s not found for spec %s in local schema DB", specVersion, subject, predicate) +} +{{- end}} + +func new{{if .IsTestData}}Test{{end}}JsonSchemaCompiler() (*jsonschema.Compiler, error) { + {{- if .IsTestData}} + c, err := newJsonSchemaCompiler() + if err != nil { + return nil, err + } + {{- else}} + c := jsonschema.NewCompiler() + {{- end}} + for url, content := range {{if .IsTestData}}Test{{end}}SchemasById { + var loaded map[string]interface{} + err := json.Unmarshal([]byte(content), &loaded) + if err != nil { + return nil, err + } + if err:=c.AddResource(url, loaded); err!=nil { + return nil, err + } + } + return c, nil +} diff --git a/tools/templates/shared_test.go.tmpl b/tools/templates/shared_test.go.tmpl new file mode 100644 index 0000000..965a9b4 --- /dev/null +++ b/tools/templates/shared_test.go.tmpl @@ -0,0 +1,95 @@ +// Code generated by tools/generator. DO NOT EDIT. +{{if .IsTestData}} +//go:build testonly +{{end}} + +/* +Copyright 2023 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package {{.SpecVersionName}}_test + +import "github.com/cdevents/sdk-go/pkg/api" + +func panicOnError(err error) { + if err != nil { + panic(err.Error()) + } +} + +type testData struct { + TestValues []map[string]string `json:"testValues"` +} + +var ( + // Examples Data + testSource = "/event/source/123" + testSubjectId = "mySubject123" + testValue = "testValue" + testArtifactId = "pkg:oci/myapp@sha256%3A0b31b1c02ff458ad9b7b81cbdf8f028bd54699fa151f221d1e8de6817db93427" + testDataJson = testData{TestValues: []map[string]string{{`{{"k1": "v1"}, {"k2": "v2"}}`}}} + testDataJsonUnmarshalled = map[string]any{ + "testValues": []any{map[string]any{"k1": string("v1")}, map[string]any{"k2": string("v2")}}, + } + testDataXml = []byte("testData") + testChangeId = "myChange123" + + // V04+ Examples Data + testChainId = "4c8cb7dd-3448-41de-8768-eec704e2829b" + testLinks api.EmbeddedLinksArray + testContextId = "5328c37f-bb7e-4bb7-84ea-9f5f85e4a7ce" + testSchemaUri = "https://myorg.com/schema/custom" +) + +func init() { + // Set up test links + tags := api.Tags{ + "foo1": "bar", + "foo2": "bar", + } + reference := api.EventReference{ + ContextId: testContextId, + } + elr := api.NewEmbeddedLinkRelation() + elr.SetTags(tags) + elr.SetLinkKind("TRIGGER") + elr.SetTarget(reference) + elp := api.NewEmbeddedLinkPath() + elp.SetTags(tags) + elp.SetFrom(reference) + ele := api.NewEmbeddedLinkEnd() + ele.SetTags(tags) + ele.SetFrom(reference) + testLinks = api.EmbeddedLinksArray{ + elr, elp, ele, + } +} + +func setContext(event api.CDEventWriter, subjectId string) { + event.SetSource(testSource) + event.SetSubjectId(subjectId) +} + +func setContextV04(event api.CDEventWriterV04, chainId, schemaUri bool) { + if chainId { + event.SetChainId(testChainId) + } + if schemaUri { + event.SetSchemaUri(testSchemaUri) + } + event.SetLinks(testLinks) +} \ No newline at end of file diff --git a/tools/templates/types.go.tmpl b/tools/templates/types.go.tmpl index f26b0e2..a8cbe49 100644 --- a/tools/templates/types.go.tmpl +++ b/tools/templates/types.go.tmpl @@ -29,17 +29,17 @@ import ( "github.com/cdevents/sdk-go/pkg/api" ) -var CDEventsTypes = []api.CDEvent{ +var CDEventsTypes = []api.CDEvent{{if ne .SpecVersion "0.3.0"}}V04{{end}}{ {{- range $i, $data := .Slice }} &{{ .Subject }}{{ .Predicate }}Event{}, {{- end }} } -var CDEventsByUnversionedTypes map[string]api.CDEvent +var CDEventsByUnversionedTypes map[string]api.CDEvent{{if ne .SpecVersion "0.3.0"}}V04{{end}} func init() { // Set up CDEventsByUnversionedTypes for convenience - CDEventsByUnversionedTypes = make(map[string]api.CDEvent) + CDEventsByUnversionedTypes = make(map[string]api.CDEvent{{if ne .SpecVersion "0.3.0"}}V04{{end}}) for _, event := range CDEventsTypes { CDEventsByUnversionedTypes[event.GetType().UnversionedString()] = event }