diff --git a/README.md b/README.md index b3f953b..bd6b307 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,14 @@ func main() { See the [CloudEvents](https://github.com/cloudevents/sdk-go#send-your-first-cloudevent) docs as well. +## Documentation + +More examples are available in the [docs](./docs) folder. +Online API Reference: +- [SDK Root](https://pkg.go.dev/github.com/cdevents/sdk-go/pkg/api) +- [v03 Specific](https://pkg.go.dev/github.com/cdevents/sdk-go/pkg/api/v03) +- [v04 Specific](https://pkg.go.dev/github.com/cdevents/sdk-go/pkg/api/v04) + ## Contributing If you would like to contribute, see our [development](DEVELOPMENT.md) guide. diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..dd09ece --- /dev/null +++ b/docs/README.md @@ -0,0 +1,152 @@ +# CDEvents Go SDK Docs + +This folder contains example of how to use this SDK. + +## Create a Custom CDEvent + +If a tool wants to emit events that are not supported by the CDEvents specification, +they can do so via [custom events](https://github.com/cdevents/spec/tree/main/custom). + +Custom events are follow the CDEvents format and can be defined via the +`CustomTypeEvent` object, available since v0.4, as well as using the `CustomCDEventReader` +and `CustomCDEventWriter` interfaces. + +Let's consider the following scenario: a tool called "MyRegistry" has a concept of "Quota" +which can be "exceeded" by users of the system. We want to use events to notify when that +happens, but CDEvents does not define any quota related subject. + +```golang +type Quota struct { + User string `json:"user,omitempty"` // The use the quota applies ot + Limit string `json:"limit,omitempty"` // The limit enforced by the quota e.g. 100Gb + Current int `json:"current,omitempty"` // The current % of the quota used e.g. 90% + Threshold int `json:"threshold,omitempty"` // The threshold for warning event e.g. 85% + Level string `json:"level,omitempty"` // INFO: threshold, quota +} +``` +For this scenario we will need a few imports: + +```golang +import ( + "context" + "fmt" + "log" + + cdevents "github.com/cdevents/sdk-go/pkg/api" + cdeventsv04 "github.com/cdevents/sdk-go/pkg/api/v04" + cloudevents "github.com/cloudevents/sdk-go/v2" +) +``` + +Let's define a custom event type for this scenario. +This is our first iteration, so the event will have version "0.1.0". + +```golang +eventType := cdevents.CDEventType{ + Subject: "quota", + Predicate: "exceeded", + Version: "0.1.0", + Custom: "myregistry", +} +``` + +With a `Quota` object, let's create a CDEvent for it: + +```golang +quotaRule123 := Quota{ + User: "heavy_user", + Limit: "50Tb", + Current: 90, + Threshold: 85, + Level: "WARNING", +} + +// Create the base event +event, err := cdeventsv04.NewCustomTypeEvent() +if err != nil { + log.Fatalf("could not create a cdevent, %v", err) +} +event.SetEventType(eventType) + +// Set the required context fields +event.SetSubjectId("quotaRule123") +event.SetSource("myregistry/region/staging") + +// Set the required subject content +event.SetSubjectContent(quotaRule123) + +// If we host a schema for the overall custom CDEvent, we can add it +// to the event so that the receiver may validate custom fields like +// the event type and subject content +event.SetSchemaUri("https://myregistry.dev/schemas/cdevents/quota-exceeded/0_1_0") +``` + +To see the event, let's render it as JSON and log it: + +```golang +// Render the event as JSON +eventJson, err := cdevents.AsJsonString(event) +if err != nil { + log.Fatalf("failed to marshal the CDEvent, %v", err) +} +// Print the event +fmt.Printf("%s", eventJson) +``` + +The resulting CDEvents will look like: + +```json +{"context":{"version":"0.4.1","id":"37fc85d9-187f-4ceb-a11d-9df30f809624","source":"my/first/cdevent/program","type":"dev.cdeventsx.myregistry-quota.exceeded.0.1.0","timestamp":"2024-07-09T14:00:54.375172+01:00","schemaUri":"https://myregistry.dev/schemas/cdevents/quota-exceeded/0_1_0"},"subject":{"id":"quotaRule123","source":"my/first/cdevent/program","type":"myregistry-quota","content":{"user":"heavy_user","limit":"50Tb","current":90,"threshold":85,"level":"WARNING"}}} +``` + +To send the event, let's setup a test sink, for instance using [smee.io/](https://smee.io/). +Then let's render the event as CloudEvent and send it to the sink: + +```golang +ce, err = cdevents.AsCloudEvent(event) +if err != nil { + log.Fatalf("failed to create cloudevent, %v", err) +} + +// Set send options +ctx := cloudevents.ContextWithTarget(context.Background(), "https://smee.io/") +ctx = cloudevents.WithEncodingBinary(ctx) + +c, err = cloudevents.NewClientHTTP() +if err != nil { + log.Fatalf("failed to create client, %v", err) +} + +// Send the CloudEvent +if result := c.Send(ctx, *ce); cloudevents.IsUndelivered(result) { + log.Fatalf("failed to send, %v", result) +} +``` + +The whole code of is available under [`examples/custom.go`](./examples/custom.go): + +```shell +➜ go run custom.go | jq . +{ + "context": { + "version": "0.4.1", + "id": "f7be8a13-8bd7-4a3a-881f-ed49cc0ebf8f", + "source": "my/first/cdevent/program", + "type": "dev.cdeventsx.myregistry-quota.exceeded.0.1.0", + "timestamp": "2024-07-09T14:01:00.449264+01:00", + "schemaUri": "https://myregistry.dev/schemas/cdevents/quota-exceeded/0_1_0" + }, + "subject": { + "id": "quotaRule123", + "source": "my/first/cdevent/program", + "type": "myregistry-quota", + "content": { + "user": "heavy_user", + "limit": "50Tb", + "current": 90, + "threshold": 85, + "level": "WARNING" + } + } +} +``` \ No newline at end of file diff --git a/docs/examples/custom.go b/docs/examples/custom.go new file mode 100644 index 0000000..bf13bc2 --- /dev/null +++ b/docs/examples/custom.go @@ -0,0 +1,105 @@ +package main + +import ( + "context" + "fmt" + "log" + "net/http" + + cdevents "github.com/cdevents/sdk-go/pkg/api" + cdeventsv04 "github.com/cdevents/sdk-go/pkg/api/v04" + cloudevents "github.com/cloudevents/sdk-go/v2" +) + +type Quota struct { + User string `json:"user,omitempty"` // The use the quota applies ot + Limit string `json:"limit,omitempty"` // The limit enforced by the quota e.g. 100Gb + Current int `json:"current,omitempty"` // The current % of the quota used e.g. 90% + Threshold int `json:"threshold,omitempty"` // The threshold for warning event e.g. 85% + Level string `json:"level,omitempty"` // INFO: threshold, quota +} + +// Copied from https://github.com/eswdd/go-smee/blob/33b0bac1f1ef3abef04c518ddf7552b04edbadd2/smee.go#L54C1-L67C2 +func CreateSmeeChannel() (*string, error) { + httpClient := http.Client{ + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, + } + resp, err := httpClient.Head("https://smee.io/new") + if err != nil { + return nil, err + } + + loc := resp.Header.Get("Location") + return &loc, nil +} + +func main() { + var ce *cloudevents.Event + var c cloudevents.Client + + // Define the event type + eventType := cdevents.CDEventType{ + Subject: "quota", + Predicate: "exceeded", + Version: "0.1.0", + Custom: "myregistry", + } + + // Define the content + quotaRule123 := Quota{ + User: "heavy_user", + Limit: "50Tb", + Current: 90, + Threshold: 85, + Level: "WARNING", + } + + // Create the base event + event, err := cdeventsv04.NewCustomTypeEvent() + if err != nil { + log.Fatalf("could not create a cdevent, %v", err) + } + event.SetEventType(eventType) + + // Set the required context fields + event.SetSubjectId("quotaRule123") + event.SetSource("my/first/cdevent/program") + + // Set the required subject fields + event.SetSubjectContent(quotaRule123) + + event.SetSchemaUri("https://myregistry.dev/schemas/cdevents/quota-exceeded/0_1_0") + + // Print the event + eventJson, err := cdevents.AsJsonString(event) + if err != nil { + log.Fatalf("failed to marshal the CDEvent, %v", err) + } + fmt.Printf("%s", eventJson) + + ce, err = cdevents.AsCloudEvent(event) + if err != nil { + log.Fatalf("failed to create cloudevent, %v", err) + } + + // Set send options + source, err := CreateSmeeChannel() + if err != nil { + log.Fatalf("failed to create a smee channel: %v", err) + } + ctx := cloudevents.ContextWithTarget(context.Background(), *source) + ctx = cloudevents.WithEncodingBinary(ctx) + + c, err = cloudevents.NewClientHTTP() + if err != nil { + log.Fatalf("failed to create client, %v", err) + } + + // Send the CloudEvent + // c is a CloudEvent client + if result := c.Send(ctx, *ce); cloudevents.IsUndelivered(result) { + log.Fatalf("failed to send, %v", result) + } +} diff --git a/pkg/api/bindings.go b/pkg/api/bindings.go index f56c743..7b10941 100644 --- a/pkg/api/bindings.go +++ b/pkg/api/bindings.go @@ -30,7 +30,10 @@ import ( "golang.org/x/mod/semver" ) -const SCHEMA_ID_REGEX = `^https://cdevents.dev/([0-9]\.[0-9])\.[0-9]/schema/([^ ]*)$` +const ( + SCHEMA_ID_REGEX = `^https://cdevents.dev/([0-9]\.[0-9])\.[0-9]/schema/([^ ]*)$` + CustomEventMapKey = "custom" +) var ( // Validation helper as singleton @@ -172,24 +175,29 @@ func NewFromJsonBytesContext[CDEventType CDEvent](event []byte, cdeventsMap map[ eventAux := &struct { Context Context `json:"context"` }{} - var nilReturn CDEventType + var nilReturn, receiver CDEventType + var ok bool err := json.Unmarshal(event, eventAux) if err != nil { 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 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. - // If the minor version is different and the message received as a version that is - // 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 nilReturn, fmt.Errorf("sdk event version %s not compatible with %s", receiver.GetType().Version, eventType.Version) + if eventType.Custom != "" { + receiver = cdeventsMap[CustomEventMapKey] // Custom type receiver does not have a predefined type + } else { + 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 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. + // If the minor version is different and the message received as a version that is + // 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 nilReturn, fmt.Errorf("sdk event version %s not compatible with %s", receiver.GetType().Version, eventType.Version) + } } err = json.Unmarshal(event, receiver) if err != nil { diff --git a/pkg/api/bindings_test.go b/pkg/api/bindings_test.go index 3ae6e11..2cde8d2 100644 --- a/pkg/api/bindings_test.go +++ b/pkg/api/bindings_test.go @@ -346,7 +346,7 @@ func TestInvalidEvent(t *testing.T) { Context: api.ContextV04{ Context: api.Context{ Type: api.CDEventType{Subject: "not-a-valid-type"}, - Version: api.CDEventsSpecVersion, + Version: testapi.SpecVersion, }, }, Subject: testapi.FooSubjectBarPredicateSubject{ diff --git a/pkg/api/schemas.go b/pkg/api/schemas.go index 601ecdc..81e2097 100644 --- a/pkg/api/schemas.go +++ b/pkg/api/schemas.go @@ -6812,7 +6812,8 @@ var ( "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", @@ -11668,8 +11669,13 @@ func init() { CompiledSchemas[url] = sch } } -func (db SchemaDB) GetBySpecSubjectPredicate(specVersion, subject, predicate string) (string, *jsonschema.Schema, error) { - id := fmt.Sprintf(CDEventsSchemaURLTemplate, specVersion, subject, predicate) +func (db SchemaDB) GetBySpecSubjectPredicate(specVersion, subject, predicate, custom string) (string, *jsonschema.Schema, error) { + id := "" + if custom == "" && subject != "" && predicate != "" { + id = fmt.Sprintf(CDEventsSchemaURLTemplate, specVersion, subject, predicate) + } else { + id = fmt.Sprintf(CDEventsCustomSchemaURLTemplate, specVersion) + } if schemaString, found := db[id]; found { return id, schemaString, nil } diff --git a/pkg/api/spec-v0.4 b/pkg/api/spec-v0.4 index f95df21..984346d 160000 --- a/pkg/api/spec-v0.4 +++ b/pkg/api/spec-v0.4 @@ -1 +1 @@ -Subproject commit f95df21d7e3045a37d2c85e07f90805130fd65be +Subproject commit 984346d84b084a21ed2d660a6439e5361077b83d diff --git a/pkg/api/types.go b/pkg/api/types.go index b68bfdb..1e5fa7c 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -31,10 +31,12 @@ import ( ) const ( - EventTypeRoot = "dev.cdevents" - CDEventsSpecVersion = "0.3.0" - CDEventsSchemaURLTemplate = "https://cdevents.dev/%s/schema/%s-%s-event" - CDEventsTypeRegex = "^dev\\.cdevents\\.(?P[a-z]+)\\.(?P[a-z]+)\\.(?P.*)$" + EventTypeRoot = "dev.cdevents" + CustomEventTypeRoot = "dev.cdeventsx" + CDEventsSchemaURLTemplate = "https://cdevents.dev/%s/schema/%s-%s-event" + CDEventsCustomSchemaURLTemplate = "https://cdevents.dev/%s/schema/custom" + CDEventsTypeRegex = "^dev\\.cdevents\\.(?P[a-z]+)\\.(?P[a-z]+)\\.(?P.*)$" + CDEventsCustomTypeRegex = "^dev\\.cdeventsx\\.(?P[a-z]+)-(?P[a-z]+)\\.(?P[a-z]+)\\.(?P.*)$" LinkTypePath LinkType = "PATH" LinkTypeEnd LinkType = "END" @@ -42,8 +44,9 @@ const ( ) var ( - CDEventsTypeCRegex = regexp.MustCompile(CDEventsTypeRegex) - LinkTypes = map[LinkType]interface{}{ + CDEventsTypeCRegex = regexp.MustCompile(CDEventsTypeRegex) + CDEventsCustomTypeCRegex = regexp.MustCompile(CDEventsCustomTypeRegex) + LinkTypes = map[LinkType]interface{}{ LinkTypePath: "", LinkTypeEnd: "", LinkTypeRelation: "", @@ -380,18 +383,59 @@ type CDEventType struct { // Version is a semantic version in the form .. Version string + + // Custom holds the tool name in case of custom events + Custom string +} + +func (t CDEventType) Root() string { + root := EventTypeRoot + if t.Custom != "" { + root = CustomEventTypeRoot + } + return root +} + +// FQSubject returns the fully qualified subject, which includes +// the tool name from t.Custom in case of custom events +func (t CDEventType) FQSubject() string { + s := t.Subject + if s == "" { + s = "" + } + if t.Custom != "" { + s = t.Custom + "-" + s + } + return s } func (t CDEventType) String() string { - return EventTypeRoot + "." + t.Subject + "." + t.Predicate + "." + t.Version + predicate := t.Predicate + if predicate == "" { + predicate = "" + } + version := t.Version + if version == "" { + version = "" + } + return t.Root() + "." + t.FQSubject() + "." + predicate + "." + version } func (t CDEventType) UnversionedString() string { - return EventTypeRoot + "." + t.Subject + "." + t.Predicate + predicate := t.Predicate + if predicate == "" { + predicate = "" + } + return t.Root() + "." + t.FQSubject() + "." + predicate } func (t CDEventType) Short() string { - return t.Subject + "_" + t.Predicate + s := t.FQSubject() + p := t.Predicate + if s == "" || p == "" { + return "" + } + return t.FQSubject() + "_" + t.Predicate } // Two CDEventTypes are compatible if the subject and predicates @@ -420,15 +464,32 @@ func (t CDEventType) MarshalJSON() ([]byte, error) { } func CDEventTypeFromString(cdeventType string) (*CDEventType, error) { + names := CDEventsTypeCRegex.SubexpNames() parts := CDEventsTypeCRegex.FindStringSubmatch(cdeventType) if len(parts) != 4 { - return nil, fmt.Errorf("cannot parse event type %s", cdeventType) + names = CDEventsCustomTypeCRegex.SubexpNames() + parts = CDEventsCustomTypeCRegex.FindStringSubmatch(cdeventType) + if len(parts) != 5 { + return nil, fmt.Errorf("cannot parse event type %s", cdeventType) + } + } + returnType := CDEventType{} + for i, matchName := range names { + if i == 0 { + continue + } + switch matchName { + case "subject": + returnType.Subject = parts[i] + case "predicate": + returnType.Predicate = parts[i] + case "version": + returnType.Version = parts[i] + case "tool": + returnType.Custom = parts[i] + } } - return &CDEventType{ - Subject: parts[1], - Predicate: parts[2], - Version: parts[3], - }, nil + return &returnType, nil } type CDEventReader interface { @@ -459,6 +520,11 @@ type CDEventReader interface { // for direct access to the content fields GetSubject() Subject + // The event specific subject. It is possible to use a type assertion with + // the generic Subject to obtain an event specific implementation of Subject + // for direct access to the content fields + GetSubjectContent() interface{} + // The URL and content of the schema file associated to the event type GetSchema() (string, *jsonschema.Schema, error) @@ -531,6 +597,20 @@ type CDEventWriterV04 interface { SetSchemaUri(schema string) } +type CustomCDEventReader interface { + CDEventReaderV04 +} + +type CustomCDEventWriter interface { + CDEventWriterV04 + + // CustomCDEvent can represent different event types + SetEventType(eventType CDEventType) + + // CustomCDEvent types can have different subject fields + SetSubjectContent(subjectContent interface{}) +} + type CDEventCustomDataEncoding string func (t CDEventCustomDataEncoding) String() string { diff --git a/pkg/api/types_test.go b/pkg/api/types_test.go index b9bb644..180f6c6 100644 --- a/pkg/api/types_test.go +++ b/pkg/api/types_test.go @@ -380,6 +380,16 @@ func TestCDEventTypeFromString(t *testing.T) { Version: "123.a-da#@#", }, wantError: false, + }, { + name: "parses, custom", + eventType: "dev.cdeventsx.tool-a.b.123.a-da#@#", + want: &api.CDEventType{ + Subject: "a", + Predicate: "b", + Version: "123.a-da#@#", + Custom: "tool", + }, + wantError: false, }, { name: "missing version", eventType: "dev.cdevents.a.b", @@ -395,6 +405,16 @@ func TestCDEventTypeFromString(t *testing.T) { eventType: "dev.cdevents.a1.b2.version", want: nil, wantError: true, + }, { + name: "missing version, custom", + eventType: "dev.cdeventsx.tool-a.b", + want: nil, + wantError: true, + }, { + name: "missing tool, custom", + eventType: "dev.cdeventsx.a1.b2.version", + want: nil, + wantError: true, }} for _, tc := range tests { diff --git a/pkg/api/v03/examples_test.go b/pkg/api/v03/examples_test.go index 27435da..9c43840 100644 --- a/pkg/api/v03/examples_test.go +++ b/pkg/api/v03/examples_test.go @@ -424,6 +424,10 @@ func TestExamples(t *testing.T) { if d := cmp.Diff(consumed.GetSubject(), produced.GetSubject()); d != "" { t.Errorf("args: diff(-want,+got):\n%s", d) } + // Coverage for GetSubjectContent + if d := cmp.Diff(consumed.GetSubjectContent(), produced.GetSubjectContent()); d != "" { + t.Errorf("args: diff(-want,+got):\n%s", d) + } }) } } diff --git a/pkg/api/v03/types.go b/pkg/api/v03/types.go index c603d44..ee3011c 100644 --- a/pkg/api/v03/types.go +++ b/pkg/api/v03/types.go @@ -74,7 +74,8 @@ func init() { // Set up CDEventsByUnversionedTypes for convenience CDEventsByUnversionedTypes = make(map[string]api.CDEvent) for _, event := range CDEventsTypes { - CDEventsByUnversionedTypes[event.GetType().UnversionedString()] = event + key := event.GetType().UnversionedString() + CDEventsByUnversionedTypes[key] = event } } diff --git a/pkg/api/v04/conformance_test.go b/pkg/api/v04/conformance_test.go index b1346b9..cac3f17 100644 --- a/pkg/api/v04/conformance_test.go +++ b/pkg/api/v04/conformance_test.go @@ -19,6 +19,7 @@ SPDX-License-Identifier: Apache-2.0 package v04_test import ( + "encoding/json" "os" "path/filepath" "testing" @@ -30,7 +31,10 @@ import ( "github.com/google/uuid" ) -const examplesFolder = "spec-v0.4/conformance" +const ( + examplesFolder = "spec-v0.4/conformance" + customExample = "spec-v0.4/custom/conformance.json" +) var ( // Examples Data @@ -106,6 +110,22 @@ var ( testTicketType = "task" testTicketUpdatedBy = "Bob" testTicketUri = "https://example.issues.com/ticket123" + testCustomEventType = api.CDEventType{ + // dev.cdeventsx.mytool-resource.created.0.1.0 + Subject: "resource", + Predicate: "created", + Custom: "mytool", + Version: "0.1.0", + } + testCustomContentBytes = []byte(`{ + "user": "mybot-myapp", + "description": "a useful resource", + "nested": { + "key": "value", + "list": ["data1", "data2"] + } + }`) + testCustomContent interface{} examplesConsumed map[string][]byte examplesProduced map[string]api.CDEventV04 @@ -124,6 +144,9 @@ func init() { uuidNewRandom = func() (uuid.UUID, error) { return u, nil } + + err = json.Unmarshal(testCustomContentBytes, &testCustomContent) + panicOnError(err) } func exampleArtifactPackagedEvent(e *apiv04.ArtifactPackagedEvent) { @@ -488,6 +511,16 @@ func exampleTicketUpdatedEvent(e *apiv04.TicketUpdatedEvent) { e.SetChainId("") } +func exampleCustomTypeEvent(e *apiv04.CustomTypeEvent) { + // Set example specific fields + // Set the type to dev.cdeventsx.mytool-resource.created.0.1.0 + e.SetEventType(testCustomEventType) + e.SetSubjectContent(testCustomContent) + e.SetSchemaUri("https://myorg.com/schema/mytool") + e.SetSubjectId("pkg:resource/name@234fd47e07d1004f0aed9c") + e.SetChainId("6ca3f9c5-1cef-4ce0-861c-2456a69cf137") +} + func init() { // Load event examples from the spec @@ -495,8 +528,13 @@ func init() { for _, event := range apiv04.CDEventsTypes { short := event.GetType().Short() - examplesConsumed[short], err = os.ReadFile(filepath.Join("..", examplesFolder, short+".json")) - panicOnError(err) + if short != "" { + examplesConsumed[short], err = os.ReadFile(filepath.Join("..", examplesFolder, short+".json")) + panicOnError(err) + } else { + // There is no type set for custom events, and the example is in a different folder + examplesConsumed[short], err = os.ReadFile(filepath.Join("..", customExample)) + } } } @@ -537,6 +575,10 @@ func TestExamples(t *testing.T) { if d := cmp.Diff(consumed.GetSubject(), produced.GetSubject()); d != "" { t.Errorf("args: diff(-want,+got):\n%s", d) } + // Coverage for GetSubjectContent + if d := cmp.Diff(consumed.GetSubjectContent(), produced.GetSubjectContent()); 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) diff --git a/pkg/api/v04/docs.go b/pkg/api/v04/docs.go index 15db905..92b703d 100644 --- a/pkg/api/v04/docs.go +++ b/pkg/api/v04/docs.go @@ -471,6 +471,15 @@ func NewTicketUpdatedEvent() (*TicketUpdatedEvent, error) { var TicketUpdatedEventType = api.TicketUpdatedEventTypeV0_1_0 +type CustomTypeEvent = api.CustomTypeEventV0_4_1 +type CustomTypeSubject = api.CustomTypeSubjectV0_4_1 + +func NewCustomTypeEvent() (*CustomTypeEvent, error) { + return api.NewCustomTypeEventV0_4_1(SpecVersion) +} + +var CustomTypeEventType = api.CustomTypeEventTypeV0_4_1 + // 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. diff --git a/pkg/api/v04/types.go b/pkg/api/v04/types.go index df1f3fe..4986db1 100644 --- a/pkg/api/v04/types.go +++ b/pkg/api/v04/types.go @@ -72,6 +72,7 @@ var CDEventsTypes = []api.CDEventV04{ &TicketClosedEvent{}, &TicketCreatedEvent{}, &TicketUpdatedEvent{}, + &CustomTypeEvent{}, } var CDEventsByUnversionedTypes map[string]api.CDEventV04 @@ -80,7 +81,11 @@ func init() { // Set up CDEventsByUnversionedTypes for convenience CDEventsByUnversionedTypes = make(map[string]api.CDEventV04) for _, event := range CDEventsTypes { - CDEventsByUnversionedTypes[event.GetType().UnversionedString()] = event + key := event.GetType().UnversionedString() + if event.GetType().Short() == "" { + key = api.CustomEventMapKey + } + CDEventsByUnversionedTypes[key] = event } } @@ -178,6 +183,8 @@ func NewCDEvent(eventType, specVersion string) (api.CDEvent, error) { return NewTicketCreatedEvent() case api.TicketUpdatedEventTypeV0_1_0.String(): return NewTicketUpdatedEvent() + case api.CustomTypeEventTypeV0_4_1.String(): + return NewCustomTypeEvent() 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 index 7a191d5..31b59b7 100644 --- a/pkg/api/v04/zz_examples_test.go +++ b/pkg/api/v04/zz_examples_test.go @@ -367,4 +367,11 @@ func init() { exampleTicketUpdatedEvent(newTicketUpdated) examplesProduced[newTicketUpdated.GetType().Short()] = newTicketUpdated + // CustomType Event producer + newCustomType, _ := specv04.NewCustomTypeEvent() + setContext(newCustomType, testSubjectId) + setContextV04(newCustomType, true, true) + exampleCustomTypeEvent(newCustomType) + examplesProduced[newCustomType.GetType().Short()] = newCustomType + } diff --git a/pkg/api/v04/zz_factory_test.go b/pkg/api/v04/zz_factory_test.go index c0c515d..66b755a 100644 --- a/pkg/api/v04/zz_factory_test.go +++ b/pkg/api/v04/zz_factory_test.go @@ -882,4 +882,23 @@ func init() { }, }, }) + tests = append(tests, testNewCDEventType{ + name: "custom type", + eventType: apiv04.CustomTypeEventType.String(), + expectedEvent: &apiv04.CustomTypeEvent{ + Context: api.ContextV04{ + Context: api.Context{ + Type: apiv04.CustomTypeEventType, + Timestamp: timeNow(), + Id: testUUID(), + Version: "0.4.1", + }, + }, + Subject: apiv04.CustomTypeSubject{ + SubjectBase: api.SubjectBase{ + Type: "", + }, + }, + }, + }) } diff --git a/pkg/api/v990/types.go b/pkg/api/v990/types.go index 6dfa657..ceb3d6a 100644 --- a/pkg/api/v990/types.go +++ b/pkg/api/v990/types.go @@ -38,7 +38,11 @@ func init() { // Set up CDEventsByUnversionedTypes for convenience CDEventsByUnversionedTypes = make(map[string]api.CDEventV04) for _, event := range CDEventsTypes { - CDEventsByUnversionedTypes[event.GetType().UnversionedString()] = event + key := event.GetType().UnversionedString() + if event.GetType().Short() == "" { + key = api.CustomEventMapKey + } + CDEventsByUnversionedTypes[key] = event } } diff --git a/pkg/api/v991/types.go b/pkg/api/v991/types.go index 715b996..d3a9b83 100644 --- a/pkg/api/v991/types.go +++ b/pkg/api/v991/types.go @@ -38,7 +38,11 @@ func init() { // Set up CDEventsByUnversionedTypes for convenience CDEventsByUnversionedTypes = make(map[string]api.CDEventV04) for _, event := range CDEventsTypes { - CDEventsByUnversionedTypes[event.GetType().UnversionedString()] = event + key := event.GetType().UnversionedString() + if event.GetType().Short() == "" { + key = api.CustomEventMapKey + } + CDEventsByUnversionedTypes[key] = event } } diff --git a/pkg/api/zz_artifactdeleted_0_1_0.go b/pkg/api/zz_artifactdeleted_0_1_0.go index 2340164..39073a4 100644 --- a/pkg/api/zz_artifactdeleted_0_1_0.go +++ b/pkg/api/zz_artifactdeleted_0_1_0.go @@ -61,7 +61,7 @@ func (e ArtifactDeletedEventV0_1_0) GetType() CDEventType { } func (e ArtifactDeletedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ArtifactDeletedEventV0_1_0) GetId() string { @@ -156,7 +156,7 @@ func (e *ArtifactDeletedEventV0_1_0) SetCustomData(contentType string, data inte func (e ArtifactDeletedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *ArtifactDeletedEventV0_1_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ArtifactDeletedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ArtifactDeletedEventV0_1_0) SetSubjectUser(user string) { diff --git a/pkg/api/zz_artifactdownloaded_0_1_0.go b/pkg/api/zz_artifactdownloaded_0_1_0.go index 87746f7..c9a7ce3 100644 --- a/pkg/api/zz_artifactdownloaded_0_1_0.go +++ b/pkg/api/zz_artifactdownloaded_0_1_0.go @@ -61,7 +61,7 @@ func (e ArtifactDownloadedEventV0_1_0) GetType() CDEventType { } func (e ArtifactDownloadedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ArtifactDownloadedEventV0_1_0) GetId() string { @@ -156,7 +156,7 @@ func (e *ArtifactDownloadedEventV0_1_0) SetCustomData(contentType string, data i func (e ArtifactDownloadedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *ArtifactDownloadedEventV0_1_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ArtifactDownloadedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ArtifactDownloadedEventV0_1_0) SetSubjectUser(user string) { diff --git a/pkg/api/zz_artifactpackaged_0_1_1.go b/pkg/api/zz_artifactpackaged_0_1_1.go index 2762da8..3748fae 100644 --- a/pkg/api/zz_artifactpackaged_0_1_1.go +++ b/pkg/api/zz_artifactpackaged_0_1_1.go @@ -61,7 +61,7 @@ func (e ArtifactPackagedEventV0_1_1) GetType() CDEventType { } func (e ArtifactPackagedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ArtifactPackagedEventV0_1_1) GetId() string { @@ -142,7 +142,11 @@ func (e *ArtifactPackagedEventV0_1_1) SetCustomData(contentType string, data int func (e ArtifactPackagedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ArtifactPackagedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_artifactpackaged_0_2_0.go b/pkg/api/zz_artifactpackaged_0_2_0.go index 5a21e3d..da556a1 100644 --- a/pkg/api/zz_artifactpackaged_0_2_0.go +++ b/pkg/api/zz_artifactpackaged_0_2_0.go @@ -63,7 +63,7 @@ func (e ArtifactPackagedEventV0_2_0) GetType() CDEventType { } func (e ArtifactPackagedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ArtifactPackagedEventV0_2_0) GetId() string { @@ -158,7 +158,7 @@ func (e *ArtifactPackagedEventV0_2_0) SetCustomData(contentType string, data int func (e ArtifactPackagedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -175,6 +175,10 @@ func (e *ArtifactPackagedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ArtifactPackagedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ArtifactPackagedEventV0_2_0) SetSubjectChange(change *Reference) { diff --git a/pkg/api/zz_artifactpublished_0_1_1.go b/pkg/api/zz_artifactpublished_0_1_1.go index 7e1e12e..8f8cba9 100644 --- a/pkg/api/zz_artifactpublished_0_1_1.go +++ b/pkg/api/zz_artifactpublished_0_1_1.go @@ -60,7 +60,7 @@ func (e ArtifactPublishedEventV0_1_1) GetType() CDEventType { } func (e ArtifactPublishedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ArtifactPublishedEventV0_1_1) GetId() string { @@ -141,10 +141,12 @@ func (e *ArtifactPublishedEventV0_1_1) SetCustomData(contentType string, data in func (e ArtifactPublishedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) } -// Set subject custom fields +func (e ArtifactPublishedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content +} // New creates a new ArtifactPublishedEventV0_1_1 func NewArtifactPublishedEventV0_1_1(specVersion string) (*ArtifactPublishedEventV0_1_1, error) { diff --git a/pkg/api/zz_artifactpublished_0_2_0.go b/pkg/api/zz_artifactpublished_0_2_0.go index bb13ebb..63acaae 100644 --- a/pkg/api/zz_artifactpublished_0_2_0.go +++ b/pkg/api/zz_artifactpublished_0_2_0.go @@ -63,7 +63,7 @@ func (e ArtifactPublishedEventV0_2_0) GetType() CDEventType { } func (e ArtifactPublishedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ArtifactPublishedEventV0_2_0) GetId() string { @@ -158,7 +158,7 @@ func (e *ArtifactPublishedEventV0_2_0) SetCustomData(contentType string, data in func (e ArtifactPublishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -175,6 +175,10 @@ func (e *ArtifactPublishedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ArtifactPublishedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ArtifactPublishedEventV0_2_0) SetSubjectSbom(sbom *ArtifactPublishedSubjectContentSbomV0_2_0) { diff --git a/pkg/api/zz_artifactsigned_0_1_0.go b/pkg/api/zz_artifactsigned_0_1_0.go index 9590543..f9932b8 100644 --- a/pkg/api/zz_artifactsigned_0_1_0.go +++ b/pkg/api/zz_artifactsigned_0_1_0.go @@ -61,7 +61,7 @@ func (e ArtifactSignedEventV0_1_0) GetType() CDEventType { } func (e ArtifactSignedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ArtifactSignedEventV0_1_0) GetId() string { @@ -142,7 +142,11 @@ func (e *ArtifactSignedEventV0_1_0) SetCustomData(contentType string, data inter func (e ArtifactSignedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ArtifactSignedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_artifactsigned_0_2_0.go b/pkg/api/zz_artifactsigned_0_2_0.go index d8ed4d2..ca58e8a 100644 --- a/pkg/api/zz_artifactsigned_0_2_0.go +++ b/pkg/api/zz_artifactsigned_0_2_0.go @@ -61,7 +61,7 @@ func (e ArtifactSignedEventV0_2_0) GetType() CDEventType { } func (e ArtifactSignedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ArtifactSignedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *ArtifactSignedEventV0_2_0) SetCustomData(contentType string, data inter func (e ArtifactSignedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *ArtifactSignedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ArtifactSignedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ArtifactSignedEventV0_2_0) SetSubjectSignature(signature string) { diff --git a/pkg/api/zz_branchcreated_0_1_2.go b/pkg/api/zz_branchcreated_0_1_2.go index 15a6886..213e20e 100644 --- a/pkg/api/zz_branchcreated_0_1_2.go +++ b/pkg/api/zz_branchcreated_0_1_2.go @@ -61,7 +61,7 @@ func (e BranchCreatedEventV0_1_2) GetType() CDEventType { } func (e BranchCreatedEventV0_1_2) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e BranchCreatedEventV0_1_2) GetId() string { @@ -142,7 +142,11 @@ func (e *BranchCreatedEventV0_1_2) SetCustomData(contentType string, data interf func (e BranchCreatedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e BranchCreatedEventV0_1_2) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_branchcreated_0_2_0.go b/pkg/api/zz_branchcreated_0_2_0.go index 2643b97..73b95f7 100644 --- a/pkg/api/zz_branchcreated_0_2_0.go +++ b/pkg/api/zz_branchcreated_0_2_0.go @@ -61,7 +61,7 @@ func (e BranchCreatedEventV0_2_0) GetType() CDEventType { } func (e BranchCreatedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e BranchCreatedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *BranchCreatedEventV0_2_0) SetCustomData(contentType string, data interf func (e BranchCreatedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *BranchCreatedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e BranchCreatedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *BranchCreatedEventV0_2_0) SetSubjectRepository(repository *Reference) { diff --git a/pkg/api/zz_branchdeleted_0_1_2.go b/pkg/api/zz_branchdeleted_0_1_2.go index 5edab79..81c9fc7 100644 --- a/pkg/api/zz_branchdeleted_0_1_2.go +++ b/pkg/api/zz_branchdeleted_0_1_2.go @@ -61,7 +61,7 @@ func (e BranchDeletedEventV0_1_2) GetType() CDEventType { } func (e BranchDeletedEventV0_1_2) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e BranchDeletedEventV0_1_2) GetId() string { @@ -142,7 +142,11 @@ func (e *BranchDeletedEventV0_1_2) SetCustomData(contentType string, data interf func (e BranchDeletedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e BranchDeletedEventV0_1_2) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_branchdeleted_0_2_0.go b/pkg/api/zz_branchdeleted_0_2_0.go index d504cf4..f3111d3 100644 --- a/pkg/api/zz_branchdeleted_0_2_0.go +++ b/pkg/api/zz_branchdeleted_0_2_0.go @@ -61,7 +61,7 @@ func (e BranchDeletedEventV0_2_0) GetType() CDEventType { } func (e BranchDeletedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e BranchDeletedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *BranchDeletedEventV0_2_0) SetCustomData(contentType string, data interf func (e BranchDeletedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *BranchDeletedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e BranchDeletedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *BranchDeletedEventV0_2_0) SetSubjectRepository(repository *Reference) { diff --git a/pkg/api/zz_buildfinished_0_1_1.go b/pkg/api/zz_buildfinished_0_1_1.go index fba172a..6c7ef43 100644 --- a/pkg/api/zz_buildfinished_0_1_1.go +++ b/pkg/api/zz_buildfinished_0_1_1.go @@ -61,7 +61,7 @@ func (e BuildFinishedEventV0_1_1) GetType() CDEventType { } func (e BuildFinishedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e BuildFinishedEventV0_1_1) GetId() string { @@ -142,7 +142,11 @@ func (e *BuildFinishedEventV0_1_1) SetCustomData(contentType string, data interf func (e BuildFinishedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e BuildFinishedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_buildfinished_0_2_0.go b/pkg/api/zz_buildfinished_0_2_0.go index 8825810..4723dcb 100644 --- a/pkg/api/zz_buildfinished_0_2_0.go +++ b/pkg/api/zz_buildfinished_0_2_0.go @@ -61,7 +61,7 @@ func (e BuildFinishedEventV0_2_0) GetType() CDEventType { } func (e BuildFinishedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e BuildFinishedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *BuildFinishedEventV0_2_0) SetCustomData(contentType string, data interf func (e BuildFinishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *BuildFinishedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e BuildFinishedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *BuildFinishedEventV0_2_0) SetSubjectArtifactId(artifactId string) { diff --git a/pkg/api/zz_buildqueued_0_1_1.go b/pkg/api/zz_buildqueued_0_1_1.go index 0ccaf1e..4ed3f12 100644 --- a/pkg/api/zz_buildqueued_0_1_1.go +++ b/pkg/api/zz_buildqueued_0_1_1.go @@ -60,7 +60,7 @@ func (e BuildQueuedEventV0_1_1) GetType() CDEventType { } func (e BuildQueuedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e BuildQueuedEventV0_1_1) GetId() string { @@ -141,10 +141,12 @@ func (e *BuildQueuedEventV0_1_1) SetCustomData(contentType string, data interfac func (e BuildQueuedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) } -// Set subject custom fields +func (e BuildQueuedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content +} // New creates a new BuildQueuedEventV0_1_1 func NewBuildQueuedEventV0_1_1(specVersion string) (*BuildQueuedEventV0_1_1, error) { diff --git a/pkg/api/zz_buildqueued_0_2_0.go b/pkg/api/zz_buildqueued_0_2_0.go index aa11196..7df434d 100644 --- a/pkg/api/zz_buildqueued_0_2_0.go +++ b/pkg/api/zz_buildqueued_0_2_0.go @@ -60,7 +60,7 @@ func (e BuildQueuedEventV0_2_0) GetType() CDEventType { } func (e BuildQueuedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e BuildQueuedEventV0_2_0) GetId() string { @@ -155,7 +155,7 @@ func (e *BuildQueuedEventV0_2_0) SetCustomData(contentType string, data interfac func (e BuildQueuedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -172,7 +172,9 @@ func (e *BuildQueuedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } -// Set subject custom fields +func (e BuildQueuedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} // New creates a new BuildQueuedEventV0_2_0 func NewBuildQueuedEventV0_2_0(specVersion string) (*BuildQueuedEventV0_2_0, error) { diff --git a/pkg/api/zz_buildstarted_0_1_1.go b/pkg/api/zz_buildstarted_0_1_1.go index 43636ea..460e0ca 100644 --- a/pkg/api/zz_buildstarted_0_1_1.go +++ b/pkg/api/zz_buildstarted_0_1_1.go @@ -60,7 +60,7 @@ func (e BuildStartedEventV0_1_1) GetType() CDEventType { } func (e BuildStartedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e BuildStartedEventV0_1_1) GetId() string { @@ -141,10 +141,12 @@ func (e *BuildStartedEventV0_1_1) SetCustomData(contentType string, data interfa func (e BuildStartedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) } -// Set subject custom fields +func (e BuildStartedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content +} // New creates a new BuildStartedEventV0_1_1 func NewBuildStartedEventV0_1_1(specVersion string) (*BuildStartedEventV0_1_1, error) { diff --git a/pkg/api/zz_buildstarted_0_2_0.go b/pkg/api/zz_buildstarted_0_2_0.go index 1c4bcc7..6e2b52b 100644 --- a/pkg/api/zz_buildstarted_0_2_0.go +++ b/pkg/api/zz_buildstarted_0_2_0.go @@ -60,7 +60,7 @@ func (e BuildStartedEventV0_2_0) GetType() CDEventType { } func (e BuildStartedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e BuildStartedEventV0_2_0) GetId() string { @@ -155,7 +155,7 @@ func (e *BuildStartedEventV0_2_0) SetCustomData(contentType string, data interfa func (e BuildStartedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -172,7 +172,9 @@ func (e *BuildStartedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } -// Set subject custom fields +func (e BuildStartedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} // New creates a new BuildStartedEventV0_2_0 func NewBuildStartedEventV0_2_0(specVersion string) (*BuildStartedEventV0_2_0, error) { diff --git a/pkg/api/zz_changeabandoned_0_1_2.go b/pkg/api/zz_changeabandoned_0_1_2.go index 9f0b0e8..301fff5 100644 --- a/pkg/api/zz_changeabandoned_0_1_2.go +++ b/pkg/api/zz_changeabandoned_0_1_2.go @@ -61,7 +61,7 @@ func (e ChangeAbandonedEventV0_1_2) GetType() CDEventType { } func (e ChangeAbandonedEventV0_1_2) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ChangeAbandonedEventV0_1_2) GetId() string { @@ -142,7 +142,11 @@ func (e *ChangeAbandonedEventV0_1_2) SetCustomData(contentType string, data inte func (e ChangeAbandonedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ChangeAbandonedEventV0_1_2) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_changeabandoned_0_2_0.go b/pkg/api/zz_changeabandoned_0_2_0.go index 15d4303..870ecdf 100644 --- a/pkg/api/zz_changeabandoned_0_2_0.go +++ b/pkg/api/zz_changeabandoned_0_2_0.go @@ -61,7 +61,7 @@ func (e ChangeAbandonedEventV0_2_0) GetType() CDEventType { } func (e ChangeAbandonedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ChangeAbandonedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *ChangeAbandonedEventV0_2_0) SetCustomData(contentType string, data inte func (e ChangeAbandonedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *ChangeAbandonedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ChangeAbandonedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ChangeAbandonedEventV0_2_0) SetSubjectRepository(repository *Reference) { diff --git a/pkg/api/zz_changecreated_0_1_2.go b/pkg/api/zz_changecreated_0_1_2.go index 486b379..ff65335 100644 --- a/pkg/api/zz_changecreated_0_1_2.go +++ b/pkg/api/zz_changecreated_0_1_2.go @@ -61,7 +61,7 @@ func (e ChangeCreatedEventV0_1_2) GetType() CDEventType { } func (e ChangeCreatedEventV0_1_2) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ChangeCreatedEventV0_1_2) GetId() string { @@ -142,7 +142,11 @@ func (e *ChangeCreatedEventV0_1_2) SetCustomData(contentType string, data interf func (e ChangeCreatedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ChangeCreatedEventV0_1_2) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_changecreated_0_3_0.go b/pkg/api/zz_changecreated_0_3_0.go index 649d58a..fd9f57b 100644 --- a/pkg/api/zz_changecreated_0_3_0.go +++ b/pkg/api/zz_changecreated_0_3_0.go @@ -63,7 +63,7 @@ func (e ChangeCreatedEventV0_3_0) GetType() CDEventType { } func (e ChangeCreatedEventV0_3_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ChangeCreatedEventV0_3_0) GetId() string { @@ -158,7 +158,7 @@ func (e *ChangeCreatedEventV0_3_0) SetCustomData(contentType string, data interf func (e ChangeCreatedEventV0_3_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -175,6 +175,10 @@ func (e *ChangeCreatedEventV0_3_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ChangeCreatedEventV0_3_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ChangeCreatedEventV0_3_0) SetSubjectDescription(description string) { diff --git a/pkg/api/zz_changemerged_0_1_2.go b/pkg/api/zz_changemerged_0_1_2.go index 67464e5..706f43a 100644 --- a/pkg/api/zz_changemerged_0_1_2.go +++ b/pkg/api/zz_changemerged_0_1_2.go @@ -61,7 +61,7 @@ func (e ChangeMergedEventV0_1_2) GetType() CDEventType { } func (e ChangeMergedEventV0_1_2) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ChangeMergedEventV0_1_2) GetId() string { @@ -142,7 +142,11 @@ func (e *ChangeMergedEventV0_1_2) SetCustomData(contentType string, data interfa func (e ChangeMergedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ChangeMergedEventV0_1_2) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_changemerged_0_2_0.go b/pkg/api/zz_changemerged_0_2_0.go index 385f586..9bce380 100644 --- a/pkg/api/zz_changemerged_0_2_0.go +++ b/pkg/api/zz_changemerged_0_2_0.go @@ -61,7 +61,7 @@ func (e ChangeMergedEventV0_2_0) GetType() CDEventType { } func (e ChangeMergedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ChangeMergedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *ChangeMergedEventV0_2_0) SetCustomData(contentType string, data interfa func (e ChangeMergedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *ChangeMergedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ChangeMergedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ChangeMergedEventV0_2_0) SetSubjectRepository(repository *Reference) { diff --git a/pkg/api/zz_changereviewed_0_1_2.go b/pkg/api/zz_changereviewed_0_1_2.go index 2d951c3..36bab51 100644 --- a/pkg/api/zz_changereviewed_0_1_2.go +++ b/pkg/api/zz_changereviewed_0_1_2.go @@ -61,7 +61,7 @@ func (e ChangeReviewedEventV0_1_2) GetType() CDEventType { } func (e ChangeReviewedEventV0_1_2) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ChangeReviewedEventV0_1_2) GetId() string { @@ -142,7 +142,11 @@ func (e *ChangeReviewedEventV0_1_2) SetCustomData(contentType string, data inter func (e ChangeReviewedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ChangeReviewedEventV0_1_2) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_changereviewed_0_2_0.go b/pkg/api/zz_changereviewed_0_2_0.go index 90a87e3..31b1c1f 100644 --- a/pkg/api/zz_changereviewed_0_2_0.go +++ b/pkg/api/zz_changereviewed_0_2_0.go @@ -61,7 +61,7 @@ func (e ChangeReviewedEventV0_2_0) GetType() CDEventType { } func (e ChangeReviewedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ChangeReviewedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *ChangeReviewedEventV0_2_0) SetCustomData(contentType string, data inter func (e ChangeReviewedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *ChangeReviewedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ChangeReviewedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ChangeReviewedEventV0_2_0) SetSubjectRepository(repository *Reference) { diff --git a/pkg/api/zz_changeupdated_0_1_2.go b/pkg/api/zz_changeupdated_0_1_2.go index f49b2c8..3b2d153 100644 --- a/pkg/api/zz_changeupdated_0_1_2.go +++ b/pkg/api/zz_changeupdated_0_1_2.go @@ -61,7 +61,7 @@ func (e ChangeUpdatedEventV0_1_2) GetType() CDEventType { } func (e ChangeUpdatedEventV0_1_2) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ChangeUpdatedEventV0_1_2) GetId() string { @@ -142,7 +142,11 @@ func (e *ChangeUpdatedEventV0_1_2) SetCustomData(contentType string, data interf func (e ChangeUpdatedEventV0_1_2) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ChangeUpdatedEventV0_1_2) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_changeupdated_0_2_0.go b/pkg/api/zz_changeupdated_0_2_0.go index 081fac1..7bc7466 100644 --- a/pkg/api/zz_changeupdated_0_2_0.go +++ b/pkg/api/zz_changeupdated_0_2_0.go @@ -61,7 +61,7 @@ func (e ChangeUpdatedEventV0_2_0) GetType() CDEventType { } func (e ChangeUpdatedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ChangeUpdatedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *ChangeUpdatedEventV0_2_0) SetCustomData(contentType string, data interf func (e ChangeUpdatedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *ChangeUpdatedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ChangeUpdatedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ChangeUpdatedEventV0_2_0) SetSubjectRepository(repository *Reference) { diff --git a/pkg/api/zz_customtype_0_4_1.go b/pkg/api/zz_customtype_0_4_1.go new file mode 100644 index 0000000..7d9a224 --- /dev/null +++ b/pkg/api/zz_customtype_0_4_1.go @@ -0,0 +1,206 @@ +// 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 ( + // CustomType event type v0.4.1 + CustomTypeEventTypeV0_4_1 CDEventType = CDEventType{} +) + +type CustomTypeSubjectV0_4_1 struct { + SubjectBase + Content interface{} `json:"content"` +} + +func (sc CustomTypeSubjectV0_4_1) GetSubjectType() SubjectType { + return sc.Type +} + +type CustomTypeEventV0_4_1 struct { + Context ContextV04 `json:"context"` + Subject CustomTypeSubjectV0_4_1 `json:"subject"` + CDEventCustomData +} + +// CDEventsReader implementation + +func (e CustomTypeEventV0_4_1) GetType() CDEventType { + return CustomTypeEventTypeV0_4_1 +} + +func (e CustomTypeEventV0_4_1) GetVersion() string { + return e.Context.GetVersion() +} + +func (e CustomTypeEventV0_4_1) GetId() string { + return e.Context.Id +} + +func (e CustomTypeEventV0_4_1) GetSource() string { + return e.Context.Source +} + +func (e CustomTypeEventV0_4_1) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e CustomTypeEventV0_4_1) GetSubjectId() string { + return e.Subject.Id +} + +func (e CustomTypeEventV0_4_1) GetSubjectSource() string { + return e.Subject.Source +} + +func (e CustomTypeEventV0_4_1) GetSubject() Subject { + return e.Subject +} + +func (e CustomTypeEventV0_4_1) GetCustomData() (interface{}, error) { + return GetCustomData(e.CustomDataContentType, e.CustomData) +} + +func (e CustomTypeEventV0_4_1) GetCustomDataAs(receiver interface{}) error { + return GetCustomDataAs(e, receiver) +} + +func (e CustomTypeEventV0_4_1) GetCustomDataRaw() ([]byte, error) { + return GetCustomDataRaw(e.CustomDataContentType, e.CustomData) +} + +func (e CustomTypeEventV0_4_1) GetCustomDataContentType() string { + return e.CustomDataContentType +} + +// CDEventsReaderV04 implementation + +func (e CustomTypeEventV0_4_1) GetChainId() string { + return e.Context.ChainId +} + +func (e CustomTypeEventV0_4_1) GetLinks() EmbeddedLinksArray { + return e.Context.Links +} + +func (e CustomTypeEventV0_4_1) GetSchemaUri() string { + return e.Context.SchemaUri +} + +// CDEventsWriter implementation + +func (e *CustomTypeEventV0_4_1) SetId(id string) { + e.Context.Id = id +} + +func (e *CustomTypeEventV0_4_1) 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 *CustomTypeEventV0_4_1) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *CustomTypeEventV0_4_1) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *CustomTypeEventV0_4_1) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func (e *CustomTypeEventV0_4_1) 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 CustomTypeEventV0_4_1) GetSchema() (string, *jsonschema.Schema, error) { + eType := e.GetType() + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) +} + +// CDEventsWriterV04 implementation + +func (e *CustomTypeEventV0_4_1) SetChainId(chainId string) { + e.Context.ChainId = chainId +} + +func (e *CustomTypeEventV0_4_1) SetLinks(links EmbeddedLinksArray) { + e.Context.Links = links +} + +func (e *CustomTypeEventV0_4_1) SetSchemaUri(schema string) { + e.Context.SchemaUri = schema +} + +func (e CustomTypeEventV0_4_1) GetSubjectContent() interface{} { + return e.Subject.Content +} + +// CustomCDEventWriter implementation + +func (e *CustomTypeEventV0_4_1) SetEventType(eventType CDEventType) { + e.Context.Type = eventType + e.Subject.Type = SubjectType(eventType.FQSubject()) +} + +// CustomCDEvent types can have different subject fields +func (e *CustomTypeEventV0_4_1) SetSubjectContent(subjectContent interface{}) { + e.Subject.Content = subjectContent +} + +// New creates a new CustomTypeEventV0_4_1 +func NewCustomTypeEventV0_4_1(specVersion string) (*CustomTypeEventV0_4_1, error) { + e := &CustomTypeEventV0_4_1{ + Context: ContextV04{ + Context{ + Type: CustomTypeEventTypeV0_4_1, + Version: specVersion, + }, + ContextLinks{}, + ContextCustom{}, + }, + Subject: CustomTypeSubjectV0_4_1{ + SubjectBase: SubjectBase{ + Type: "", + }, + }, + } + _, 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 9f110ef..d0a8263 100644 --- a/pkg/api/zz_environmentcreated_0_1_1.go +++ b/pkg/api/zz_environmentcreated_0_1_1.go @@ -63,7 +63,7 @@ func (e EnvironmentCreatedEventV0_1_1) GetType() CDEventType { } func (e EnvironmentCreatedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e EnvironmentCreatedEventV0_1_1) GetId() string { @@ -144,7 +144,11 @@ func (e *EnvironmentCreatedEventV0_1_1) SetCustomData(contentType string, data i func (e EnvironmentCreatedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e EnvironmentCreatedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_environmentcreated_0_2_0.go b/pkg/api/zz_environmentcreated_0_2_0.go index 22cd18f..b0fb0bc 100644 --- a/pkg/api/zz_environmentcreated_0_2_0.go +++ b/pkg/api/zz_environmentcreated_0_2_0.go @@ -63,7 +63,7 @@ func (e EnvironmentCreatedEventV0_2_0) GetType() CDEventType { } func (e EnvironmentCreatedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e EnvironmentCreatedEventV0_2_0) GetId() string { @@ -158,7 +158,7 @@ func (e *EnvironmentCreatedEventV0_2_0) SetCustomData(contentType string, data i func (e EnvironmentCreatedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -175,6 +175,10 @@ func (e *EnvironmentCreatedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e EnvironmentCreatedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *EnvironmentCreatedEventV0_2_0) SetSubjectName(name string) { diff --git a/pkg/api/zz_environmentdeleted_0_1_1.go b/pkg/api/zz_environmentdeleted_0_1_1.go index c1299ea..86ab794 100644 --- a/pkg/api/zz_environmentdeleted_0_1_1.go +++ b/pkg/api/zz_environmentdeleted_0_1_1.go @@ -61,7 +61,7 @@ func (e EnvironmentDeletedEventV0_1_1) GetType() CDEventType { } func (e EnvironmentDeletedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e EnvironmentDeletedEventV0_1_1) GetId() string { @@ -142,7 +142,11 @@ func (e *EnvironmentDeletedEventV0_1_1) SetCustomData(contentType string, data i func (e EnvironmentDeletedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e EnvironmentDeletedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_environmentdeleted_0_2_0.go b/pkg/api/zz_environmentdeleted_0_2_0.go index 12c2c44..56c1f8c 100644 --- a/pkg/api/zz_environmentdeleted_0_2_0.go +++ b/pkg/api/zz_environmentdeleted_0_2_0.go @@ -61,7 +61,7 @@ func (e EnvironmentDeletedEventV0_2_0) GetType() CDEventType { } func (e EnvironmentDeletedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e EnvironmentDeletedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *EnvironmentDeletedEventV0_2_0) SetCustomData(contentType string, data i func (e EnvironmentDeletedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *EnvironmentDeletedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e EnvironmentDeletedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *EnvironmentDeletedEventV0_2_0) SetSubjectName(name string) { diff --git a/pkg/api/zz_environmentmodified_0_1_1.go b/pkg/api/zz_environmentmodified_0_1_1.go index b94e791..aba1d0e 100644 --- a/pkg/api/zz_environmentmodified_0_1_1.go +++ b/pkg/api/zz_environmentmodified_0_1_1.go @@ -63,7 +63,7 @@ func (e EnvironmentModifiedEventV0_1_1) GetType() CDEventType { } func (e EnvironmentModifiedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e EnvironmentModifiedEventV0_1_1) GetId() string { @@ -144,7 +144,11 @@ func (e *EnvironmentModifiedEventV0_1_1) SetCustomData(contentType string, data func (e EnvironmentModifiedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e EnvironmentModifiedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_environmentmodified_0_2_0.go b/pkg/api/zz_environmentmodified_0_2_0.go index 90b0934..7bc152b 100644 --- a/pkg/api/zz_environmentmodified_0_2_0.go +++ b/pkg/api/zz_environmentmodified_0_2_0.go @@ -63,7 +63,7 @@ func (e EnvironmentModifiedEventV0_2_0) GetType() CDEventType { } func (e EnvironmentModifiedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e EnvironmentModifiedEventV0_2_0) GetId() string { @@ -158,7 +158,7 @@ func (e *EnvironmentModifiedEventV0_2_0) SetCustomData(contentType string, data func (e EnvironmentModifiedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -175,6 +175,10 @@ func (e *EnvironmentModifiedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e EnvironmentModifiedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *EnvironmentModifiedEventV0_2_0) SetSubjectName(name string) { diff --git a/pkg/api/zz_incidentdetected_0_1_0.go b/pkg/api/zz_incidentdetected_0_1_0.go index e13d70d..c404110 100644 --- a/pkg/api/zz_incidentdetected_0_1_0.go +++ b/pkg/api/zz_incidentdetected_0_1_0.go @@ -67,7 +67,7 @@ func (e IncidentDetectedEventV0_1_0) GetType() CDEventType { } func (e IncidentDetectedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e IncidentDetectedEventV0_1_0) GetId() string { @@ -148,7 +148,11 @@ func (e *IncidentDetectedEventV0_1_0) SetCustomData(contentType string, data int func (e IncidentDetectedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e IncidentDetectedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_incidentdetected_0_2_0.go b/pkg/api/zz_incidentdetected_0_2_0.go index ef41adf..6058b39 100644 --- a/pkg/api/zz_incidentdetected_0_2_0.go +++ b/pkg/api/zz_incidentdetected_0_2_0.go @@ -67,7 +67,7 @@ func (e IncidentDetectedEventV0_2_0) GetType() CDEventType { } func (e IncidentDetectedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e IncidentDetectedEventV0_2_0) GetId() string { @@ -162,7 +162,7 @@ func (e *IncidentDetectedEventV0_2_0) SetCustomData(contentType string, data int func (e IncidentDetectedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -179,6 +179,10 @@ func (e *IncidentDetectedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e IncidentDetectedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *IncidentDetectedEventV0_2_0) SetSubjectArtifactId(artifactId string) { diff --git a/pkg/api/zz_incidentreported_0_1_0.go b/pkg/api/zz_incidentreported_0_1_0.go index a3a4f23..035afdd 100644 --- a/pkg/api/zz_incidentreported_0_1_0.go +++ b/pkg/api/zz_incidentreported_0_1_0.go @@ -69,7 +69,7 @@ func (e IncidentReportedEventV0_1_0) GetType() CDEventType { } func (e IncidentReportedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e IncidentReportedEventV0_1_0) GetId() string { @@ -150,7 +150,11 @@ func (e *IncidentReportedEventV0_1_0) SetCustomData(contentType string, data int func (e IncidentReportedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e IncidentReportedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_incidentreported_0_2_0.go b/pkg/api/zz_incidentreported_0_2_0.go index ca0f1d6..38dd7ec 100644 --- a/pkg/api/zz_incidentreported_0_2_0.go +++ b/pkg/api/zz_incidentreported_0_2_0.go @@ -69,7 +69,7 @@ func (e IncidentReportedEventV0_2_0) GetType() CDEventType { } func (e IncidentReportedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e IncidentReportedEventV0_2_0) GetId() string { @@ -164,7 +164,7 @@ func (e *IncidentReportedEventV0_2_0) SetCustomData(contentType string, data int func (e IncidentReportedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -181,6 +181,10 @@ func (e *IncidentReportedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e IncidentReportedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *IncidentReportedEventV0_2_0) SetSubjectArtifactId(artifactId string) { diff --git a/pkg/api/zz_incidentresolved_0_1_0.go b/pkg/api/zz_incidentresolved_0_1_0.go index 96a7d0b..1d679de 100644 --- a/pkg/api/zz_incidentresolved_0_1_0.go +++ b/pkg/api/zz_incidentresolved_0_1_0.go @@ -67,7 +67,7 @@ func (e IncidentResolvedEventV0_1_0) GetType() CDEventType { } func (e IncidentResolvedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e IncidentResolvedEventV0_1_0) GetId() string { @@ -148,7 +148,11 @@ func (e *IncidentResolvedEventV0_1_0) SetCustomData(contentType string, data int func (e IncidentResolvedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e IncidentResolvedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_incidentresolved_0_2_0.go b/pkg/api/zz_incidentresolved_0_2_0.go index 72189e4..272ec7f 100644 --- a/pkg/api/zz_incidentresolved_0_2_0.go +++ b/pkg/api/zz_incidentresolved_0_2_0.go @@ -67,7 +67,7 @@ func (e IncidentResolvedEventV0_2_0) GetType() CDEventType { } func (e IncidentResolvedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e IncidentResolvedEventV0_2_0) GetId() string { @@ -162,7 +162,7 @@ func (e *IncidentResolvedEventV0_2_0) SetCustomData(contentType string, data int func (e IncidentResolvedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -179,6 +179,10 @@ func (e *IncidentResolvedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e IncidentResolvedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *IncidentResolvedEventV0_2_0) SetSubjectArtifactId(artifactId string) { diff --git a/pkg/api/zz_pipelinerunfinished_0_1_1.go b/pkg/api/zz_pipelinerunfinished_0_1_1.go index 422eb04..1ba279d 100644 --- a/pkg/api/zz_pipelinerunfinished_0_1_1.go +++ b/pkg/api/zz_pipelinerunfinished_0_1_1.go @@ -67,7 +67,7 @@ func (e PipelineRunFinishedEventV0_1_1) GetType() CDEventType { } func (e PipelineRunFinishedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e PipelineRunFinishedEventV0_1_1) GetId() string { @@ -148,7 +148,11 @@ func (e *PipelineRunFinishedEventV0_1_1) SetCustomData(contentType string, data func (e PipelineRunFinishedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e PipelineRunFinishedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_pipelinerunfinished_0_2_0.go b/pkg/api/zz_pipelinerunfinished_0_2_0.go index 8a3a59f..55dc854 100644 --- a/pkg/api/zz_pipelinerunfinished_0_2_0.go +++ b/pkg/api/zz_pipelinerunfinished_0_2_0.go @@ -67,7 +67,7 @@ func (e PipelineRunFinishedEventV0_2_0) GetType() CDEventType { } func (e PipelineRunFinishedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e PipelineRunFinishedEventV0_2_0) GetId() string { @@ -162,7 +162,7 @@ func (e *PipelineRunFinishedEventV0_2_0) SetCustomData(contentType string, data func (e PipelineRunFinishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -179,6 +179,10 @@ func (e *PipelineRunFinishedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e PipelineRunFinishedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *PipelineRunFinishedEventV0_2_0) SetSubjectErrors(errors string) { diff --git a/pkg/api/zz_pipelinerunqueued_0_1_1.go b/pkg/api/zz_pipelinerunqueued_0_1_1.go index 434bfad..0fd4664 100644 --- a/pkg/api/zz_pipelinerunqueued_0_1_1.go +++ b/pkg/api/zz_pipelinerunqueued_0_1_1.go @@ -63,7 +63,7 @@ func (e PipelineRunQueuedEventV0_1_1) GetType() CDEventType { } func (e PipelineRunQueuedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e PipelineRunQueuedEventV0_1_1) GetId() string { @@ -144,7 +144,11 @@ func (e *PipelineRunQueuedEventV0_1_1) SetCustomData(contentType string, data in func (e PipelineRunQueuedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e PipelineRunQueuedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_pipelinerunqueued_0_2_0.go b/pkg/api/zz_pipelinerunqueued_0_2_0.go index b24e144..8f581f1 100644 --- a/pkg/api/zz_pipelinerunqueued_0_2_0.go +++ b/pkg/api/zz_pipelinerunqueued_0_2_0.go @@ -63,7 +63,7 @@ func (e PipelineRunQueuedEventV0_2_0) GetType() CDEventType { } func (e PipelineRunQueuedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e PipelineRunQueuedEventV0_2_0) GetId() string { @@ -158,7 +158,7 @@ func (e *PipelineRunQueuedEventV0_2_0) SetCustomData(contentType string, data in func (e PipelineRunQueuedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -175,6 +175,10 @@ func (e *PipelineRunQueuedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e PipelineRunQueuedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *PipelineRunQueuedEventV0_2_0) SetSubjectPipelineName(pipelineName string) { diff --git a/pkg/api/zz_pipelinerunstarted_0_1_1.go b/pkg/api/zz_pipelinerunstarted_0_1_1.go index 842d1e8..024277c 100644 --- a/pkg/api/zz_pipelinerunstarted_0_1_1.go +++ b/pkg/api/zz_pipelinerunstarted_0_1_1.go @@ -63,7 +63,7 @@ func (e PipelineRunStartedEventV0_1_1) GetType() CDEventType { } func (e PipelineRunStartedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e PipelineRunStartedEventV0_1_1) GetId() string { @@ -144,7 +144,11 @@ func (e *PipelineRunStartedEventV0_1_1) SetCustomData(contentType string, data i func (e PipelineRunStartedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e PipelineRunStartedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_pipelinerunstarted_0_2_0.go b/pkg/api/zz_pipelinerunstarted_0_2_0.go index 46703c5..71dd2c5 100644 --- a/pkg/api/zz_pipelinerunstarted_0_2_0.go +++ b/pkg/api/zz_pipelinerunstarted_0_2_0.go @@ -63,7 +63,7 @@ func (e PipelineRunStartedEventV0_2_0) GetType() CDEventType { } func (e PipelineRunStartedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e PipelineRunStartedEventV0_2_0) GetId() string { @@ -158,7 +158,7 @@ func (e *PipelineRunStartedEventV0_2_0) SetCustomData(contentType string, data i func (e PipelineRunStartedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -175,6 +175,10 @@ func (e *PipelineRunStartedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e PipelineRunStartedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *PipelineRunStartedEventV0_2_0) SetSubjectPipelineName(pipelineName string) { diff --git a/pkg/api/zz_repositorycreated_0_1_1.go b/pkg/api/zz_repositorycreated_0_1_1.go index 32ef75c..4ba57c5 100644 --- a/pkg/api/zz_repositorycreated_0_1_1.go +++ b/pkg/api/zz_repositorycreated_0_1_1.go @@ -67,7 +67,7 @@ func (e RepositoryCreatedEventV0_1_1) GetType() CDEventType { } func (e RepositoryCreatedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e RepositoryCreatedEventV0_1_1) GetId() string { @@ -148,7 +148,11 @@ func (e *RepositoryCreatedEventV0_1_1) SetCustomData(contentType string, data in func (e RepositoryCreatedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e RepositoryCreatedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_repositorycreated_0_2_0.go b/pkg/api/zz_repositorycreated_0_2_0.go index 9c04633..86f8e71 100644 --- a/pkg/api/zz_repositorycreated_0_2_0.go +++ b/pkg/api/zz_repositorycreated_0_2_0.go @@ -67,7 +67,7 @@ func (e RepositoryCreatedEventV0_2_0) GetType() CDEventType { } func (e RepositoryCreatedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e RepositoryCreatedEventV0_2_0) GetId() string { @@ -162,7 +162,7 @@ func (e *RepositoryCreatedEventV0_2_0) SetCustomData(contentType string, data in func (e RepositoryCreatedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -179,6 +179,10 @@ func (e *RepositoryCreatedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e RepositoryCreatedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *RepositoryCreatedEventV0_2_0) SetSubjectName(name string) { diff --git a/pkg/api/zz_repositorydeleted_0_1_1.go b/pkg/api/zz_repositorydeleted_0_1_1.go index acf1d41..f481f07 100644 --- a/pkg/api/zz_repositorydeleted_0_1_1.go +++ b/pkg/api/zz_repositorydeleted_0_1_1.go @@ -67,7 +67,7 @@ func (e RepositoryDeletedEventV0_1_1) GetType() CDEventType { } func (e RepositoryDeletedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e RepositoryDeletedEventV0_1_1) GetId() string { @@ -148,7 +148,11 @@ func (e *RepositoryDeletedEventV0_1_1) SetCustomData(contentType string, data in func (e RepositoryDeletedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e RepositoryDeletedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_repositorydeleted_0_2_0.go b/pkg/api/zz_repositorydeleted_0_2_0.go index ac700f8..3b544db 100644 --- a/pkg/api/zz_repositorydeleted_0_2_0.go +++ b/pkg/api/zz_repositorydeleted_0_2_0.go @@ -67,7 +67,7 @@ func (e RepositoryDeletedEventV0_2_0) GetType() CDEventType { } func (e RepositoryDeletedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e RepositoryDeletedEventV0_2_0) GetId() string { @@ -162,7 +162,7 @@ func (e *RepositoryDeletedEventV0_2_0) SetCustomData(contentType string, data in func (e RepositoryDeletedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -179,6 +179,10 @@ func (e *RepositoryDeletedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e RepositoryDeletedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *RepositoryDeletedEventV0_2_0) SetSubjectName(name string) { diff --git a/pkg/api/zz_repositorymodified_0_1_1.go b/pkg/api/zz_repositorymodified_0_1_1.go index 6d902de..30aa6c3 100644 --- a/pkg/api/zz_repositorymodified_0_1_1.go +++ b/pkg/api/zz_repositorymodified_0_1_1.go @@ -67,7 +67,7 @@ func (e RepositoryModifiedEventV0_1_1) GetType() CDEventType { } func (e RepositoryModifiedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e RepositoryModifiedEventV0_1_1) GetId() string { @@ -148,7 +148,11 @@ func (e *RepositoryModifiedEventV0_1_1) SetCustomData(contentType string, data i func (e RepositoryModifiedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e RepositoryModifiedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_repositorymodified_0_2_0.go b/pkg/api/zz_repositorymodified_0_2_0.go index 411211c..1c2cdeb 100644 --- a/pkg/api/zz_repositorymodified_0_2_0.go +++ b/pkg/api/zz_repositorymodified_0_2_0.go @@ -67,7 +67,7 @@ func (e RepositoryModifiedEventV0_2_0) GetType() CDEventType { } func (e RepositoryModifiedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e RepositoryModifiedEventV0_2_0) GetId() string { @@ -162,7 +162,7 @@ func (e *RepositoryModifiedEventV0_2_0) SetCustomData(contentType string, data i func (e RepositoryModifiedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -179,6 +179,10 @@ func (e *RepositoryModifiedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e RepositoryModifiedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *RepositoryModifiedEventV0_2_0) SetSubjectName(name string) { diff --git a/pkg/api/zz_servicedeployed_0_1_1.go b/pkg/api/zz_servicedeployed_0_1_1.go index 0d14fc3..1a8a2ab 100644 --- a/pkg/api/zz_servicedeployed_0_1_1.go +++ b/pkg/api/zz_servicedeployed_0_1_1.go @@ -63,7 +63,7 @@ func (e ServiceDeployedEventV0_1_1) GetType() CDEventType { } func (e ServiceDeployedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ServiceDeployedEventV0_1_1) GetId() string { @@ -144,7 +144,11 @@ func (e *ServiceDeployedEventV0_1_1) SetCustomData(contentType string, data inte func (e ServiceDeployedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ServiceDeployedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_servicedeployed_0_2_0.go b/pkg/api/zz_servicedeployed_0_2_0.go index e7c1a75..681a6fb 100644 --- a/pkg/api/zz_servicedeployed_0_2_0.go +++ b/pkg/api/zz_servicedeployed_0_2_0.go @@ -63,7 +63,7 @@ func (e ServiceDeployedEventV0_2_0) GetType() CDEventType { } func (e ServiceDeployedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ServiceDeployedEventV0_2_0) GetId() string { @@ -158,7 +158,7 @@ func (e *ServiceDeployedEventV0_2_0) SetCustomData(contentType string, data inte func (e ServiceDeployedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -175,6 +175,10 @@ func (e *ServiceDeployedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ServiceDeployedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ServiceDeployedEventV0_2_0) SetSubjectArtifactId(artifactId string) { diff --git a/pkg/api/zz_servicepublished_0_1_1.go b/pkg/api/zz_servicepublished_0_1_1.go index a1483b2..c46b255 100644 --- a/pkg/api/zz_servicepublished_0_1_1.go +++ b/pkg/api/zz_servicepublished_0_1_1.go @@ -61,7 +61,7 @@ func (e ServicePublishedEventV0_1_1) GetType() CDEventType { } func (e ServicePublishedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ServicePublishedEventV0_1_1) GetId() string { @@ -142,7 +142,11 @@ func (e *ServicePublishedEventV0_1_1) SetCustomData(contentType string, data int func (e ServicePublishedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ServicePublishedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_servicepublished_0_2_0.go b/pkg/api/zz_servicepublished_0_2_0.go index 81c88b6..48b1770 100644 --- a/pkg/api/zz_servicepublished_0_2_0.go +++ b/pkg/api/zz_servicepublished_0_2_0.go @@ -61,7 +61,7 @@ func (e ServicePublishedEventV0_2_0) GetType() CDEventType { } func (e ServicePublishedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ServicePublishedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *ServicePublishedEventV0_2_0) SetCustomData(contentType string, data int func (e ServicePublishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *ServicePublishedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ServicePublishedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ServicePublishedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { diff --git a/pkg/api/zz_serviceremoved_0_1_1.go b/pkg/api/zz_serviceremoved_0_1_1.go index 7292271..95286bd 100644 --- a/pkg/api/zz_serviceremoved_0_1_1.go +++ b/pkg/api/zz_serviceremoved_0_1_1.go @@ -61,7 +61,7 @@ func (e ServiceRemovedEventV0_1_1) GetType() CDEventType { } func (e ServiceRemovedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ServiceRemovedEventV0_1_1) GetId() string { @@ -142,7 +142,11 @@ func (e *ServiceRemovedEventV0_1_1) SetCustomData(contentType string, data inter func (e ServiceRemovedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ServiceRemovedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_serviceremoved_0_2_0.go b/pkg/api/zz_serviceremoved_0_2_0.go index 82d6021..e4e4d66 100644 --- a/pkg/api/zz_serviceremoved_0_2_0.go +++ b/pkg/api/zz_serviceremoved_0_2_0.go @@ -61,7 +61,7 @@ func (e ServiceRemovedEventV0_2_0) GetType() CDEventType { } func (e ServiceRemovedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ServiceRemovedEventV0_2_0) GetId() string { @@ -156,7 +156,7 @@ func (e *ServiceRemovedEventV0_2_0) SetCustomData(contentType string, data inter func (e ServiceRemovedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -173,6 +173,10 @@ func (e *ServiceRemovedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ServiceRemovedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ServiceRemovedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { diff --git a/pkg/api/zz_servicerolledback_0_1_1.go b/pkg/api/zz_servicerolledback_0_1_1.go index 0d0106f..54f76df 100644 --- a/pkg/api/zz_servicerolledback_0_1_1.go +++ b/pkg/api/zz_servicerolledback_0_1_1.go @@ -63,7 +63,7 @@ func (e ServiceRolledbackEventV0_1_1) GetType() CDEventType { } func (e ServiceRolledbackEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ServiceRolledbackEventV0_1_1) GetId() string { @@ -144,7 +144,11 @@ func (e *ServiceRolledbackEventV0_1_1) SetCustomData(contentType string, data in func (e ServiceRolledbackEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ServiceRolledbackEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_servicerolledback_0_2_0.go b/pkg/api/zz_servicerolledback_0_2_0.go index cf3865f..cab8087 100644 --- a/pkg/api/zz_servicerolledback_0_2_0.go +++ b/pkg/api/zz_servicerolledback_0_2_0.go @@ -63,7 +63,7 @@ func (e ServiceRolledbackEventV0_2_0) GetType() CDEventType { } func (e ServiceRolledbackEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ServiceRolledbackEventV0_2_0) GetId() string { @@ -158,7 +158,7 @@ func (e *ServiceRolledbackEventV0_2_0) SetCustomData(contentType string, data in func (e ServiceRolledbackEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -175,6 +175,10 @@ func (e *ServiceRolledbackEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ServiceRolledbackEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ServiceRolledbackEventV0_2_0) SetSubjectArtifactId(artifactId string) { diff --git a/pkg/api/zz_serviceupgraded_0_1_1.go b/pkg/api/zz_serviceupgraded_0_1_1.go index 8ad1013..97b7c33 100644 --- a/pkg/api/zz_serviceupgraded_0_1_1.go +++ b/pkg/api/zz_serviceupgraded_0_1_1.go @@ -63,7 +63,7 @@ func (e ServiceUpgradedEventV0_1_1) GetType() CDEventType { } func (e ServiceUpgradedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ServiceUpgradedEventV0_1_1) GetId() string { @@ -144,7 +144,11 @@ func (e *ServiceUpgradedEventV0_1_1) SetCustomData(contentType string, data inte func (e ServiceUpgradedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e ServiceUpgradedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_serviceupgraded_0_2_0.go b/pkg/api/zz_serviceupgraded_0_2_0.go index 2cabff0..e191886 100644 --- a/pkg/api/zz_serviceupgraded_0_2_0.go +++ b/pkg/api/zz_serviceupgraded_0_2_0.go @@ -63,7 +63,7 @@ func (e ServiceUpgradedEventV0_2_0) GetType() CDEventType { } func (e ServiceUpgradedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e ServiceUpgradedEventV0_2_0) GetId() string { @@ -158,7 +158,7 @@ func (e *ServiceUpgradedEventV0_2_0) SetCustomData(contentType string, data inte func (e ServiceUpgradedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -175,6 +175,10 @@ func (e *ServiceUpgradedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e ServiceUpgradedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *ServiceUpgradedEventV0_2_0) SetSubjectArtifactId(artifactId string) { diff --git a/pkg/api/zz_taskrunfinished_0_1_1.go b/pkg/api/zz_taskrunfinished_0_1_1.go index fb3eaf8..aa47e64 100644 --- a/pkg/api/zz_taskrunfinished_0_1_1.go +++ b/pkg/api/zz_taskrunfinished_0_1_1.go @@ -69,7 +69,7 @@ func (e TaskRunFinishedEventV0_1_1) GetType() CDEventType { } func (e TaskRunFinishedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TaskRunFinishedEventV0_1_1) GetId() string { @@ -150,7 +150,11 @@ func (e *TaskRunFinishedEventV0_1_1) SetCustomData(contentType string, data inte func (e TaskRunFinishedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e TaskRunFinishedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_taskrunfinished_0_2_0.go b/pkg/api/zz_taskrunfinished_0_2_0.go index 2d5e380..368c684 100644 --- a/pkg/api/zz_taskrunfinished_0_2_0.go +++ b/pkg/api/zz_taskrunfinished_0_2_0.go @@ -69,7 +69,7 @@ func (e TaskRunFinishedEventV0_2_0) GetType() CDEventType { } func (e TaskRunFinishedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TaskRunFinishedEventV0_2_0) GetId() string { @@ -164,7 +164,7 @@ func (e *TaskRunFinishedEventV0_2_0) SetCustomData(contentType string, data inte func (e TaskRunFinishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -181,6 +181,10 @@ func (e *TaskRunFinishedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TaskRunFinishedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TaskRunFinishedEventV0_2_0) SetSubjectErrors(errors string) { diff --git a/pkg/api/zz_taskrunstarted_0_1_1.go b/pkg/api/zz_taskrunstarted_0_1_1.go index 570a77b..3d0612c 100644 --- a/pkg/api/zz_taskrunstarted_0_1_1.go +++ b/pkg/api/zz_taskrunstarted_0_1_1.go @@ -65,7 +65,7 @@ func (e TaskRunStartedEventV0_1_1) GetType() CDEventType { } func (e TaskRunStartedEventV0_1_1) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TaskRunStartedEventV0_1_1) GetId() string { @@ -146,7 +146,11 @@ func (e *TaskRunStartedEventV0_1_1) SetCustomData(contentType string, data inter func (e TaskRunStartedEventV0_1_1) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e TaskRunStartedEventV0_1_1) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_taskrunstarted_0_2_0.go b/pkg/api/zz_taskrunstarted_0_2_0.go index 5df39c7..58f6752 100644 --- a/pkg/api/zz_taskrunstarted_0_2_0.go +++ b/pkg/api/zz_taskrunstarted_0_2_0.go @@ -65,7 +65,7 @@ func (e TaskRunStartedEventV0_2_0) GetType() CDEventType { } func (e TaskRunStartedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TaskRunStartedEventV0_2_0) GetId() string { @@ -160,7 +160,7 @@ func (e *TaskRunStartedEventV0_2_0) SetCustomData(contentType string, data inter func (e TaskRunStartedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -177,6 +177,10 @@ func (e *TaskRunStartedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TaskRunStartedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TaskRunStartedEventV0_2_0) SetSubjectPipelineRun(pipelineRun *Reference) { diff --git a/pkg/api/zz_testcaserunfinished_0_1_0.go b/pkg/api/zz_testcaserunfinished_0_1_0.go index 43bd44b..6cf0c38 100644 --- a/pkg/api/zz_testcaserunfinished_0_1_0.go +++ b/pkg/api/zz_testcaserunfinished_0_1_0.go @@ -71,7 +71,7 @@ func (e TestCaseRunFinishedEventV0_1_0) GetType() CDEventType { } func (e TestCaseRunFinishedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestCaseRunFinishedEventV0_1_0) GetId() string { @@ -152,7 +152,11 @@ func (e *TestCaseRunFinishedEventV0_1_0) SetCustomData(contentType string, data func (e TestCaseRunFinishedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e TestCaseRunFinishedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_testcaserunfinished_0_2_0.go b/pkg/api/zz_testcaserunfinished_0_2_0.go index 2232257..2f0fdcf 100644 --- a/pkg/api/zz_testcaserunfinished_0_2_0.go +++ b/pkg/api/zz_testcaserunfinished_0_2_0.go @@ -71,7 +71,7 @@ func (e TestCaseRunFinishedEventV0_2_0) GetType() CDEventType { } func (e TestCaseRunFinishedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestCaseRunFinishedEventV0_2_0) GetId() string { @@ -166,7 +166,7 @@ func (e *TestCaseRunFinishedEventV0_2_0) SetCustomData(contentType string, data func (e TestCaseRunFinishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -183,6 +183,10 @@ func (e *TestCaseRunFinishedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TestCaseRunFinishedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TestCaseRunFinishedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { diff --git a/pkg/api/zz_testcaserunqueued_0_1_0.go b/pkg/api/zz_testcaserunqueued_0_1_0.go index 70a564a..1abff5e 100644 --- a/pkg/api/zz_testcaserunqueued_0_1_0.go +++ b/pkg/api/zz_testcaserunqueued_0_1_0.go @@ -67,7 +67,7 @@ func (e TestCaseRunQueuedEventV0_1_0) GetType() CDEventType { } func (e TestCaseRunQueuedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestCaseRunQueuedEventV0_1_0) GetId() string { @@ -148,7 +148,11 @@ func (e *TestCaseRunQueuedEventV0_1_0) SetCustomData(contentType string, data in func (e TestCaseRunQueuedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e TestCaseRunQueuedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_testcaserunqueued_0_2_0.go b/pkg/api/zz_testcaserunqueued_0_2_0.go index fe5d978..bffaf82 100644 --- a/pkg/api/zz_testcaserunqueued_0_2_0.go +++ b/pkg/api/zz_testcaserunqueued_0_2_0.go @@ -67,7 +67,7 @@ func (e TestCaseRunQueuedEventV0_2_0) GetType() CDEventType { } func (e TestCaseRunQueuedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestCaseRunQueuedEventV0_2_0) GetId() string { @@ -162,7 +162,7 @@ func (e *TestCaseRunQueuedEventV0_2_0) SetCustomData(contentType string, data in func (e TestCaseRunQueuedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -179,6 +179,10 @@ func (e *TestCaseRunQueuedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TestCaseRunQueuedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TestCaseRunQueuedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { diff --git a/pkg/api/zz_testcaserunskipped_0_1_0.go b/pkg/api/zz_testcaserunskipped_0_1_0.go index 166f349..3173897 100644 --- a/pkg/api/zz_testcaserunskipped_0_1_0.go +++ b/pkg/api/zz_testcaserunskipped_0_1_0.go @@ -67,7 +67,7 @@ func (e TestCaseRunSkippedEventV0_1_0) GetType() CDEventType { } func (e TestCaseRunSkippedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestCaseRunSkippedEventV0_1_0) GetId() string { @@ -162,7 +162,7 @@ func (e *TestCaseRunSkippedEventV0_1_0) SetCustomData(contentType string, data i func (e TestCaseRunSkippedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -179,6 +179,10 @@ func (e *TestCaseRunSkippedEventV0_1_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TestCaseRunSkippedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TestCaseRunSkippedEventV0_1_0) SetSubjectEnvironment(environment *Reference) { diff --git a/pkg/api/zz_testcaserunstarted_0_1_0.go b/pkg/api/zz_testcaserunstarted_0_1_0.go index d0e748f..2382042 100644 --- a/pkg/api/zz_testcaserunstarted_0_1_0.go +++ b/pkg/api/zz_testcaserunstarted_0_1_0.go @@ -67,7 +67,7 @@ func (e TestCaseRunStartedEventV0_1_0) GetType() CDEventType { } func (e TestCaseRunStartedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestCaseRunStartedEventV0_1_0) GetId() string { @@ -148,7 +148,11 @@ func (e *TestCaseRunStartedEventV0_1_0) SetCustomData(contentType string, data i func (e TestCaseRunStartedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e TestCaseRunStartedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_testcaserunstarted_0_2_0.go b/pkg/api/zz_testcaserunstarted_0_2_0.go index 87832fe..dd9e91c 100644 --- a/pkg/api/zz_testcaserunstarted_0_2_0.go +++ b/pkg/api/zz_testcaserunstarted_0_2_0.go @@ -67,7 +67,7 @@ func (e TestCaseRunStartedEventV0_2_0) GetType() CDEventType { } func (e TestCaseRunStartedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestCaseRunStartedEventV0_2_0) GetId() string { @@ -162,7 +162,7 @@ func (e *TestCaseRunStartedEventV0_2_0) SetCustomData(contentType string, data i func (e TestCaseRunStartedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -179,6 +179,10 @@ func (e *TestCaseRunStartedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TestCaseRunStartedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TestCaseRunStartedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { diff --git a/pkg/api/zz_testoutputpublished_0_1_0.go b/pkg/api/zz_testoutputpublished_0_1_0.go index 1ba1f8a..6499f9c 100644 --- a/pkg/api/zz_testoutputpublished_0_1_0.go +++ b/pkg/api/zz_testoutputpublished_0_1_0.go @@ -67,7 +67,7 @@ func (e TestOutputPublishedEventV0_1_0) GetType() CDEventType { } func (e TestOutputPublishedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestOutputPublishedEventV0_1_0) GetId() string { @@ -148,7 +148,11 @@ func (e *TestOutputPublishedEventV0_1_0) SetCustomData(contentType string, data func (e TestOutputPublishedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e TestOutputPublishedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_testoutputpublished_0_2_0.go b/pkg/api/zz_testoutputpublished_0_2_0.go index d508352..e34aad1 100644 --- a/pkg/api/zz_testoutputpublished_0_2_0.go +++ b/pkg/api/zz_testoutputpublished_0_2_0.go @@ -67,7 +67,7 @@ func (e TestOutputPublishedEventV0_2_0) GetType() CDEventType { } func (e TestOutputPublishedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestOutputPublishedEventV0_2_0) GetId() string { @@ -162,7 +162,7 @@ func (e *TestOutputPublishedEventV0_2_0) SetCustomData(contentType string, data func (e TestOutputPublishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -179,6 +179,10 @@ func (e *TestOutputPublishedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TestOutputPublishedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TestOutputPublishedEventV0_2_0) SetSubjectFormat(format string) { diff --git a/pkg/api/zz_testsuiterunfinished_0_1_0.go b/pkg/api/zz_testsuiterunfinished_0_1_0.go index aea7ea5..bee8bf4 100644 --- a/pkg/api/zz_testsuiterunfinished_0_1_0.go +++ b/pkg/api/zz_testsuiterunfinished_0_1_0.go @@ -69,7 +69,7 @@ func (e TestSuiteRunFinishedEventV0_1_0) GetType() CDEventType { } func (e TestSuiteRunFinishedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestSuiteRunFinishedEventV0_1_0) GetId() string { @@ -150,7 +150,11 @@ func (e *TestSuiteRunFinishedEventV0_1_0) SetCustomData(contentType string, data func (e TestSuiteRunFinishedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e TestSuiteRunFinishedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_testsuiterunfinished_0_2_0.go b/pkg/api/zz_testsuiterunfinished_0_2_0.go index 70ed2e2..48c42d7 100644 --- a/pkg/api/zz_testsuiterunfinished_0_2_0.go +++ b/pkg/api/zz_testsuiterunfinished_0_2_0.go @@ -69,7 +69,7 @@ func (e TestSuiteRunFinishedEventV0_2_0) GetType() CDEventType { } func (e TestSuiteRunFinishedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestSuiteRunFinishedEventV0_2_0) GetId() string { @@ -164,7 +164,7 @@ func (e *TestSuiteRunFinishedEventV0_2_0) SetCustomData(contentType string, data func (e TestSuiteRunFinishedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -181,6 +181,10 @@ func (e *TestSuiteRunFinishedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TestSuiteRunFinishedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TestSuiteRunFinishedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { diff --git a/pkg/api/zz_testsuiterunqueued_0_1_0.go b/pkg/api/zz_testsuiterunqueued_0_1_0.go index c1c16a7..aa95e39 100644 --- a/pkg/api/zz_testsuiterunqueued_0_1_0.go +++ b/pkg/api/zz_testsuiterunqueued_0_1_0.go @@ -65,7 +65,7 @@ func (e TestSuiteRunQueuedEventV0_1_0) GetType() CDEventType { } func (e TestSuiteRunQueuedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestSuiteRunQueuedEventV0_1_0) GetId() string { @@ -146,7 +146,11 @@ func (e *TestSuiteRunQueuedEventV0_1_0) SetCustomData(contentType string, data i func (e TestSuiteRunQueuedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e TestSuiteRunQueuedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_testsuiterunqueued_0_2_0.go b/pkg/api/zz_testsuiterunqueued_0_2_0.go index 50fba0a..ee1de07 100644 --- a/pkg/api/zz_testsuiterunqueued_0_2_0.go +++ b/pkg/api/zz_testsuiterunqueued_0_2_0.go @@ -65,7 +65,7 @@ func (e TestSuiteRunQueuedEventV0_2_0) GetType() CDEventType { } func (e TestSuiteRunQueuedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestSuiteRunQueuedEventV0_2_0) GetId() string { @@ -160,7 +160,7 @@ func (e *TestSuiteRunQueuedEventV0_2_0) SetCustomData(contentType string, data i func (e TestSuiteRunQueuedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -177,6 +177,10 @@ func (e *TestSuiteRunQueuedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TestSuiteRunQueuedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TestSuiteRunQueuedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { diff --git a/pkg/api/zz_testsuiterunstarted_0_1_0.go b/pkg/api/zz_testsuiterunstarted_0_1_0.go index 28b3c9b..fad6783 100644 --- a/pkg/api/zz_testsuiterunstarted_0_1_0.go +++ b/pkg/api/zz_testsuiterunstarted_0_1_0.go @@ -65,7 +65,7 @@ func (e TestSuiteRunStartedEventV0_1_0) GetType() CDEventType { } func (e TestSuiteRunStartedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestSuiteRunStartedEventV0_1_0) GetId() string { @@ -146,7 +146,11 @@ func (e *TestSuiteRunStartedEventV0_1_0) SetCustomData(contentType string, data func (e TestSuiteRunStartedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.3.0", eType.Subject, eType.Predicate, eType.Custom) +} + +func (e TestSuiteRunStartedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content } // Set subject custom fields diff --git a/pkg/api/zz_testsuiterunstarted_0_2_0.go b/pkg/api/zz_testsuiterunstarted_0_2_0.go index 72d3a86..7082ad6 100644 --- a/pkg/api/zz_testsuiterunstarted_0_2_0.go +++ b/pkg/api/zz_testsuiterunstarted_0_2_0.go @@ -65,7 +65,7 @@ func (e TestSuiteRunStartedEventV0_2_0) GetType() CDEventType { } func (e TestSuiteRunStartedEventV0_2_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TestSuiteRunStartedEventV0_2_0) GetId() string { @@ -160,7 +160,7 @@ func (e *TestSuiteRunStartedEventV0_2_0) SetCustomData(contentType string, data func (e TestSuiteRunStartedEventV0_2_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -177,6 +177,10 @@ func (e *TestSuiteRunStartedEventV0_2_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TestSuiteRunStartedEventV0_2_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TestSuiteRunStartedEventV0_2_0) SetSubjectEnvironment(environment *Reference) { diff --git a/pkg/api/zz_ticketclosed_0_1_0.go b/pkg/api/zz_ticketclosed_0_1_0.go index f6dda86..99a3e1a 100644 --- a/pkg/api/zz_ticketclosed_0_1_0.go +++ b/pkg/api/zz_ticketclosed_0_1_0.go @@ -81,7 +81,7 @@ func (e TicketClosedEventV0_1_0) GetType() CDEventType { } func (e TicketClosedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TicketClosedEventV0_1_0) GetId() string { @@ -176,7 +176,7 @@ func (e *TicketClosedEventV0_1_0) SetCustomData(contentType string, data interfa func (e TicketClosedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -193,6 +193,10 @@ func (e *TicketClosedEventV0_1_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TicketClosedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TicketClosedEventV0_1_0) SetSubjectAssignees(assignees []string) { diff --git a/pkg/api/zz_ticketcreated_0_1_0.go b/pkg/api/zz_ticketcreated_0_1_0.go index bbde39b..113ef82 100644 --- a/pkg/api/zz_ticketcreated_0_1_0.go +++ b/pkg/api/zz_ticketcreated_0_1_0.go @@ -77,7 +77,7 @@ func (e TicketCreatedEventV0_1_0) GetType() CDEventType { } func (e TicketCreatedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TicketCreatedEventV0_1_0) GetId() string { @@ -172,7 +172,7 @@ func (e *TicketCreatedEventV0_1_0) SetCustomData(contentType string, data interf func (e TicketCreatedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -189,6 +189,10 @@ func (e *TicketCreatedEventV0_1_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TicketCreatedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TicketCreatedEventV0_1_0) SetSubjectAssignees(assignees []string) { diff --git a/pkg/api/zz_ticketupdated_0_1_0.go b/pkg/api/zz_ticketupdated_0_1_0.go index cd7b149..212826b 100644 --- a/pkg/api/zz_ticketupdated_0_1_0.go +++ b/pkg/api/zz_ticketupdated_0_1_0.go @@ -79,7 +79,7 @@ func (e TicketUpdatedEventV0_1_0) GetType() CDEventType { } func (e TicketUpdatedEventV0_1_0) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e TicketUpdatedEventV0_1_0) GetId() string { @@ -174,7 +174,7 @@ func (e *TicketUpdatedEventV0_1_0) SetCustomData(contentType string, data interf func (e TicketUpdatedEventV0_1_0) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate) + return CompiledSchemas.GetBySpecSubjectPredicate("0.4.1", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -191,6 +191,10 @@ func (e *TicketUpdatedEventV0_1_0) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e TicketUpdatedEventV0_1_0) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *TicketUpdatedEventV0_1_0) SetSubjectAssignees(assignees []string) { diff --git a/pkg/api/zz_ztest_foosubjectbarpredicate_1_2_3.go b/pkg/api/zz_ztest_foosubjectbarpredicate_1_2_3.go index e72ef6e..ee48c2c 100644 --- a/pkg/api/zz_ztest_foosubjectbarpredicate_1_2_3.go +++ b/pkg/api/zz_ztest_foosubjectbarpredicate_1_2_3.go @@ -69,7 +69,7 @@ func (e FooSubjectBarPredicateEventV1_2_3) GetType() CDEventType { } func (e FooSubjectBarPredicateEventV1_2_3) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e FooSubjectBarPredicateEventV1_2_3) GetId() string { @@ -164,7 +164,7 @@ func (e *FooSubjectBarPredicateEventV1_2_3) SetCustomData(contentType string, da func (e FooSubjectBarPredicateEventV1_2_3) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return TestCompiledSchemas.GetBySpecSubjectPredicate("99.0.0", eType.Subject, eType.Predicate) + return TestCompiledSchemas.GetBySpecSubjectPredicate("99.0.0", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -181,6 +181,10 @@ func (e *FooSubjectBarPredicateEventV1_2_3) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e FooSubjectBarPredicateEventV1_2_3) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *FooSubjectBarPredicateEventV1_2_3) SetSubjectArtifactId(artifactId string) { diff --git a/pkg/api/zz_ztest_foosubjectbarpredicate_2_2_3.go b/pkg/api/zz_ztest_foosubjectbarpredicate_2_2_3.go index 5e5794c..fad2727 100644 --- a/pkg/api/zz_ztest_foosubjectbarpredicate_2_2_3.go +++ b/pkg/api/zz_ztest_foosubjectbarpredicate_2_2_3.go @@ -69,7 +69,7 @@ func (e FooSubjectBarPredicateEventV2_2_3) GetType() CDEventType { } func (e FooSubjectBarPredicateEventV2_2_3) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e FooSubjectBarPredicateEventV2_2_3) GetId() string { @@ -164,7 +164,7 @@ func (e *FooSubjectBarPredicateEventV2_2_3) SetCustomData(contentType string, da func (e FooSubjectBarPredicateEventV2_2_3) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return TestCompiledSchemas.GetBySpecSubjectPredicate("99.1.0", eType.Subject, eType.Predicate) + return TestCompiledSchemas.GetBySpecSubjectPredicate("99.1.0", eType.Subject, eType.Predicate, eType.Custom) } // CDEventsWriterV04 implementation @@ -181,6 +181,10 @@ func (e *FooSubjectBarPredicateEventV2_2_3) SetSchemaUri(schema string) { e.Context.SchemaUri = schema } +func (e FooSubjectBarPredicateEventV2_2_3) GetSubjectContent() interface{} { + return e.Subject.Content +} + // Set subject custom fields func (e *FooSubjectBarPredicateEventV2_2_3) SetSubjectArtifactId(artifactId string) { diff --git a/tools/generator.go b/tools/generator.go index 0a5984a..0871249 100644 --- a/tools/generator.go +++ b/tools/generator.go @@ -138,6 +138,7 @@ type Data struct { Schema string IsTestData bool SpecVersion string + IsCustom bool } type Schemas struct { @@ -288,9 +289,21 @@ func main() { // 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, templates, GO_TYPES_NAMES, false) + // Setup folders where to look for schemas + folders := []string{} + versioned_folder := "" + for _, folder := range SCHEMA_FOLDERS[1:3] { + versioned_folder = filepath.Join(CODE_FOLDER, SPEC_FOLDER_PREFIX+shortVersion, folder) + fileInfo, err := os.Stat(versioned_folder) + if err == nil && fileInfo.IsDir() { + // If the path does exists, and it's a dir, include this in the generation + folders = append(folders, versioned_folder) + } + } + + // Generate SDK files for all discovered folders + log.Printf("Generating SDK files from templates: %s and schemas: %s into %s", TEMPLATES_FOLDER, folders, GEN_CODE_FOLDER) + err = generate(folders, GEN_CODE_FOLDER, "", version, templates, GO_TYPES_NAMES, false) if err != nil { log.Fatalf("%s", err.Error()) } @@ -301,7 +314,7 @@ func main() { 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) + err = generate([]string{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()) } @@ -322,7 +335,7 @@ func loadSchemas(schemaFolder string, schemas *Schemas) error { 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 { +func generate(schemaFolders []string, 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) @@ -335,15 +348,17 @@ func generate(schemaFolder, genFolder, prefix, specVersion string, templates *te } // Walk the jsonschemas folder, process each ".json" file - walkProcessor := getWalkProcessor(schemaFolder, templates, genFolder, goTypes, &allData, prefix, isTestMode) - err := fs.WalkDir(os.DirFS(schemaFolder), ".", walkProcessor) - if err != nil { - return err + for _, schemaFolder := range schemaFolders { + walkProcessor := getWalkProcessor(schemaFolder, templates, genFolder, goTypes, &allData, prefix, isTestMode) + err := fs.WalkDir(os.DirFS(schemaFolder), ".", walkProcessor) + if err != nil { + return err + } } // Process the spec template. Create the target folder is it doesn't exist specFileFolder := filepath.Join(genFolder, allData.SpecVersionName) - err = os.MkdirAll(specFileFolder, os.ModePerm) + err := os.MkdirAll(specFileFolder, os.ModePerm) if err != nil { return err } @@ -457,6 +472,10 @@ func getWalkProcessor(rootDir string, allTemplates *template.Template, genFolder // This should not happen, but ignore just in case return nil } + if info.Name() == "conformance.json" { + // Skip conformance tests + return nil + } // Set the whole path schemaPath := filepath.Join(rootDir, path) // Load the jsonschema from the spec @@ -466,7 +485,7 @@ func getWalkProcessor(rootDir string, allTemplates *template.Template, genFolder } // Prepare the data - data, err := DataFromSchema(sch, goTypes) + data, err := DataFromSchema(sch, goTypes, allData.SpecVersion) if err != nil { return err } @@ -520,131 +539,148 @@ func validateStringEnumAnyOf(schema *jsonschema.Schema) error { return nil } -func DataFromSchema(schema *jsonschema.Schema, mappings map[string]string) (*Data, error) { +func DataFromSchema(schema *jsonschema.Schema, mappings map[string]string, specVersion string) (*Data, error) { // Parse the event type from the context contextSchema, ok := schema.Properties["context"] if !ok { return nil, fmt.Errorf("no context property in schema %s", schema.Location) } - eventTypeSchema, ok := contextSchema.Properties["type"] - if !ok { - return nil, fmt.Errorf("no type property in schema %s", eventTypeSchema.Location) - } - if len(eventTypeSchema.Enum.Values) == 0 { - return nil, fmt.Errorf("no value defined for type in schema %s", eventTypeSchema.Location) - } - 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 := cdeventTypeFromString(string(eventTypeString)) - if err != nil { - return nil, err - } - - // Parse the subject type - subjectSchema, ok := schema.Properties["subject"] - if !ok { - return nil, fmt.Errorf("no subject property in schema %s", schema.Location) - } - subjectTypeSchema, ok := subjectSchema.Properties["type"] - if !ok { - return nil, fmt.Errorf("no type property in schema %s", subjectSchema.Location) - } - if len(subjectTypeSchema.Enum.Values) == 0 { - return nil, fmt.Errorf("no value defined for type in schema %s", subjectTypeSchema.Location) - } - subjectTypeString, ok := subjectTypeSchema.Enum.Values[0].(string) - if !ok { - return nil, fmt.Errorf("non-string value defined for type in schema %s", subjectTypeSchema.Location) - } - - // Parse the subject content fields + isCustom := false + var eventType cdeventType + var subjectTypeString string contentFields := []ContentField{} contentTypes := []ContentType{} - contentSchema, ok := subjectSchema.Properties["content"] - if !ok { - return nil, fmt.Errorf("no content property in schema %s", subjectSchema.Location) - } - for name, propertySchema := range contentSchema.Properties { - contentField := ContentField{} - 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 - } + + // Special logic for custom schema + if strings.HasSuffix(schema.ID, "schema/custom") { + isCustom = true + eventType = cdeventType{ + Subject: "custom", + Predicate: "type", + Version: specVersion, } - // Handles the case of "anyOf" with string + enum of strings - var types = []string{} - if propertySchema.Types != nil { - types = propertySchema.Types.ToStrings() + } + + // We can get more data from non-custom schemas + if !isCustom { + var err error + eventTypeSchema, ok := contextSchema.Properties["type"] + if !ok { + return nil, fmt.Errorf("no type property in schema %s", eventTypeSchema.Location) } - 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 eventTypeSchema.Enum != nil && len(eventTypeSchema.Enum.Values) == 0 { + return nil, fmt.Errorf("no value defined for type in schema %s", eventTypeSchema.Location) } - if len(types) > 1 { - return nil, fmt.Errorf("only one type allowed for content property in schema %s: %v", propertySchema.Location, types) + 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 len(types) > 1 { - return nil, fmt.Errorf("only one type allowed for content property in schema %s: %v", propertySchema.Location, types) + if eventTypeString == "" { + return nil, fmt.Errorf("empty value defined for type in schema %s", eventTypeSchema.Location) } - switch contentFieldType { - case "object": - contentType, err := typesForSchema(name, propertySchema, mappings) - if err != nil { - return nil, err + eventType, err = cdeventTypeFromString(string(eventTypeString)) + if err != nil { + return nil, err + } + // Parse the subject type + subjectSchema, ok := schema.Properties["subject"] + if !ok { + return nil, fmt.Errorf("no subject property in schema %s", schema.Location) + } + subjectTypeSchema, ok := subjectSchema.Properties["type"] + if !ok { + return nil, fmt.Errorf("no type property in schema %s", subjectSchema.Location) + } + if len(subjectTypeSchema.Enum.Values) == 0 { + return nil, fmt.Errorf("no value defined for type in schema %s", subjectTypeSchema.Location) + } + subjectTypeString, ok = subjectTypeSchema.Enum.Values[0].(string) + if !ok { + return nil, fmt.Errorf("non-string value defined for type in schema %s", subjectTypeSchema.Location) + } + + // Parse the subject content fields + contentSchema, ok := subjectSchema.Properties["content"] + if !ok { + return nil, fmt.Errorf("no content property in schema %s", subjectSchema.Location) + } + for name, propertySchema := range contentSchema.Properties { + contentField := ContentField{} + 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 + } } - namespacedType := GoTypeName(contentType.Name, mappings) - if contentType.Name != REFERENCE_TYPE { - // If this is not a "Reference" we need to define a new type - contentTypes = append(contentTypes, *contentType) - // 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) + "V" + strings.ReplaceAll(eventType.Version, ".", "_") + // Handles the case of "anyOf" with string + enum of strings + var types = []string{} + if propertySchema.Types != nil { + types = propertySchema.Types.ToStrings() } - // 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" + 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 { + return nil, err + } + namespacedType := GoTypeName(contentType.Name, mappings) + if contentType.Name != REFERENCE_TYPE { + // If this is not a "Reference" we need to define a new type + contentTypes = append(contentTypes, *contentType) + // 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) + "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) } - case "anyOfStringEnum": - contentField.Type = "string" - default: - return nil, fmt.Errorf("content property type %s not allowed in schema %s", contentField.Type, propertySchema.Location) + contentFields = append(contentFields, contentField) } - contentFields = append(contentFields, contentField) + // Sort contents for deterministic code rendering + sort.Slice(contentFields, func(i, j int) bool { + return contentFields[i].Name < contentFields[j].Name + }) + sort.Slice(contentTypes, func(i, j int) bool { + return contentTypes[i].Name < contentTypes[j].Name + }) } - // Sort contents for deterministic code rendering - sort.Slice(contentFields, func(i, j int) bool { - return contentFields[i].Name < contentFields[j].Name - }) - sort.Slice(contentTypes, func(i, j int) bool { - return contentTypes[i].Name < contentTypes[j].Name - }) return &Data{ Subject: GoTypeName(eventType.Subject, mappings), Predicate: GoTypeName(eventType.Predicate, mappings), @@ -655,6 +691,7 @@ func DataFromSchema(schema *jsonschema.Schema, mappings map[string]string) (*Dat SubjectType: subjectTypeString, Contents: contentFields, ContentTypes: contentTypes, + IsCustom: isCustom, }, nil } diff --git a/tools/generator_test.go b/tools/generator_test.go index c5be95a..bc5f08f 100644 --- a/tools/generator_test.go +++ b/tools/generator_test.go @@ -119,7 +119,7 @@ func TestDataFromSchema(t *testing.T) { "foosubject": "FooSubject", "barpredicate": "BarPredicate", } - got, err := DataFromSchema(testSchema, mappings) + got, err := DataFromSchema(testSchema, mappings, "0.1.2") if err != nil { t.Fatalf(err.Error()) } diff --git a/tools/templates/event.go.tmpl b/tools/templates/event.go.tmpl index 0ba2813..df5398e 100644 --- a/tools/templates/event.go.tmpl +++ b/tools/templates/event.go.tmpl @@ -32,25 +32,34 @@ import ( var ( // {{.Subject}}{{.Predicate}} event type v{{.Version}} {{.Subject}}{{.Predicate}}EventTypeV{{.VersionName}} CDEventType = CDEventType{ +{{- if not .IsCustom }} Subject: "{{.SubjectLower}}", Predicate: "{{.PredicateLower}}", Version: "{{.Version}}", +{{- else -}} +{{- end }} } ) +{{- if not .IsCustom }} 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 }} } +{{- end }} type {{.Subject}}{{.Predicate}}SubjectV{{.VersionName}} struct { SubjectBase - Content {{.Subject}}{{.Predicate}}SubjectContentV{{.VersionName}} `json:"content"` + Content {{if .IsCustom }}interface{}{{ else }}{{.Subject}}{{.Predicate}}SubjectContentV{{.VersionName}}{{ end }} `json:"content"` } func (sc {{.Subject}}{{.Predicate}}SubjectV{{.VersionName}}) GetSubjectType() SubjectType { +{{- if not .IsCustom }} return "{{.SubjectType}}" +{{- else }} + return sc.Type +{{- end }} } type {{.Subject}}{{.Predicate}}EventV{{.VersionName}} struct { @@ -70,7 +79,7 @@ func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetType() CDEventType } func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetVersion() string { - return CDEventsSpecVersion + return e.Context.GetVersion() } func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetId() string { @@ -167,7 +176,7 @@ func (e *{{.Subject}}{{.Predicate}}EventV{{.VersionName}}) SetCustomData(content func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetSchema() (string, *jsonschema.Schema, error) { eType := e.GetType() - return {{if .IsTestData }}Test{{end}}CompiledSchemas.GetBySpecSubjectPredicate("{{.SpecVersion}}", eType.Subject, eType.Predicate) + return {{if .IsTestData }}Test{{end}}CompiledSchemas.GetBySpecSubjectPredicate("{{.SpecVersion}}", eType.Subject, eType.Predicate, eType.Custom) } {{- if ne .SpecVersion "0.3.0"}} @@ -187,7 +196,27 @@ func (e *{{.Subject}}{{.Predicate}}EventV{{.VersionName}}) SetSchemaUri(schema s {{- end}} +func (e {{.Subject}}{{.Predicate}}EventV{{.VersionName}}) GetSubjectContent() interface{} { + return e.Subject.Content +} + +{{- if .IsCustom }} +// CustomCDEventWriter implementation + +func (e *{{.Subject}}{{.Predicate}}EventV{{.VersionName}}) SetEventType(eventType CDEventType) { + e.Context.Type = eventType + e.Subject.Type = SubjectType(eventType.FQSubject()) +} + +// CustomCDEvent types can have different subject fields +func (e *{{.Subject}}{{.Predicate}}EventV{{.VersionName}}) SetSubjectContent(subjectContent interface{}) { + e.Subject.Content = subjectContent +} +{{- end }} + +{{- if gt (len .Contents) 0 }} // Set subject custom fields +{{- end }} {{ range $i, $field := .Contents }} func (e *{{$.Subject}}{{$.Predicate}}EventV{{$.VersionName}}) SetSubject{{ .Name }}({{ .NameLower }} {{ .Type }}) { e.Subject.Content.{{ .Name }} = {{ .NameLower }} diff --git a/tools/templates/schemas.go.tmpl b/tools/templates/schemas.go.tmpl index 573f50c..a53b265 100644 --- a/tools/templates/schemas.go.tmpl +++ b/tools/templates/schemas.go.tmpl @@ -68,8 +68,13 @@ func init() { } {{- if not .IsTestData}} -func (db SchemaDB) GetBySpecSubjectPredicate(specVersion, subject, predicate string) (string, *jsonschema.Schema, error) { - id := fmt.Sprintf(CDEventsSchemaURLTemplate, specVersion, subject, predicate) +func (db SchemaDB) GetBySpecSubjectPredicate(specVersion, subject, predicate, custom string) (string, *jsonschema.Schema, error) { + id := "" + if custom == "" && subject != "" && predicate != "" { + id = fmt.Sprintf(CDEventsSchemaURLTemplate, specVersion, subject, predicate) + } else { + id = fmt.Sprintf(CDEventsCustomSchemaURLTemplate, specVersion) + } if schemaString, found := db[id]; found { return id, schemaString, nil } diff --git a/tools/templates/types.go.tmpl b/tools/templates/types.go.tmpl index a8cbe49..3008219 100644 --- a/tools/templates/types.go.tmpl +++ b/tools/templates/types.go.tmpl @@ -41,7 +41,13 @@ func init() { // Set up CDEventsByUnversionedTypes for convenience CDEventsByUnversionedTypes = make(map[string]api.CDEvent{{if ne .SpecVersion "0.3.0"}}V04{{end}}) for _, event := range CDEventsTypes { - CDEventsByUnversionedTypes[event.GetType().UnversionedString()] = event + key := event.GetType().UnversionedString() + {{- if ne .SpecVersion "0.3.0" }} + if event.GetType().Short() == "" { + key = api.CustomEventMapKey + } + {{- end }} + CDEventsByUnversionedTypes[key] = event } }