diff --git a/pkg/apis/eventing/v1beta1/eventtype_validation.go b/pkg/apis/eventing/v1beta1/eventtype_validation.go index 3688bc899e7..f24053e5034 100644 --- a/pkg/apis/eventing/v1beta1/eventtype_validation.go +++ b/pkg/apis/eventing/v1beta1/eventtype_validation.go @@ -33,8 +33,14 @@ func (ets *EventTypeSpec) Validate(ctx context.Context) *apis.FieldError { fe := apis.ErrMissingField("type") errs = errs.Also(fe) } - // TODO validate Source is a valid URI. - // TODO validate Schema is a valid URI. + // Validate Source is a non-empty URI when provided + if ets.Source != nil && ets.Source.IsEmpty() { + errs = errs.Also(apis.ErrInvalidValue("", "source", "source URI cannot be empty")) + } + // Validate Schema is a non-empty URI when provided + if ets.Schema != nil && ets.Schema.IsEmpty() { + errs = errs.Also(apis.ErrInvalidValue("", "schema", "schema URI cannot be empty")) + } // There is no validation of the SchemaData, it is application specific data. return errs } diff --git a/pkg/apis/eventing/v1beta1/eventtype_validation_test.go b/pkg/apis/eventing/v1beta1/eventtype_validation_test.go index 80ae19a0893..b3e9ea1fd56 100644 --- a/pkg/apis/eventing/v1beta1/eventtype_validation_test.go +++ b/pkg/apis/eventing/v1beta1/eventtype_validation_test.go @@ -61,6 +61,23 @@ func TestEventTypeSpecValidation(t *testing.T) { Source: testSource, Broker: "test-broker", }, + }, { + name: "invalid empty source", + ets: &EventTypeSpec{ + Type: "test-type", + Source: &apis.URL{}, + Broker: "test-broker", + }, + want: apis.ErrInvalidValue("", "source", "source URI cannot be empty"), + }, { + name: "invalid empty schema", + ets: &EventTypeSpec{ + Type: "test-type", + Source: testSource, + Schema: &apis.URL{}, + Broker: "test-broker", + }, + want: apis.ErrInvalidValue("", "schema", "schema URI cannot be empty"), }, }