From 133a642ba24efef55311d85d88766987a97edcf8 Mon Sep 17 00:00:00 2001 From: Tushar Shahi Date: Sat, 25 Apr 2026 04:22:36 +0530 Subject: [PATCH] feat(api-docs-spectral-linter): add new frontend system support --- .changeset/add-new-frontend-system-support.md | 13 ++++ plugins/api-docs-spectral-linter/package.json | 29 ++++++++- .../src/alpha.test.tsx | 22 +++++++ .../api-docs-spectral-linter/src/alpha.tsx | 63 +++++++++++++++++++ yarn.lock | 1 + 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 .changeset/add-new-frontend-system-support.md create mode 100644 plugins/api-docs-spectral-linter/src/alpha.test.tsx create mode 100644 plugins/api-docs-spectral-linter/src/alpha.tsx diff --git a/.changeset/add-new-frontend-system-support.md b/.changeset/add-new-frontend-system-support.md new file mode 100644 index 0000000..0223734 --- /dev/null +++ b/.changeset/add-new-frontend-system-support.md @@ -0,0 +1,13 @@ +--- +'@dweber019/backstage-plugin-api-docs-spectral-linter': minor +--- + +Added support for the new frontend system. + +A new `/alpha` entry point is now available that exports the plugin as a default export compatible with `createFrontendPlugin`. This includes: + +- `ApiBlueprint` for the Spectral Linter API +- `EntityContentBlueprint` for the Spectral Linter tab on API entity pages +- Entity filter that automatically shows the tab only on `openapi` and `asyncapi` API entities + +The existing entry point (`/`) remains unchanged for backward compatibility. diff --git a/plugins/api-docs-spectral-linter/package.json b/plugins/api-docs-spectral-linter/package.json index f36e603..b12ced7 100644 --- a/plugins/api-docs-spectral-linter/package.json +++ b/plugins/api-docs-spectral-linter/package.json @@ -10,10 +10,36 @@ "version": "0.5.2", "main": "src/index.ts", "types": "src/index.ts", + "exports": { + ".": "./src/index.ts", + "./alpha": "./src/alpha.tsx", + "./package.json": "./package.json" + }, + "typesVersions": { + "*": { + "alpha": [ + "src/alpha.tsx" + ], + "package.json": [ + "package.json" + ] + } + }, "publishConfig": { "access": "public", "main": "dist/index.esm.js", - "types": "dist/index.d.ts" + "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.esm.js" + }, + "./alpha": { + "types": "./dist/alpha.d.ts", + "default": "./dist/alpha.esm.js" + }, + "./package.json": "./package.json" + } }, "backstage": { "role": "frontend-plugin", @@ -36,6 +62,7 @@ "@backstage/catalog-model": "^1.7.6", "@backstage/core-components": "^0.18.4", "@backstage/core-plugin-api": "^1.12.1", + "@backstage/frontend-plugin-api": "^0.13.2", "@backstage/plugin-catalog-react": "^1.21.4", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", diff --git a/plugins/api-docs-spectral-linter/src/alpha.test.tsx b/plugins/api-docs-spectral-linter/src/alpha.test.tsx new file mode 100644 index 0000000..6dc28db --- /dev/null +++ b/plugins/api-docs-spectral-linter/src/alpha.test.tsx @@ -0,0 +1,22 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import plugin from './alpha'; + +describe('spectral linter new frontend system', () => { + it('should export the plugin as default', () => { + expect(plugin).toBeDefined(); + }); +}); diff --git a/plugins/api-docs-spectral-linter/src/alpha.tsx b/plugins/api-docs-spectral-linter/src/alpha.tsx new file mode 100644 index 0000000..22f5059 --- /dev/null +++ b/plugins/api-docs-spectral-linter/src/alpha.tsx @@ -0,0 +1,63 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + ApiBlueprint, + configApiRef, + createFrontendPlugin, +} from '@backstage/frontend-plugin-api'; +import { EntityContentBlueprint } from '@backstage/plugin-catalog-react/alpha'; +import { linterApiRef, LinterClient } from './api'; +import { isApiDocsSpectralLinterAvailable } from './lib/helper'; + +/** + * Provides the Spectral Linter API as an extension. + * @alpha + */ +const spectralLinterApi = ApiBlueprint.make({ + params: defineParams => + defineParams({ + api: linterApiRef, + deps: { configApi: configApiRef }, + factory: ({ configApi }) => new LinterClient({ configApi }), + }), +}); + +/** + * Entity content extension that renders the Spectral Linter tab on API entity pages. + * @alpha + */ +const spectralLinterContent = EntityContentBlueprint.make({ + name: 'spectral-linter', + params: { + path: '/spectral-linter', + title: 'Spectral Linter', + filter: entity => isApiDocsSpectralLinterAvailable(entity), + loader: () => + import('./components/EntityApiDocsSpectralLinterContent').then(m => ( + + )), + }, +}); + +/** + * The API docs spectral linter plugin, for use with the new frontend system. + * @alpha + */ +export default createFrontendPlugin({ + pluginId: 'api-docs-spectral-linter', + extensions: [spectralLinterApi, spectralLinterContent], +}); diff --git a/yarn.lock b/yarn.lock index ba92bee..57ecd5b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4899,6 +4899,7 @@ __metadata: "@backstage/core-components": "npm:^0.18.4" "@backstage/core-plugin-api": "npm:^1.12.1" "@backstage/dev-utils": "npm:^1.1.18" + "@backstage/frontend-plugin-api": "npm:^0.13.2" "@backstage/plugin-catalog-react": "npm:^1.21.4" "@backstage/test-utils": "npm:^1.7.14" "@material-ui/core": "npm:^4.12.2"