diff --git a/packages/frontend-plugin-api/src/extensions/createApiExtension.test.ts b/packages/frontend-plugin-api/src/extensions/createApiExtension.test.ts index e90c0b6b85..b2f84f05aa 100644 --- a/packages/frontend-plugin-api/src/extensions/createApiExtension.test.ts +++ b/packages/frontend-plugin-api/src/extensions/createApiExtension.test.ts @@ -26,13 +26,38 @@ describe('createApiExtension', () => { factory: () => ({ foo: 'bar' }), }); - const extension = createApiExtension({ - factory, + expect( + createApiExtension({ + factory, + }), + ).toEqual({ + $$type: '@backstage/ExtensionDefinition', + kind: 'api', + attachTo: { id: 'core', input: 'apis' }, + disabled: false, + configSchema: undefined, + inputs: {}, + output: { + api: expect.objectContaining({ + $$type: '@backstage/ExtensionDataRef', + id: 'core.api.factory', + config: {}, + }), + }, + factory: expect.any(Function), }); - expect(extension).toEqual({ - $$type: '@backstage/Extension', - id: 'apis.test', + expect( + createApiExtension({ + factory, + namespace: 'ns', + name: 'n', + }), + ).toEqual({ + $$type: '@backstage/ExtensionDefinition', + kind: 'api', + namespace: 'ns', + name: 'n', attachTo: { id: 'core', input: 'apis' }, disabled: false, configSchema: undefined, @@ -53,7 +78,6 @@ describe('createApiExtension', () => { const factory = jest.fn(() => ({ foo: 'bar' })); const extension = createApiExtension({ - api, inputs: {}, factory({ config: _config, inputs: _inputs }) { return createApiFactory({ @@ -65,8 +89,8 @@ describe('createApiExtension', () => { }); // boo expect(extension).toEqual({ - $$type: '@backstage/Extension', - id: 'apis.test', + $$type: '@backstage/ExtensionDefinition', + kind: 'api', attachTo: { id: 'core', input: 'apis' }, disabled: false, configSchema: undefined, diff --git a/packages/frontend-plugin-api/src/extensions/createApiExtension.ts b/packages/frontend-plugin-api/src/extensions/createApiExtension.ts index 7b6dded022..fb9acf0076 100644 --- a/packages/frontend-plugin-api/src/extensions/createApiExtension.ts +++ b/packages/frontend-plugin-api/src/extensions/createApiExtension.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { AnyApiFactory, AnyApiRef } from '@backstage/core-plugin-api'; +import { AnyApiFactory } from '@backstage/core-plugin-api'; import { PortableSchema } from '../schema'; import { ExtensionInputValues, @@ -28,30 +28,24 @@ import { Expand } from '../types'; export function createApiExtension< TConfig extends {}, TInputs extends AnyExtensionInputMap, ->( - options: ( - | { - api: AnyApiRef; - factory: (options: { - config: TConfig; - inputs: Expand>; - }) => AnyApiFactory; - } - | { - factory: AnyApiFactory; - } - ) & { - configSchema?: PortableSchema; - inputs?: TInputs; - }, -) { +>(options: { + factory: + | AnyApiFactory + | ((options: { + config: TConfig; + inputs: Expand>; + }) => AnyApiFactory); + namespace?: string; + name?: string; + configSchema?: PortableSchema; + inputs?: TInputs; +}) { const { factory, configSchema, inputs: extensionInputs } = options; - const apiRef = - 'api' in options ? options.api : (factory as { api: AnyApiRef }).api; - return createExtension({ - id: `apis.${apiRef.id}`, + kind: 'api', + namespace: options.namespace, + name: options.name, attachTo: { id: 'core', input: 'apis' }, inputs: extensionInputs, configSchema,