diff --git a/models/registration/utils.go b/models/registration/utils.go index 876c23b6a..3a64affe5 100644 --- a/models/registration/utils.go +++ b/models/registration/utils.go @@ -45,7 +45,12 @@ func getEntity(byt []byte) (et entity.Entity, _ error) { return nil, ErrGetEntity(fmt.Errorf("Invalid model definition: %s", err.Error())) } et = &model - case schema.RelationshipSchemaVersionV1Beta2, v1alpha3.RelationshipSchemaVersion: + // Accept v1alpha3, v1beta2, and v1beta3 relationship schema version + // strings, mirroring the component/model compatibility above. The wire + // shapes are compatible with the v1alpha3 Go struct (meshery/meshery's + // relationship_version_bridge.go round-trips them with shallow typed + // copies), so all three decode into the same registration type. + case schema.RelationshipSchemaVersionV1Beta2, schema.RelationshipSchemaVersionV1Beta3, v1alpha3.RelationshipSchemaVersion: var rel relationship.RelationshipDefinition err := encoding.Unmarshal(byt, &rel) if err != nil { diff --git a/models/registration/utils_test.go b/models/registration/utils_test.go index dddd947b2..46b5943a4 100644 --- a/models/registration/utils_test.go +++ b/models/registration/utils_test.go @@ -29,3 +29,40 @@ func TestGetEntityAcceptsV1Beta2RelationshipSchemaVersion(t *testing.T) { require.NoError(t, err) assert.Equal(t, entity.RelationshipDefinition, actual.Type()) } + +func TestGetEntityAcceptsV1Beta3RelationshipSchemaVersion(t *testing.T) { + t.Parallel() + + relationshipDocument := []byte(`{ + "schemaVersion": "relationships.meshery.io/v1beta3", + "kind": "edge", + "type": "non-binding", + "subType": "reference", + "model": { + "name": "kubernetes", + "model": { + "version": "v1.0.0" + } + }, + "version": "v1.0.0" + }`) + + actual, err := getEntity(relationshipDocument) + require.NoError(t, err) + assert.Equal(t, entity.RelationshipDefinition, actual.Type()) +} + +func TestGetEntityRejectsUnknownRelationshipSchemaVersion(t *testing.T) { + t.Parallel() + + relationshipDocument := []byte(`{ + "schemaVersion": "relationships.meshery.io/v1beta9", + "kind": "edge", + "type": "non-binding", + "subType": "reference", + "version": "v1.0.0" + }`) + + _, err := getEntity(relationshipDocument) + require.Error(t, err) +} diff --git a/schema/validator.go b/schema/validator.go index f8af4a6b9..822f8f29c 100644 --- a/schema/validator.go +++ b/schema/validator.go @@ -33,6 +33,12 @@ const ( // the string to keep all packages in sync. const RelationshipSchemaVersionV1Beta2 = "relationships.meshery.io/v1beta2" +// RelationshipSchemaVersionV1Beta3 is the schema version string for v1beta3 +// relationship definitions, the current authoring target published by +// meshery/schemas. Use this constant instead of hard-coding the string to +// keep all packages in sync. +const RelationshipSchemaVersionV1Beta3 = "relationships.meshery.io/v1beta3" + // Ref identifies which schema should be used to validate a document. type Ref struct { SchemaVersion string `json:"schemaVersion,omitempty" yaml:"schemaVersion,omitempty"`