diff --git a/.changeset/wet-chefs-exercise.md b/.changeset/wet-chefs-exercise.md new file mode 100644 index 0000000000..cf8a2e538e --- /dev/null +++ b/.changeset/wet-chefs-exercise.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-api-docs': patch +--- + +Display entity title on `ApiDefinitionCard` if defined diff --git a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx index 32a6ec0f77..936edc07da 100644 --- a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx +++ b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx @@ -62,6 +62,7 @@ paths: kind: 'API', metadata: { name: 'my-name', + title: 'My Name', }, spec: { type: 'openapi', @@ -88,7 +89,7 @@ paths: ); await waitFor(() => { - expect(getByText(/my-name/i)).toBeInTheDocument(); + expect(getByText(/My Name/i)).toBeInTheDocument(); expect(getByText(/OpenAPI/)).toBeInTheDocument(); expect(getByText(/Raw/i)).toBeInTheDocument(); expect(getByText(/List all artists/i)).toBeInTheDocument(); @@ -101,6 +102,7 @@ paths: kind: 'API', metadata: { name: 'my-name', + title: 'My Name', }, spec: { type: 'custom-type', @@ -118,7 +120,7 @@ paths: , ); - expect(getByText(/my-name/i)).toBeInTheDocument(); + expect(getByText(/My Name/i)).toBeInTheDocument(); expect(getByText(/custom-type/i)).toBeInTheDocument(); expect( getAllByText( diff --git a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.tsx b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.tsx index 2ad5a4aca7..6f3e155816 100644 --- a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.tsx +++ b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.tsx @@ -39,10 +39,11 @@ export const ApiDefinitionCard = (_: Props) => { } const definitionWidget = getApiDefinitionWidget(entity); + const entityTitle = entity.metadata.title ?? entity.metadata.name; if (definitionWidget) { return ( - + {definitionWidget.component(entity.spec.definition)} @@ -58,7 +59,7 @@ export const ApiDefinitionCard = (_: Props) => { return (