Skip to content

Commit 0bd3c1a

Browse files
Merge branch '7.x' into backport/7.x/pr-90634
2 parents 99b3ef1 + 1fd58b5 commit 0bd3c1a

File tree

85 files changed

+4156
-620
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+4156
-620
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.aws-config.json
22
.signing-config.json
3+
/api_docs
34
.ackrc
45
/.es
56
/.chromium

docs/development/core/server/kibana-plugin-core-server.pluginmanifest.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Should never be used in code outside of Core but is exported for documentation p
2828
| [requiredBundles](./kibana-plugin-core-server.pluginmanifest.requiredbundles.md) | <code>readonly string[]</code> | List of plugin ids that this plugin's UI code imports modules from that are not in <code>requiredPlugins</code>. |
2929
| [requiredPlugins](./kibana-plugin-core-server.pluginmanifest.requiredplugins.md) | <code>readonly PluginName[]</code> | An optional list of the other plugins that \*\*must be\*\* installed and enabled for this plugin to function properly. |
3030
| [server](./kibana-plugin-core-server.pluginmanifest.server.md) | <code>boolean</code> | Specifies whether plugin includes some server-side specific functionality. |
31+
| [serviceFolders](./kibana-plugin-core-server.pluginmanifest.servicefolders.md) | <code>readonly string[]</code> | Only used for the automatically generated API documentation. Specifying service folders will cause your plugin API reference to be broken up into sub sections. |
3132
| [ui](./kibana-plugin-core-server.pluginmanifest.ui.md) | <code>boolean</code> | Specifies whether plugin includes some client/browser specific functionality that should be included into client bundle via <code>public/ui_plugin.js</code> file. |
3233
| [version](./kibana-plugin-core-server.pluginmanifest.version.md) | <code>string</code> | Version of the plugin. |
3334

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [PluginManifest](./kibana-plugin-core-server.pluginmanifest.md) &gt; [serviceFolders](./kibana-plugin-core-server.pluginmanifest.servicefolders.md)
4+
5+
## PluginManifest.serviceFolders property
6+
7+
Only used for the automatically generated API documentation. Specifying service folders will cause your plugin API reference to be broken up into sub sections.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
readonly serviceFolders?: readonly string[];
13+
```

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"test:ftr:runner": "node scripts/functional_test_runner",
4848
"checkLicenses": "node scripts/check_licenses --dev",
4949
"build": "node scripts/build --all-platforms",
50+
"build:apidocs": "node scripts/build_api_docs",
5051
"start": "node scripts/kibana --dev",
5152
"debug": "node --nolazy --inspect scripts/kibana --dev",
5253
"debug-break": "node --nolazy --inspect-brk scripts/kibana --dev",
@@ -364,7 +365,7 @@
364365
"@kbn/plugin-generator": "link:packages/kbn-plugin-generator",
365366
"@kbn/plugin-helpers": "link:packages/kbn-plugin-helpers",
366367
"@kbn/pm": "link:packages/kbn-pm",
367-
"@kbn/release-notes": "link:packages/kbn-release-notes",
368+
"@kbn/docs-utils": "link:packages/kbn-docs-utils",
368369
"@kbn/storybook": "link:packages/kbn-storybook",
369370
"@kbn/telemetry-tools": "link:packages/kbn-telemetry-tools",
370371
"@kbn/test": "link:packages/kbn-test",
@@ -819,6 +820,7 @@
819820
"tinycolor2": "1.4.1",
820821
"topojson-client": "3.0.0",
821822
"ts-loader": "^7.0.5",
823+
"ts-morph": "^9.1.0",
822824
"tsd": "^0.13.1",
823825
"typescript": "4.1.3",
824826
"typescript-fsa": "^3.0.0",

packages/kbn-dev-utils/src/plugins/parse_kibana_platform_plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface Manifest {
2929
server: boolean;
3030
kibanaVersion: string;
3131
version: string;
32+
serviceFolders: readonly string[];
3233
requiredPlugins: readonly string[];
3334
optionalPlugins: readonly string[];
3435
requiredBundles: readonly string[];
@@ -64,6 +65,7 @@ export function parseKibanaPlatformPlugin(manifestPath: string): KibanaPlatformP
6465
id: manifest.id,
6566
version: manifest.version,
6667
kibanaVersion: manifest.kibanaVersion || manifest.version,
68+
serviceFolders: manifest.serviceFolders || [],
6769
requiredPlugins: isValidDepsDeclaration(manifest.requiredPlugins, 'requiredPlugins'),
6870
optionalPlugins: isValidDepsDeclaration(manifest.optionalPlugins, 'optionalPlugins'),
6971
requiredBundles: isValidDepsDeclaration(manifest.requiredBundles, 'requiredBundles'),

packages/kbn-release-notes/jest.config.js renamed to packages/kbn-docs-utils/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
module.exports = {
1010
preset: '@kbn/test',
1111
rootDir: '../..',
12-
roots: ['<rootDir>/packages/kbn-release-notes'],
12+
roots: ['<rootDir>/packages/kbn-docs-utils'],
1313
};

packages/kbn-release-notes/package.json renamed to packages/kbn-docs-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@kbn/release-notes",
2+
"name": "@kbn/docs-utils",
33
"version": "1.0.0",
44
"license": "SSPL-1.0 OR Elastic License 2.0",
55
"private": "true",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Autogenerated API documentation
2+
3+
[RFC](../../../rfcs/text/0014_api_documentation.md)
4+
5+
This is an experimental api documentation system that is managed by the Kibana Tech Leads until
6+
we determine the value of such a system and what kind of maintenance burder it will incur.
7+
8+
To generate the docs run
9+
10+
```
11+
node scripts/build_api_docs
12+
```
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import Path from 'path';
10+
import { Project, Node } from 'ts-morph';
11+
import { ToolingLog, KibanaPlatformPlugin } from '@kbn/dev-utils';
12+
13+
import { TypeKind, ApiScope } from '../types';
14+
import { getKibanaPlatformPlugin } from '../tests/kibana_platform_plugin_mock';
15+
import { getDeclarationNodesForPluginScope } from '../get_declaration_nodes_for_plugin';
16+
import { buildApiDeclaration } from './build_api_declaration';
17+
import { isNamedNode } from '../tsmorph_utils';
18+
19+
const log = new ToolingLog({
20+
level: 'debug',
21+
writeTo: process.stdout,
22+
});
23+
24+
let nodes: Node[];
25+
let plugins: KibanaPlatformPlugin[];
26+
27+
function getNodeName(node: Node): string {
28+
return isNamedNode(node) ? node.getName() : '';
29+
}
30+
31+
beforeAll(() => {
32+
const tsConfigFilePath = Path.resolve(__dirname, '../tests/__fixtures__/src/tsconfig.json');
33+
const project = new Project({
34+
tsConfigFilePath,
35+
});
36+
37+
plugins = [getKibanaPlatformPlugin('pluginA')];
38+
39+
nodes = getDeclarationNodesForPluginScope(project, plugins[0], ApiScope.CLIENT, log);
40+
});
41+
42+
it('Test number primitive doc def', () => {
43+
const node = nodes.find((n) => getNodeName(n) === 'aNum');
44+
expect(node).toBeDefined();
45+
const def = buildApiDeclaration(node!, plugins, log, plugins[0].manifest.id, ApiScope.CLIENT);
46+
47+
expect(def.type).toBe(TypeKind.NumberKind);
48+
});
49+
50+
it('Function type is exported as type with signature', () => {
51+
const node = nodes.find((n) => getNodeName(n) === 'FnWithGeneric');
52+
expect(node).toBeDefined();
53+
const def = buildApiDeclaration(node!, plugins, log, plugins[0].manifest.id, ApiScope.CLIENT);
54+
expect(def).toBeDefined();
55+
expect(def?.type).toBe(TypeKind.TypeKind);
56+
expect(def?.signature?.length).toBeGreaterThan(0);
57+
});
58+
59+
it('Test Interface Kind doc def', () => {
60+
const node = nodes.find((n) => getNodeName(n) === 'ExampleInterface');
61+
expect(node).toBeDefined();
62+
const def = buildApiDeclaration(node!, plugins, log, plugins[0].manifest.id, ApiScope.CLIENT);
63+
64+
expect(def.type).toBe(TypeKind.InterfaceKind);
65+
expect(def.children).toBeDefined();
66+
expect(def.children!.length).toBe(3);
67+
});
68+
69+
it('Test union export', () => {
70+
const node = nodes.find((n) => getNodeName(n) === 'aUnionProperty');
71+
expect(node).toBeDefined();
72+
const def = buildApiDeclaration(node!, plugins, log, plugins[0].manifest.id, ApiScope.CLIENT);
73+
expect(def.type).toBe(TypeKind.CompoundTypeKind);
74+
});
75+
76+
it('Function inside interface has a label', () => {
77+
const node = nodes.find((n) => getNodeName(n) === 'ExampleInterface');
78+
expect(node).toBeDefined();
79+
const def = buildApiDeclaration(node!, plugins, log, plugins[0].manifest.id, ApiScope.CLIENT);
80+
81+
const fn = def!.children?.find((c) => c.label === 'aFn');
82+
expect(fn).toBeDefined();
83+
expect(fn?.label).toBe('aFn');
84+
expect(fn?.type).toBe(TypeKind.FunctionKind);
85+
});
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { Node } from 'ts-morph';
10+
import { ToolingLog, KibanaPlatformPlugin } from '@kbn/dev-utils';
11+
import { buildClassDec } from './build_class_dec';
12+
import { buildFunctionDec } from './build_function_dec';
13+
import { getCommentsFromNode } from './js_doc_utils';
14+
import { isNamedNode } from '../tsmorph_utils';
15+
import { AnchorLink, ApiDeclaration } from '../types';
16+
import { buildVariableDec } from './build_variable_dec';
17+
import { getApiSectionId } from '../utils';
18+
import { getSourceForNode } from './utils';
19+
import { buildTypeLiteralDec } from './build_type_literal_dec';
20+
import { ApiScope } from '../types';
21+
import { getSignature } from './get_signature';
22+
import { buildInterfaceDec } from './build_interface_dec';
23+
import { getTypeKind } from './get_type_kind';
24+
25+
/**
26+
* A potentially recursive function, depending on the node type, that builds a JSON like structure
27+
* that can be passed to the elastic-docs component for rendering as an API. Nodes like classes,
28+
* interfaces, objects and functions will have children for their properties, members and parameters.
29+
*
30+
* @param node The ts-morph node to build an ApiDeclaration for.
31+
* @param plugins The list of plugins registered is used for building cross plugin links by looking up
32+
* the plugin by import path. We could accomplish the same thing via a regex on the import path, but this lets us
33+
* decouple plugin path from plugin id.
34+
* @param log Logs messages to console.
35+
* @param pluginName The name of the plugin this declaration belongs to.
36+
* @param scope The scope this declaration belongs to (server, public, or common).
37+
* @param parentApiId If this declaration is nested inside another declaration, it should have a parent id. This
38+
* is used to create the anchor link to this API item.
39+
* @param name An optional name to pass through which will be used instead of node.getName, if it
40+
* exists. For some types, like Parameters, the name comes on the parent node, but we want the doc def
41+
* to be built from the TypedNode
42+
*/
43+
export function buildApiDeclaration(
44+
node: Node,
45+
plugins: KibanaPlatformPlugin[],
46+
log: ToolingLog,
47+
pluginName: string,
48+
scope: ApiScope,
49+
parentApiId?: string,
50+
name?: string
51+
): ApiDeclaration {
52+
const apiName = name ? name : isNamedNode(node) ? node.getName() : 'Unnamed';
53+
log.debug(`Building API Declaration for ${apiName} of kind ${node.getKindName()}`);
54+
const apiId = parentApiId ? parentApiId + '.' + apiName : apiName;
55+
const anchorLink: AnchorLink = { scope, pluginName, apiName: apiId };
56+
57+
if (Node.isClassDeclaration(node)) {
58+
return buildClassDec(node, plugins, anchorLink, log);
59+
} else if (Node.isInterfaceDeclaration(node)) {
60+
return buildInterfaceDec(node, plugins, anchorLink, log);
61+
} else if (
62+
Node.isMethodSignature(node) ||
63+
Node.isFunctionDeclaration(node) ||
64+
Node.isMethodDeclaration(node) ||
65+
Node.isConstructorDeclaration(node)
66+
) {
67+
return buildFunctionDec(node, plugins, anchorLink, log);
68+
} else if (
69+
Node.isPropertySignature(node) ||
70+
Node.isPropertyDeclaration(node) ||
71+
Node.isShorthandPropertyAssignment(node) ||
72+
Node.isPropertyAssignment(node) ||
73+
Node.isVariableDeclaration(node)
74+
) {
75+
return buildVariableDec(node, plugins, anchorLink, log);
76+
} else if (Node.isTypeLiteralNode(node)) {
77+
return buildTypeLiteralDec(node, plugins, anchorLink, log, apiName);
78+
}
79+
80+
return {
81+
id: getApiSectionId(anchorLink),
82+
type: getTypeKind(node),
83+
label: apiName,
84+
description: getCommentsFromNode(node),
85+
source: getSourceForNode(node),
86+
signature: getSignature(node, plugins, log),
87+
};
88+
}

0 commit comments

Comments
 (0)