diff --git a/.changeset/strong-dryers-heal.md b/.changeset/strong-dryers-heal.md new file mode 100644 index 0000000..d3dfbbd --- /dev/null +++ b/.changeset/strong-dryers-heal.md @@ -0,0 +1,7 @@ +--- +'@dweber019/backstage-plugin-api-docs-module-wsdl': patch +--- + +Fix WSDL preview on component tab. + +**BREAKING**: Because of this change the API setup has changed, see README. diff --git a/packages/app/src/apis.ts b/packages/app/src/apis.ts index 2b2f9e2..4b3a3b5 100644 --- a/packages/app/src/apis.ts +++ b/packages/app/src/apis.ts @@ -46,13 +46,12 @@ export const apis: AnyApiFactory[] = [ api: apiDocsConfigRef, deps: {}, factory: () => { - // load the default widgets const definitionWidgets = defaultDefinitionWidgets(); - // add the wsdl-docs api widget to the definition widgets - definitionWidgets.push(wsdlApiWidget); return { getApiDefinitionWidget: (apiEntity: ApiEntity) => { - // find the widget for the type of api entity + if (apiEntity.spec.type.toLowerCase() === 'wsdl') { + return wsdlApiWidget(apiEntity); + } return definitionWidgets.find(d => d.type === apiEntity.spec.type); }, }; diff --git a/packages/entities/wsdl-api-example.yaml b/packages/entities/wsdl-api-example.yaml index 7f4d8a0..fa4ba2c 100644 --- a/packages/entities/wsdl-api-example.yaml +++ b/packages/entities/wsdl-api-example.yaml @@ -9,3 +9,14 @@ spec: owner: foo definition: $text: http://www.dneonline.com/calculator.asmx?wsdl +--- +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: wsdl-hello-world +spec: + type: service + lifecycle: production + owner: user:development/guest + providesApis: + - wsdl-hello-world diff --git a/plugins/api-docs-module-wsdl/README.md b/plugins/api-docs-module-wsdl/README.md index ce0ee07..5b6eb95 100644 --- a/plugins/api-docs-module-wsdl/README.md +++ b/plugins/api-docs-module-wsdl/README.md @@ -36,13 +36,12 @@ export const apis: AnyApiFactory[] = [ api: apiDocsConfigRef, deps: {}, factory: () => { - // load the default widgets const definitionWidgets = defaultDefinitionWidgets(); - // add the wsdl-docs api widget to the definition widgets - definitionWidgets.push(wsdlApiWidget); return { getApiDefinitionWidget: (apiEntity: ApiEntity) => { - // find the widget for the type of api entity + if (apiEntity.spec.type.toLowerCase() === 'wsdl') { + return wsdlApiWidget(apiEntity); + } return definitionWidgets.find(d => d.type === apiEntity.spec.type); }, }; diff --git a/plugins/api-docs-module-wsdl/dev/index.tsx b/plugins/api-docs-module-wsdl/dev/index.tsx deleted file mode 100644 index a291277..0000000 --- a/plugins/api-docs-module-wsdl/dev/index.tsx +++ /dev/null @@ -1,118 +0,0 @@ -import React from 'react'; -import { createDevApp } from '@backstage/dev-utils'; -import { EntityProvider } from '@backstage/plugin-catalog-react'; -import { ApiEntity, Entity } from '@backstage/catalog-model'; -import { - apiDocsConfigRef, - apiDocsPlugin, - defaultDefinitionWidgets, - EntityApiDefinitionCard, -} from '@backstage/plugin-api-docs'; -import { - apiDocsModuleWsdlDocPlugin, - apiDocsModuleWsdlApiRef, - ApiDocsModuleWsdlClient, - wsdlApiWidget, -} from '../src'; -import { - BackstageUserIdentity, - DiscoveryApi, - IdentityApi, - ProfileInfo, -} from '@backstage/core-plugin-api'; -import { Content, Header, Page } from '@backstage/core-components'; -// @ts-ignore -import helloWsdlApiEntity from './wsdl-api.yaml'; -// @ts-ignore -import helloWsdlCalculatorApiEntity from './wsdl-calculator.yaml'; -// @ts-ignore -import helloComplexWsdlApiEntity from './wsdl-complex-api.yaml'; - -const localDiscoveryApi: DiscoveryApi = { - async getBaseUrl(pluginId: string): Promise { - return `http://localhost:7007/api/${pluginId}`; - }, -}; - -const localIdentityApi: IdentityApi = { - async getCredentials(): Promise<{ token?: string }> { - return {}; - }, - getProfileInfo(): Promise { - throw new Error('Function not implemented.'); - }, - getBackstageIdentity(): Promise { - throw new Error('Function not implemented.'); - }, - signOut(): Promise { - throw new Error('Function not implemented.'); - }, -}; - -createDevApp() - .registerPlugin(apiDocsPlugin) - .registerApi({ - api: apiDocsConfigRef, - deps: {}, - factory: () => { - const definitionWidgets = defaultDefinitionWidgets(); - definitionWidgets.push(wsdlApiWidget); - return { - getApiDefinitionWidget: (apiEntity: ApiEntity) => { - return definitionWidgets.find(d => d.type === apiEntity.spec.type); - }, - }; - }, - }) - .registerPlugin(apiDocsModuleWsdlDocPlugin) - .registerApi({ - api: apiDocsModuleWsdlApiRef, - deps: {}, - factory: () => - new ApiDocsModuleWsdlClient({ - discoveryApi: localDiscoveryApi, - identityApi: localIdentityApi, - }), - }) - .addPage({ - title: 'Simple', - element: ( - -
- - - - - - - ), - }) - .addPage({ - title: 'Calculator', - element: ( - -
- - - - - - - ), - }) - .addPage({ - title: 'Complex', - element: ( - -
- - - - - - - ), - }) - .render(); diff --git a/plugins/api-docs-module-wsdl/dev/wsdl-api.yaml b/plugins/api-docs-module-wsdl/dev/wsdl-api.yaml deleted file mode 100644 index 2070f2a..0000000 --- a/plugins/api-docs-module-wsdl/dev/wsdl-api.yaml +++ /dev/null @@ -1,70 +0,0 @@ -apiVersion: backstage.io/v1alpha1 -kind: API -metadata: - name: hello-wsdl - description: Hello World example for WSDL -spec: - type: wsdl - lifecycle: deprecated - owner: team-a - definition: - - Doc definitions - - - Say hello request documentation - - - - - - - - - Doc portType - - Doc portType operation - - - - - - - Doc binding - - - Doc binding operation - - - Doc binding operation input - - - - - Doc binding operation output - - - - - - - Doc service - - Doc service port - - - - diff --git a/plugins/api-docs-module-wsdl/dev/wsdl-calculator.yaml b/plugins/api-docs-module-wsdl/dev/wsdl-calculator.yaml deleted file mode 100644 index 5f90ff8..0000000 --- a/plugins/api-docs-module-wsdl/dev/wsdl-calculator.yaml +++ /dev/null @@ -1,205 +0,0 @@ -apiVersion: backstage.io/v1alpha1 -kind: API -metadata: - name: hello-wsdl-calculator - description: Hello World example for WSDL -spec: - type: wsdl - lifecycle: deprecated - owner: team-a - definition: | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Adds two integers. This is a test WebService. ©DNE Online - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/api-docs-module-wsdl/dev/wsdl-complex-api.yaml b/plugins/api-docs-module-wsdl/dev/wsdl-complex-api.yaml deleted file mode 100644 index 4af7342..0000000 --- a/plugins/api-docs-module-wsdl/dev/wsdl-complex-api.yaml +++ /dev/null @@ -1,428 +0,0 @@ -apiVersion: backstage.io/v1alpha1 -kind: API -metadata: - name: hello-complex-wsdl - description: Hello World example for complex WSDL -spec: - type: wsdl - lifecycle: deprecated - owner: team-a - definition: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plugins/api-docs-module-wsdl/src/components/WsdlDefinitionWidget/WsdlDefinition.tsx b/plugins/api-docs-module-wsdl/src/components/WsdlDefinitionWidget/WsdlDefinition.tsx index 5b21858..1da6650 100644 --- a/plugins/api-docs-module-wsdl/src/components/WsdlDefinitionWidget/WsdlDefinition.tsx +++ b/plugins/api-docs-module-wsdl/src/components/WsdlDefinitionWidget/WsdlDefinition.tsx @@ -4,16 +4,15 @@ import { Alert } from '@material-ui/lab'; import { Progress } from '@backstage/core-components'; import { appThemeApiRef, useApi } from '@backstage/core-plugin-api'; import { apiDocsModuleWsdlApiRef } from '../../api'; -import { useEntity } from '@backstage/plugin-catalog-react'; -import { stringifyEntityRef } from '@backstage/catalog-model'; +import { ApiEntityV1alpha1, stringifyEntityRef } from '@backstage/catalog-model'; export type WsdlDefinitionProps = { definition: string; + entity: ApiEntityV1alpha1; }; -export const WsdlDefinition = ({ definition }: WsdlDefinitionProps) => { +export const WsdlDefinition = ({ definition, entity }: WsdlDefinitionProps) => { const apiDocsModuleWsdlDocApi = useApi(apiDocsModuleWsdlApiRef); - const { entity } = useEntity(); const appThemeApi = useApi(appThemeApiRef); const result = useAsync(() => { return apiDocsModuleWsdlDocApi.convert(stringifyEntityRef(entity)); diff --git a/plugins/api-docs-module-wsdl/src/components/WsdlDefinitionWidget/WsdlDefinitionWidget.tsx b/plugins/api-docs-module-wsdl/src/components/WsdlDefinitionWidget/WsdlDefinitionWidget.tsx index 8236ff5..d14a137 100644 --- a/plugins/api-docs-module-wsdl/src/components/WsdlDefinitionWidget/WsdlDefinitionWidget.tsx +++ b/plugins/api-docs-module-wsdl/src/components/WsdlDefinitionWidget/WsdlDefinitionWidget.tsx @@ -1,5 +1,6 @@ import { Progress } from '@backstage/core-components'; import React, { Suspense } from 'react'; +import { ApiEntityV1alpha1 } from '@backstage/catalog-model'; // The widget will convert WSDL markup to HTML so only load it if necessary const LazyWsdlDefinition = React.lazy(() => @@ -11,6 +12,7 @@ const LazyWsdlDefinition = React.lazy(() => /** @public */ export type WsdlDefinitionWidgetProps = { definition: string; + entity: ApiEntityV1alpha1; }; /** @public */ diff --git a/plugins/api-docs-module-wsdl/src/widgets.tsx b/plugins/api-docs-module-wsdl/src/widgets.tsx index 290238d..5b3e503 100644 --- a/plugins/api-docs-module-wsdl/src/widgets.tsx +++ b/plugins/api-docs-module-wsdl/src/widgets.tsx @@ -1,13 +1,14 @@ import React from 'react'; import { WsdlDefinitionWidget } from './components/WsdlDefinitionWidget'; +import { ApiEntityV1alpha1 } from '@backstage/catalog-model'; /** * @public */ -export const wsdlApiWidget = { +export const wsdlApiWidget = (apiEntity: ApiEntityV1alpha1) => ({ type: 'wsdl', title: 'WSDL', component: (definition: string) => ( - + ), -}; +});