forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically generated Api documentation (elastic#86232)
* auto generated mdx api doc system * Fix README.md * update core api docs after master merge * clean up signature * Update packages/kbn-dev-utils/src/plugins/parse_kibana_platform_plugin.ts Co-authored-by: Spencer <[email protected]> * migrate to docs-util package * Remove bad links * fix ref to release-notes and add extra dats service folder * update name change * Update packages/kbn-docs-utils/src/api_docs/build_api_declarations/get_type_kind.ts Co-authored-by: Brandon Kobel <[email protected]> * Update packages/kbn-docs-utils/src/api_docs/utils.ts Co-authored-by: Brandon Kobel <[email protected]> * review updates 1 * review feedback updates round 1 * Small refactor of extractImportReferences * Review feedback updates 2 * Review update 3 plus support for links in class interface heritage clause * debug failing test on ci only * Escape regex directory path * Update packages/kbn-docs-utils/src/api_docs/build_api_declarations/utils.ts Co-authored-by: Spencer <[email protected]> * fix for commit suggestion Co-authored-by: Spencer <[email protected]> Co-authored-by: spalger <[email protected]> Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Brandon Kobel <[email protected]> Co-authored-by: kobelb <[email protected]>
- Loading branch information
1 parent
044de1e
commit aa368c1
Showing
85 changed files
with
4,156 additions
and
620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.aws-config.json | ||
.signing-config.json | ||
/api_docs | ||
.ackrc | ||
/.es | ||
/.chromium | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...elopment/core/server/kibana-plugin-core-server.pluginmanifest.servicefolders.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [PluginManifest](./kibana-plugin-core-server.pluginmanifest.md) > [serviceFolders](./kibana-plugin-core-server.pluginmanifest.servicefolders.md) | ||
|
||
## PluginManifest.serviceFolders property | ||
|
||
Only used for the automatically generated API documentation. Specifying service folders will cause your plugin API reference to be broken up into sub sections. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly serviceFolders?: readonly string[]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/kbn-release-notes/package.json → packages/kbn-docs-utils/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Autogenerated API documentation | ||
|
||
[RFC](../../../rfcs/text/0014_api_documentation.md) | ||
|
||
This is an experimental api documentation system that is managed by the Kibana Tech Leads until | ||
we determine the value of such a system and what kind of maintenance burder it will incur. | ||
|
||
To generate the docs run | ||
|
||
``` | ||
node scripts/build_api_docs | ||
``` |
85 changes: 85 additions & 0 deletions
85
packages/kbn-docs-utils/src/api_docs/build_api_declarations/buid_api_declaration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import Path from 'path'; | ||
import { Project, Node } from 'ts-morph'; | ||
import { ToolingLog, KibanaPlatformPlugin } from '@kbn/dev-utils'; | ||
|
||
import { TypeKind, ApiScope } from '../types'; | ||
import { getKibanaPlatformPlugin } from '../tests/kibana_platform_plugin_mock'; | ||
import { getDeclarationNodesForPluginScope } from '../get_declaration_nodes_for_plugin'; | ||
import { buildApiDeclaration } from './build_api_declaration'; | ||
import { isNamedNode } from '../tsmorph_utils'; | ||
|
||
const log = new ToolingLog({ | ||
level: 'debug', | ||
writeTo: process.stdout, | ||
}); | ||
|
||
let nodes: Node[]; | ||
let plugins: KibanaPlatformPlugin[]; | ||
|
||
function getNodeName(node: Node): string { | ||
return isNamedNode(node) ? node.getName() : ''; | ||
} | ||
|
||
beforeAll(() => { | ||
const tsConfigFilePath = Path.resolve(__dirname, '../tests/__fixtures__/src/tsconfig.json'); | ||
const project = new Project({ | ||
tsConfigFilePath, | ||
}); | ||
|
||
plugins = [getKibanaPlatformPlugin('pluginA')]; | ||
|
||
nodes = getDeclarationNodesForPluginScope(project, plugins[0], ApiScope.CLIENT, log); | ||
}); | ||
|
||
it('Test number primitive doc def', () => { | ||
const node = nodes.find((n) => getNodeName(n) === 'aNum'); | ||
expect(node).toBeDefined(); | ||
const def = buildApiDeclaration(node!, plugins, log, plugins[0].manifest.id, ApiScope.CLIENT); | ||
|
||
expect(def.type).toBe(TypeKind.NumberKind); | ||
}); | ||
|
||
it('Function type is exported as type with signature', () => { | ||
const node = nodes.find((n) => getNodeName(n) === 'FnWithGeneric'); | ||
expect(node).toBeDefined(); | ||
const def = buildApiDeclaration(node!, plugins, log, plugins[0].manifest.id, ApiScope.CLIENT); | ||
expect(def).toBeDefined(); | ||
expect(def?.type).toBe(TypeKind.TypeKind); | ||
expect(def?.signature?.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it('Test Interface Kind doc def', () => { | ||
const node = nodes.find((n) => getNodeName(n) === 'ExampleInterface'); | ||
expect(node).toBeDefined(); | ||
const def = buildApiDeclaration(node!, plugins, log, plugins[0].manifest.id, ApiScope.CLIENT); | ||
|
||
expect(def.type).toBe(TypeKind.InterfaceKind); | ||
expect(def.children).toBeDefined(); | ||
expect(def.children!.length).toBe(3); | ||
}); | ||
|
||
it('Test union export', () => { | ||
const node = nodes.find((n) => getNodeName(n) === 'aUnionProperty'); | ||
expect(node).toBeDefined(); | ||
const def = buildApiDeclaration(node!, plugins, log, plugins[0].manifest.id, ApiScope.CLIENT); | ||
expect(def.type).toBe(TypeKind.CompoundTypeKind); | ||
}); | ||
|
||
it('Function inside interface has a label', () => { | ||
const node = nodes.find((n) => getNodeName(n) === 'ExampleInterface'); | ||
expect(node).toBeDefined(); | ||
const def = buildApiDeclaration(node!, plugins, log, plugins[0].manifest.id, ApiScope.CLIENT); | ||
|
||
const fn = def!.children?.find((c) => c.label === 'aFn'); | ||
expect(fn).toBeDefined(); | ||
expect(fn?.label).toBe('aFn'); | ||
expect(fn?.type).toBe(TypeKind.FunctionKind); | ||
}); |
88 changes: 88 additions & 0 deletions
88
packages/kbn-docs-utils/src/api_docs/build_api_declarations/build_api_declaration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { Node } from 'ts-morph'; | ||
import { ToolingLog, KibanaPlatformPlugin } from '@kbn/dev-utils'; | ||
import { buildClassDec } from './build_class_dec'; | ||
import { buildFunctionDec } from './build_function_dec'; | ||
import { getCommentsFromNode } from './js_doc_utils'; | ||
import { isNamedNode } from '../tsmorph_utils'; | ||
import { AnchorLink, ApiDeclaration } from '../types'; | ||
import { buildVariableDec } from './build_variable_dec'; | ||
import { getApiSectionId } from '../utils'; | ||
import { getSourceForNode } from './utils'; | ||
import { buildTypeLiteralDec } from './build_type_literal_dec'; | ||
import { ApiScope } from '../types'; | ||
import { getSignature } from './get_signature'; | ||
import { buildInterfaceDec } from './build_interface_dec'; | ||
import { getTypeKind } from './get_type_kind'; | ||
|
||
/** | ||
* A potentially recursive function, depending on the node type, that builds a JSON like structure | ||
* that can be passed to the elastic-docs component for rendering as an API. Nodes like classes, | ||
* interfaces, objects and functions will have children for their properties, members and parameters. | ||
* | ||
* @param node The ts-morph node to build an ApiDeclaration for. | ||
* @param plugins The list of plugins registered is used for building cross plugin links by looking up | ||
* the plugin by import path. We could accomplish the same thing via a regex on the import path, but this lets us | ||
* decouple plugin path from plugin id. | ||
* @param log Logs messages to console. | ||
* @param pluginName The name of the plugin this declaration belongs to. | ||
* @param scope The scope this declaration belongs to (server, public, or common). | ||
* @param parentApiId If this declaration is nested inside another declaration, it should have a parent id. This | ||
* is used to create the anchor link to this API item. | ||
* @param name An optional name to pass through which will be used instead of node.getName, if it | ||
* exists. For some types, like Parameters, the name comes on the parent node, but we want the doc def | ||
* to be built from the TypedNode | ||
*/ | ||
export function buildApiDeclaration( | ||
node: Node, | ||
plugins: KibanaPlatformPlugin[], | ||
log: ToolingLog, | ||
pluginName: string, | ||
scope: ApiScope, | ||
parentApiId?: string, | ||
name?: string | ||
): ApiDeclaration { | ||
const apiName = name ? name : isNamedNode(node) ? node.getName() : 'Unnamed'; | ||
log.debug(`Building API Declaration for ${apiName} of kind ${node.getKindName()}`); | ||
const apiId = parentApiId ? parentApiId + '.' + apiName : apiName; | ||
const anchorLink: AnchorLink = { scope, pluginName, apiName: apiId }; | ||
|
||
if (Node.isClassDeclaration(node)) { | ||
return buildClassDec(node, plugins, anchorLink, log); | ||
} else if (Node.isInterfaceDeclaration(node)) { | ||
return buildInterfaceDec(node, plugins, anchorLink, log); | ||
} else if ( | ||
Node.isMethodSignature(node) || | ||
Node.isFunctionDeclaration(node) || | ||
Node.isMethodDeclaration(node) || | ||
Node.isConstructorDeclaration(node) | ||
) { | ||
return buildFunctionDec(node, plugins, anchorLink, log); | ||
} else if ( | ||
Node.isPropertySignature(node) || | ||
Node.isPropertyDeclaration(node) || | ||
Node.isShorthandPropertyAssignment(node) || | ||
Node.isPropertyAssignment(node) || | ||
Node.isVariableDeclaration(node) | ||
) { | ||
return buildVariableDec(node, plugins, anchorLink, log); | ||
} else if (Node.isTypeLiteralNode(node)) { | ||
return buildTypeLiteralDec(node, plugins, anchorLink, log, apiName); | ||
} | ||
|
||
return { | ||
id: getApiSectionId(anchorLink), | ||
type: getTypeKind(node), | ||
label: apiName, | ||
description: getCommentsFromNode(node), | ||
source: getSourceForNode(node), | ||
signature: getSignature(node, plugins, log), | ||
}; | ||
} |
63 changes: 63 additions & 0 deletions
63
packages/kbn-docs-utils/src/api_docs/build_api_declarations/build_arrow_fn_dec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ToolingLog, KibanaPlatformPlugin } from '@kbn/dev-utils'; | ||
|
||
import { | ||
ArrowFunction, | ||
VariableDeclaration, | ||
PropertyDeclaration, | ||
PropertySignature, | ||
ShorthandPropertyAssignment, | ||
PropertyAssignment, | ||
} from 'ts-morph'; | ||
import { getApiSectionId } from '../utils'; | ||
import { getCommentsFromNode } from './js_doc_utils'; | ||
import { AnchorLink, TypeKind } from '../types'; | ||
import { getSourceForNode } from './utils'; | ||
import { buildApiDecsForParameters } from './build_parameter_decs'; | ||
import { getSignature } from './get_signature'; | ||
import { getJSDocReturnTagComment } from './js_doc_utils'; | ||
|
||
/** | ||
* Arrow functions are handled differently than regular functions because you need the arrow function | ||
* initializer as well as the node. The initializer is where the parameters are grabbed from and the | ||
* signature, while the node has the comments and name. | ||
* | ||
* @param node | ||
* @param initializer | ||
* @param plugins | ||
* @param anchorLink | ||
* @param log | ||
*/ | ||
export function getArrowFunctionDec( | ||
node: | ||
| VariableDeclaration | ||
| PropertyDeclaration | ||
| PropertySignature | ||
| ShorthandPropertyAssignment | ||
| PropertyAssignment, | ||
initializer: ArrowFunction, | ||
plugins: KibanaPlatformPlugin[], | ||
anchorLink: AnchorLink, | ||
log: ToolingLog | ||
) { | ||
log.debug( | ||
`Getting Arrow Function doc def for node ${node.getName()} of kind ${node.getKindName()}` | ||
); | ||
return { | ||
id: getApiSectionId(anchorLink), | ||
type: TypeKind.FunctionKind, | ||
children: buildApiDecsForParameters(initializer.getParameters(), plugins, anchorLink, log), | ||
signature: getSignature(initializer, plugins, log), | ||
description: getCommentsFromNode(node), | ||
label: node.getName(), | ||
source: getSourceForNode(node), | ||
returnComment: getJSDocReturnTagComment(node), | ||
}; | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/kbn-docs-utils/src/api_docs/build_api_declarations/build_class_dec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ToolingLog, KibanaPlatformPlugin } from '@kbn/dev-utils'; | ||
import { ClassDeclaration } from 'ts-morph'; | ||
import { AnchorLink, ApiDeclaration, TypeKind } from '../types'; | ||
import { getCommentsFromNode } from './js_doc_utils'; | ||
import { buildApiDeclaration } from './build_api_declaration'; | ||
import { getSourceForNode, isPrivate } from './utils'; | ||
import { getApiSectionId } from '../utils'; | ||
import { getSignature } from './get_signature'; | ||
|
||
export function buildClassDec( | ||
node: ClassDeclaration, | ||
plugins: KibanaPlatformPlugin[], | ||
anchorLink: AnchorLink, | ||
log: ToolingLog | ||
): ApiDeclaration { | ||
return { | ||
id: getApiSectionId(anchorLink), | ||
type: TypeKind.ClassKind, | ||
label: node.getName() || 'Missing label', | ||
description: getCommentsFromNode(node), | ||
signature: getSignature(node, plugins, log), | ||
children: node.getMembers().reduce((acc, m) => { | ||
if (!isPrivate(m)) { | ||
acc.push( | ||
buildApiDeclaration( | ||
m, | ||
plugins, | ||
log, | ||
anchorLink.pluginName, | ||
anchorLink.scope, | ||
anchorLink.apiName | ||
) | ||
); | ||
} | ||
return acc; | ||
}, [] as ApiDeclaration[]), | ||
source: getSourceForNode(node), | ||
}; | ||
} |
Oops, something went wrong.