Skip to content
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

Conversation

stacey-gammon
Copy link
Contributor

@stacey-gammon stacey-gammon commented Dec 17, 2020

An automated plugin API documentation system using ts-morph.

This effort is going to be broken into three PRs (of which this is the first):

  1. The code that creates the API docs. API docs NOT included, nor hooked up to CI. Run yarn build:apidocs to see the generated docs. The folder will be ignored in the first iteration (added to .gitignore).
  2. Docs generated and added.
  3. Hooked up to CI.
  • Precommit hook, detect changes, push back to dev if changes not part of their PR.

This is to make it easier to review.

How to run locally

  1. Clone elastic-docs repo locally
  2. Edit elastic-docs/config/sources.dev.json and add:
      {
      "type": "file",
      "location": "../kibana/api_docs"
    },
    {
      "type": "file",
      "location": "../kibana/packages/kbn-docs-utils/src/api_docs/tests"
    }
  1. Merge https://github.com/elastic/elastic-docs/pull/260, or, add the nav menu items manually by editing elastic-docs/config/nav-kibana-dev.ts:
    Change
    {
      category: 'API documentation',
      items: [{ id: 'kibDevDocsApiWelcome' }],
    },

to

{
      category: 'API documentation',
      items: [
        { id: 'kibDevDocsApiWelcome' },
        { id: 'kibPluginAPluginApi' },
        { id: 'kibPluginAFooPluginApi' },
        { id: 'kibActionsPluginApi' },
        { id: 'kibAdvancedSettingsPluginApi' },
        { id: 'kibAlertsPluginApi' },
        { id: 'kibApmPluginApi' },
        { id: 'kibApmOssPluginApi' },
        { id: 'kibApmPluginApi' },
        { id: 'kibBfetchPluginApi' },
        { id: 'kibCasePluginApi' },
        { id: 'kibCanvasPluginApi' },
        { id: 'kibChartsPluginApi' },
        { id: 'kibCorePluginApi' },
        { id: 'kibCoreChromePluginApi' },
        { id: 'kibCoreHttpPluginApi' },
        { id: 'kibCoreSavedObjectsPluginApi' },
        { id: 'kibDashboardPluginApi' },
        { id: 'kibDashboardEnhancedPluginApi' },
        { id: 'kibDashboardModePluginApi' },
        { id: 'kibDataPluginApi' },
        { id: 'kibDataIndexPatternsPluginApi' },
        { id: 'kibDataAutocompletePluginApi' },
        { id: 'kibDataSearchPluginApi' },
        { id: 'kibDataEnhancedPluginApi' },
        { id: 'kibDataQueryPluginApi' },
        { id: 'kibDataUiPluginApi' },
        { id: 'kibEmbeddablePluginApi' },
        { id: 'kibRuntimeFieldsPluginApi' },
      ],
    },

Note I did not add everything, but enough to get an idea.

  • Pull this PR, run yarn build:apidocs
  • To build the test files run yarn jest build_api
  • Boot up local instance of elastic-docs (yarn start) and navigate to localhost:8000

RFC: #86704

blocked on https://github.com/elastic/elastic-docs/pull/224

Screen Shot 2021-01-12 at 7 17 27 PM

Tasks

Features:

  • Covert comments with @link tags into links.
  • Group by Class, Function, etc. Ensure the rendering uses the order in the array, or pulls start/setup to the top.
  • Ingest statistics during API doc generation, like count of missing comments, count of APIs, etc.

Bugs:

  • Remove APIs with @internal tag.
  • Build the github string with kibana version to pass as source.
  • Types that are optional (string | undefined) are being marked as CompoundType, when it should use isRequired: false.
  • Interfaces not being exported.
  • Failing test about function type.
  • Create top level api_docs folder if it doesn't exist, or the script will break.
  • Clear api_docs folder every run so plugins that are deleted will have their docs deleted as well.
  • Test/fix anchor links.
  • Some core types are being lost because common types are not nested inside a common folder.

TODO elastic-docs features:

  • anchor links
  • description shown by default
  • Add known tags and map to a description. beta, alpha, experimental
  • Render descriptions with formating like back tics. This won't happen until Katie finishes switching to the Next system.

@stacey-gammon stacey-gammon force-pushed the 2020-12-02-api-doc-generator branch 9 times, most recently from a5d7318 to 5653c59 Compare December 22, 2020 16:51
@stacey-gammon stacey-gammon force-pushed the 2020-12-02-api-doc-generator branch 2 times, most recently from 66817ef to 5736ed5 Compare January 6, 2021 20:55
@stacey-gammon stacey-gammon force-pushed the 2020-12-02-api-doc-generator branch 6 times, most recently from a88a24d to 13528c0 Compare January 15, 2021 20:56
@stacey-gammon stacey-gammon force-pushed the 2020-12-02-api-doc-generator branch 5 times, most recently from 8608c87 to 5ac9c3e Compare January 28, 2021 17:32
@stacey-gammon stacey-gammon force-pushed the 2020-12-02-api-doc-generator branch 8 times, most recently from e33a748 to 300e76a Compare February 2, 2021 20:47
* 'src/plugin/data/server/file.ts' would return undefined.
* @param path
*/
export function getServiceForPath(path: string): string | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bug with getServiceForPath if we have a path like "src/plugins/embed/server/routes/public/foo/index.ts". There's only one usage of getServiceForPath https://github.com/elastic/kibana/pull/86232/files#diff-d3ce0084b5713e36ab23a452ffe50380efc2b94fda541b83b502ab752b25ecabR47 and the scope is known. Perhaps we should just pass the scope to getServiceForPath and use this to create the regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two usages, and the one in getPluginApiDocId doesn't have scope available. I added a test and refactored this. The code that has scope available is just part of that function now, and the other usage passes in the plugin directory.

