From 33eae4b39a955d6c9a23d4b7535260161ceae524 Mon Sep 17 00:00:00 2001 From: kmarkow Date: Tue, 16 May 2023 10:09:18 -0400 Subject: [PATCH] Deprecate target field and make targetRef required Signed-off-by: kmarkow --- .changeset/sour-papayas-wink.md | 5 +++++ .github/vale/Vocab/Backstage/accept.txt | 1 + .../src/schema/shared/common.schema.json | 5 +++-- .../validation/entityKindSchemaValidator.test.ts | 6 +++++- .../src/validation/entitySchemaValidator.test.ts | 13 +++++++++++-- 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 .changeset/sour-papayas-wink.md 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 83f05e390d..f1b9de492c 100644 --- a/.github/vale/Vocab/Backstage/accept.txt +++ b/.github/vale/Vocab/Backstage/accept.txt @@ -361,6 +361,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..77eb4a2612 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", "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..7ae6a1fa05 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,8 +365,13 @@ describe('entitySchemaValidator', () => { expect(() => validator(entity)).toThrow(/relations/); }); - it('rejects missing relations.target', () => { + it('does not reject missing relations.target', () => { delete entity.relations[0].target; + expect(() => validator(entity)).not.toThrow(/relations/); + }); + + it('does reject missing relations.targetRef', () => { + delete entity.relations[0].targetRef; expect(() => validator(entity)).toThrow(/relations/); });