diff --git a/.changeset/fifty-nails-pay.md b/.changeset/fifty-nails-pay.md new file mode 100644 index 0000000000..5880d9a8cc --- /dev/null +++ b/.changeset/fifty-nails-pay.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-api-docs': patch +'@backstage/plugin-catalog': patch +--- + +Replace usage of implementsApis with relations diff --git a/.changeset/short-singers-serve.md b/.changeset/short-singers-serve.md index ae8e8d171c..c2f1c1914f 100644 --- a/.changeset/short-singers-serve.md +++ b/.changeset/short-singers-serve.md @@ -4,7 +4,7 @@ Marked the field `spec.implementsApis` on `Component` entities for deprecation on Dec 14th, 2020. -Code that consumes these fields should remove those usages as soon as possible as migrate to using +Code that consumes these fields should remove those usages as soon as possible and migrate to using relations instead. Producers should fill the field `spec.providesApis` instead, which has the same semantic. diff --git a/plugins/api-docs/src/catalog/MissingImplementsApisEmptyState/MissingImplementsApisEmptyState.tsx b/plugins/api-docs/src/catalog/MissingImplementsApisEmptyState/MissingImplementsApisEmptyState.tsx index 9160aca514..f13848bd19 100644 --- a/plugins/api-docs/src/catalog/MissingImplementsApisEmptyState/MissingImplementsApisEmptyState.tsx +++ b/plugins/api-docs/src/catalog/MissingImplementsApisEmptyState/MissingImplementsApisEmptyState.tsx @@ -28,7 +28,7 @@ spec: type: service lifecycle: production owner: guest - implementsApis: + providesApis: - example-api `; @@ -49,8 +49,7 @@ export const MissingImplementsApisEmptyState = () => { description={ Components can implement APIs that are displayed on this page. You - need to fill the implementsApis field to enable this - tool. + need to fill the providesApis field to enable this tool. } action={ @@ -71,7 +70,7 @@ export const MissingImplementsApisEmptyState = () => { diff --git a/plugins/api-docs/src/catalog/Router.tsx b/plugins/api-docs/src/catalog/Router.tsx index d3fe7f7553..6991ad4b57 100644 --- a/plugins/api-docs/src/catalog/Router.tsx +++ b/plugins/api-docs/src/catalog/Router.tsx @@ -15,14 +15,15 @@ */ import React from 'react'; -import { Entity } from '@backstage/catalog-model'; +import { Entity, RELATION_PROVIDES_API } from '@backstage/catalog-model'; import { Route, Routes } from 'react-router'; import { catalogRoute } from '../routes'; import { EntityPageApi } from './EntityPageApi'; import { MissingImplementsApisEmptyState } from './MissingImplementsApisEmptyState'; const isPluginApplicableToEntity = (entity: Entity) => { - return ((entity.spec?.implementsApis as string[]) || []).length > 0; + // TODO: Als support RELATION_CONSUMES_API + return entity.relations?.some(r => r.type === RELATION_PROVIDES_API); }; export const Router = ({ entity }: { entity: Entity }) => diff --git a/plugins/api-docs/src/components/useComponentApiNames.ts b/plugins/api-docs/src/components/useComponentApiNames.ts index 0eabe2b6c7..1303967895 100644 --- a/plugins/api-docs/src/components/useComponentApiNames.ts +++ b/plugins/api-docs/src/components/useComponentApiNames.ts @@ -14,8 +14,16 @@ * limitations under the License. */ -import { ComponentEntity } from '@backstage/catalog-model'; +import { + ComponentEntity, + RELATION_PROVIDES_API, +} from '@backstage/catalog-model'; export const useComponentApiNames = (entity: ComponentEntity) => { - return (entity.spec?.implementsApis as string[]) || []; + // TODO: This code doesn't handle namespaces and kinds correctly, but will be removed soon + return ( + entity.relations + ?.filter(r => r.type === RELATION_PROVIDES_API) + ?.map(r => r.target.name) || [] + ); }; diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.tsx index 89630d6f10..49653fe981 100644 --- a/plugins/catalog/src/components/AboutCard/AboutCard.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutCard.tsx @@ -18,6 +18,7 @@ import { Entity, ENTITY_DEFAULT_NAMESPACE, RELATION_OWNED_BY, + RELATION_PROVIDES_API, serializeEntityRef, } from '@backstage/catalog-model'; import { @@ -111,6 +112,8 @@ type AboutCardProps = { export function AboutCard({ entity, variant }: AboutCardProps) { const classes = useStyles(); const codeLink = getCodeLinkInfo(entity); + // TODO: Also support RELATION_CONSUMES_API here + const hasApis = entity.relations?.some(r => r.type === RELATION_PROVIDES_API); return ( @@ -146,9 +149,9 @@ export function AboutCard({ entity, variant }: AboutCardProps) { }/${entity.kind}/${entity.metadata.name}`} /> } href="api" />