diff --git a/packages/kbn-docs-utils/src/api_docs/build_api_declarations/extract_import_refs.test.ts b/packages/kbn-docs-utils/src/api_docs/build_api_declarations/extract_import_refs.test.ts index bf8ec4f3dfce2..a757df2ece366 100644 --- a/packages/kbn-docs-utils/src/api_docs/build_api_declarations/extract_import_refs.test.ts +++ b/packages/kbn-docs-utils/src/api_docs/build_api_declarations/extract_import_refs.test.ts @@ -36,7 +36,7 @@ it('test extractImportReference', () => { expect(results[0]).toBe('(param: string) => '); expect(results[1]).toEqual({ text: 'Bar', - docId: getPluginApiDocId('plugin_a'), + docId: getPluginApiDocId('plugin_a', log), section: 'def-public.Bar', pluginId: 'pluginA', scope: ApiScope.CLIENT, @@ -52,7 +52,7 @@ it('test extractImportReference with public folder nested under server folder', expect(results.length).toBe(1); expect(results[0]).toEqual({ text: 'Bar', - docId: getPluginApiDocId('plugin_a'), + docId: getPluginApiDocId('plugin_a', log), section: 'def-server.Bar', pluginId: 'pluginA', scope: ApiScope.SERVER, diff --git a/packages/kbn-docs-utils/src/api_docs/build_api_declarations/extract_import_refs.ts b/packages/kbn-docs-utils/src/api_docs/build_api_declarations/extract_import_refs.ts index 5d8204b79f55e..1147e15a1acb6 100644 --- a/packages/kbn-docs-utils/src/api_docs/build_api_declarations/extract_import_refs.ts +++ b/packages/kbn-docs-utils/src/api_docs/build_api_declarations/extract_import_refs.ts @@ -64,7 +64,7 @@ export function extractImportReferences( texts.push({ pluginId: plugin.manifest.id, scope: getScopeFromPath(path, plugin, log), - docId: getPluginApiDocId(plugin.manifest.id, { + docId: getPluginApiDocId(plugin.manifest.id, log, { serviceFolders: plugin.manifest.serviceFolders, apiPath: path, directory: plugin.directory, diff --git a/packages/kbn-docs-utils/src/api_docs/mdx/write_plugin_mdx_docs.ts b/packages/kbn-docs-utils/src/api_docs/mdx/write_plugin_mdx_docs.ts index c72f70c36712e..b35515eb9d209 100644 --- a/packages/kbn-docs-utils/src/api_docs/mdx/write_plugin_mdx_docs.ts +++ b/packages/kbn-docs-utils/src/api_docs/mdx/write_plugin_mdx_docs.ts @@ -65,7 +65,7 @@ export function writePluginDoc(folder: string, doc: PluginApi, log: ToolingLog): let mdx = dedent(` --- -id: ${getPluginApiDocId(doc.id)} +id: ${getPluginApiDocId(doc.id, log)} slug: /kibana-dev-docs/${doc.id}PluginApi title: ${doc.id} image: https://source.unsplash.com/400x175/?github diff --git a/packages/kbn-docs-utils/src/api_docs/utils.ts b/packages/kbn-docs-utils/src/api_docs/utils.ts index af419efa62b3e..b7e1cc9de8c04 100644 --- a/packages/kbn-docs-utils/src/api_docs/utils.ts +++ b/packages/kbn-docs-utils/src/api_docs/utils.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { KibanaPlatformPlugin } from '@kbn/dev-utils'; +import { KibanaPlatformPlugin, ToolingLog } from '@kbn/dev-utils'; import { AnchorLink, ApiDeclaration, @@ -60,9 +60,9 @@ export function groupPluginApi(declarations: ApiDeclaration[]): ScopeApi { * @param path */ export function getServiceForPath(path: string, pluginDirectory: string): string | undefined { - const publicMatchGroups = path.match(`${pluginDirectory}/public\/([^\/]*)\/`); - const serverMatchGroups = path.match(`${pluginDirectory}/server\/([^\/]*)\/`); - const commonMatchGroups = path.match(`${pluginDirectory}/common\/([^\/]*)\/`); + const publicMatchGroups = path.match(`${pluginDirectory}\/public\/([^\/]*)\/`); + const serverMatchGroups = path.match(`${pluginDirectory}\/server\/([^\/]*)\/`); + const commonMatchGroups = path.match(`${pluginDirectory}\/common\/([^\/]*)\/`); if (publicMatchGroups && publicMatchGroups.length > 1) { return publicMatchGroups[1]; @@ -75,6 +75,7 @@ export function getServiceForPath(path: string, pluginDirectory: string): string export function getPluginApiDocId( id: string, + log: ToolingLog, serviceInfo?: { serviceFolders: readonly string[]; apiPath: string; @@ -85,6 +86,9 @@ export function getPluginApiDocId( const cleanName = id.replace('.', '_'); if (serviceInfo) { const serviceName = getServiceForPath(serviceInfo.apiPath, serviceInfo.directory); + log.debug( + `Service for path ${serviceInfo.apiPath} and ${serviceInfo.directory} is ${serviceName}` + ); const serviceFolder = serviceInfo.serviceFolders?.find((f) => f === serviceName); if (serviceFolder) {