diff --git a/.changeset/sour-papayas-wink.md b/.changeset/sour-papayas-wink.md new file mode 100644 index 0000000000..30d5110fff --- /dev/null +++ b/.changeset/sour-papayas-wink.md @@ -0,0 +1,5 @@ +--- +'@backstage/catalog-model': minor +--- + +Deprecate target field and make targetRef required in common.schema.json diff --git a/.github/vale/Vocab/Backstage/accept.txt b/.github/vale/Vocab/Backstage/accept.txt index 68fbdabb00..e9fc74b874 100644 --- a/.github/vale/Vocab/Backstage/accept.txt +++ b/.github/vale/Vocab/Backstage/accept.txt @@ -364,6 +364,7 @@ SVGs talkdesk Talkdesk Tanzu +targetRef tasklist techdocs Telenor diff --git a/packages/catalog-model/src/schema/shared/common.schema.json b/packages/catalog-model/src/schema/shared/common.schema.json index 5a5eb97bb7..7468bd9d70 100644 --- a/packages/catalog-model/src/schema/shared/common.schema.json +++ b/packages/catalog-model/src/schema/shared/common.schema.json @@ -32,7 +32,7 @@ "$id": "#relation", "type": "object", "description": "A directed relation from one entity to another.", - "required": ["type", "target"], + "required": ["type", "target", "targetRef"], "additionalProperties": false, "properties": { "type": { @@ -42,7 +42,8 @@ "description": "The type of relation." }, "target": { - "$ref": "#reference" + "$ref": "#reference", + "deprecated": true }, "targetRef": { "type": "string", diff --git a/packages/catalog-model/src/validation/entityKindSchemaValidator.test.ts b/packages/catalog-model/src/validation/entityKindSchemaValidator.test.ts index ee8f39b140..14cfcbe50a 100644 --- a/packages/catalog-model/src/validation/entityKindSchemaValidator.test.ts +++ b/packages/catalog-model/src/validation/entityKindSchemaValidator.test.ts @@ -51,7 +51,11 @@ describe('entityKindSchemaValidator', () => { owner: 'me', }, relations: [ - { type: 't', target: { kind: 'k', namespace: 'ns', name: 'n' } }, + { + type: 't', + targetRef: 'someTargetRef', + target: { kind: 'k', namespace: 'ns', name: 'n' }, + }, ], status: { items: [ diff --git a/packages/catalog-model/src/validation/entitySchemaValidator.test.ts b/packages/catalog-model/src/validation/entitySchemaValidator.test.ts index 12f890d9db..bc31c5d800 100644 --- a/packages/catalog-model/src/validation/entitySchemaValidator.test.ts +++ b/packages/catalog-model/src/validation/entitySchemaValidator.test.ts @@ -52,7 +52,11 @@ describe('entitySchemaValidator', () => { owner: 'me', }, relations: [ - { type: 't', target: { kind: 'k', namespace: 'ns', name: 'n' } }, + { + type: 't', + targetRef: 'someTargetRef', + target: { kind: 'k', namespace: 'ns', name: 'n' }, + }, ], status: { items: [ @@ -361,11 +365,16 @@ describe('entitySchemaValidator', () => { expect(() => validator(entity)).toThrow(/relations/); }); - it('rejects missing relations.target', () => { + it('does reject missing relations.target', () => { delete entity.relations[0].target; expect(() => validator(entity)).toThrow(/relations/); }); + it('does reject missing relations.targetRef', () => { + delete entity.relations[0].targetRef; + expect(() => validator(entity)).toThrow(/relations/); + }); + it('rejects empty relations.target', () => { entity.relations[0].target = ''; expect(() => validator(entity)).toThrow(/relations/);