@stacey-gammon
Copy link
Contributor Author

I think I covered all your comments. Also added support for links in "heritage" clauses of classes and interfaces.

Screen Shot 2021-02-23 at 6 26 43 PM

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@stacey-gammon stacey-gammon requested review from spalger and removed request for ppisljar February 24, 2021 18:29
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@stacey-gammon stacey-gammon merged commit deb555a into elastic:master Feb 25, 2021
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Feb 25, 2021
* 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@spalger.com>

* 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 <brandon.kobel@gmail.com>

* Update packages/kbn-docs-utils/src/api_docs/utils.ts

Co-authored-by: Brandon Kobel <brandon.kobel@gmail.com>

* 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@spalger.com>

* fix for commit suggestion

Co-authored-by: Spencer <email@spalger.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Brandon Kobel <brandon.kobel@gmail.com>
Co-authored-by: kobelb <brandon.kobel@elastic.co>
stacey-gammon added a commit that referenced this pull request Feb 25, 2021
* 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@spalger.com>

* 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 <brandon.kobel@gmail.com>

* Update packages/kbn-docs-utils/src/api_docs/utils.ts

Co-authored-by: Brandon Kobel <brandon.kobel@gmail.com>

* 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@spalger.com>

* fix for commit suggestion

Co-authored-by: Spencer <email@spalger.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Brandon Kobel <brandon.kobel@gmail.com>
Co-authored-by: kobelb <brandon.kobel@elastic.co>

Co-authored-by: Spencer <email@spalger.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Brandon Kobel <brandon.kobel@gmail.com>
Co-authored-by: kobelb <brandon.kobel@elastic.co>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Feb 25, 2021
* master: (38 commits)
  Fixes Cypress flake by adding pipe, click, and should (elastic#92762)
  [Discover] Fix filtering selected sidebar fields (elastic#91828)
  [ML] Fixes positions of calendar arrow buttons in start datafeed modal (elastic#92625)
  [dev/build_ts_refs] check that commit in outDirs matches mergeBase (elastic#92513)
  add dep on `@kbn/config` so it is built first
  [Expressions] [Lens] Add id and copyMetaFrom arg to mapColumn fn + add configurable onError argument to math fn (elastic#90481)
  [Lens] Fix Workspace hidden when using Safari (elastic#92616)
  [Lens] Fixes vertical alignment validation messages (elastic#91878)
  forbid x-elastic-product-origin header in elasticsearch configuration (elastic#92359)
  [Security Solution][Detections] Set default indicator path to reduce friction with new filebeat modules (elastic#92081)
  [ILM][Accessibility] Added A11y test for ILM new policy form. (elastic#92570)
  [Security Solution][Exceptions] - Fixes exceptions builder UI where invalid values can cause overwrites of other values (elastic#90634)
  Automatically generated Api documentation (elastic#86232)
  Increase index pattern select limit to 1000 (elastic#92093)
  [core.logging] Add RewriteAppender for filtering LogMeta. (elastic#91492)
  [Security Solution][Detection Rules] Update prebuilt rule threats to match schema (elastic#92281)
  [Security Solutions][Detection Engine] Fixes bug with not being able to duplicate indicator matches (elastic#92565)
  [Dashboard] Export appropriate references from byValue panels (elastic#91567)
  [Upgrade Assistant] Align code between branches (elastic#91862)
  [Security Solution][Case] Fix alerts push (elastic#91638)
  ...
@stacey-gammon stacey-gammon mentioned this pull request Feb 25, 2021
4 tasks

[RFC](../../../rfcs/text/0014_api_documentation.md)

This is an experimental api documentation system that is managed by the Kibana Tech Leads until
Copy link
Contributor

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?

Copy link
Contributor Author

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:

  1. 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

  2. Link scroll positions are off and the section is not auto-expanded. https://github.com/elastic/elastic-docs/issues/262

  3. 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.

Copy link
Contributor

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. 🕺

Comment on lines +38 to +65
// Literal types are non primitives that aren't references to other types. We add them as a more
// defined node, with children.
// If we don't want the docs to be too deeply nested we could avoid this special handling.
if (param.getTypeNode() && param.getTypeNode()!.getKind() === SyntaxKind.TypeLiteral) {
acc.push(
buildApiDeclaration(
param.getTypeNode()!,
plugins,
log,
anchorLink.pluginName,
anchorLink.scope,
anchorLink.apiName,
label
)
);
} else {
acc.push({
type: getTypeKind(param),
label,
isRequired: param.getType().isNullable() === false,
signature: extractImportReferences(param.getType().getText(), plugins, log),
description: jsDocs ? getJSDocParamComment(jsDocs, label) : [],
source: getSourceForNode(param),
});
}
return acc;
}, [] as ApiDeclaration[]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goodroot FYI for future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants