-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically generated Api documentation #86232
Merged
stacey-gammon
merged 30 commits into
elastic:master
from
stacey-gammon:2020-12-02-api-doc-generator
Feb 25, 2021
Merged
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6afa78d
auto generated mdx api doc system
stacey-gammon 92fb1d3
Fix README.md
stacey-gammon 4a9ab9b
Merge branch 'master' of https://github.com/elastic/kibana into 2020-…
stacey-gammon e8f9644
update core api docs after master merge
stacey-gammon ec953af
clean up signature
stacey-gammon 256acf6
Update packages/kbn-dev-utils/src/plugins/parse_kibana_platform_plugi…
stacey-gammon ec3598d
migrate to docs-util package
spalger eed4042
Merge pull request #16 from spalger/migrate-to-docs-util-pkg
stacey-gammon 0130534
Remove bad links
stacey-gammon 228ad7f
fix ref to release-notes and add extra dats service folder
stacey-gammon fd31239
Merge branch 'master' into 2020-12-02-api-doc-generator
kibanamachine b409734
Merge branch 'master' into 2020-12-02-api-doc-generator
kibanamachine 10f9e2a
Merge branch 'master' of https://github.com/elastic/kibana into 2020-…
stacey-gammon 1dc3d70
update name change
stacey-gammon 295831e
Merge branch 'master' of https://github.com/elastic/kibana into 2020-…
stacey-gammon 48b18c3
Update packages/kbn-docs-utils/src/api_docs/build_api_declarations/ge…
stacey-gammon 62944b4
Update packages/kbn-docs-utils/src/api_docs/utils.ts
stacey-gammon 7da2dac
Merge branch '2020-12-02-api-doc-generator' of github.com:stacey-gamm…
stacey-gammon 6b6de03
review updates 1
stacey-gammon 9fbf544
review feedback updates round 1
stacey-gammon bfff33f
Merge branch 'master' of https://github.com/elastic/kibana into 2020-…
stacey-gammon 558c404
Small refactor of extractImportReferences
kobelb f15bbf8
Merge pull request #17 from kobelb/pr/stacey-gammon/86232
stacey-gammon eafd497
Review feedback updates 2
stacey-gammon 6d1ea2d
Review update 3 plus support for links in class interface heritage cl…
stacey-gammon 65270ad
debug failing test on ci only
stacey-gammon 3ac3e3d
Merge branch 'master' of https://github.com/elastic/kibana into 2020-…
stacey-gammon 279956d
Escape regex directory path
stacey-gammon a2b63b7
Update packages/kbn-docs-utils/src/api_docs/build_api_declarations/ut…
stacey-gammon 49fbd4c
fix for commit suggestion
stacey-gammon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', 'plugin_a')]; | ||
|
||
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); | ||
}); |
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
/* | ||
* 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'; | ||
|
||
/** | ||
kobelb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* 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 parentAnchorLink Used to build a nested id for the API. If this is a top level plugin API, parentAnchorLink.apiId | ||
* will be undefined. | ||
* @param log Logs messages to console. | ||
* @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), | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stacey-gammon Hi! I realize this is, like, 3 weeks old, but...
Temperate check? How has it been? Any flags so far?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @goodroot, thanks for asking! It's going well but there are a few issues that I suspect are causing folks to not adopt and use this:
Performance. The page may even pop up an error that says "page failed to respond within x seconds". https://github.com/elastic/elastic-docs/issues/274
Link scroll positions are off and the section is not auto-expanded. https://github.com/elastic/elastic-docs/issues/262
Usage tracking and analytics: https://github.com/elastic/elastic-docs/issues/309. I'll need this to be able to prove whether these API docs are valuable. If they aren't being used much, I can dig into the why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very helpful -- thank you! I am gathering very broad information and will circle back. 🕺