mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[ML] Script to generate a content page for the ML Kibana API (#154538)
## Summary - Adds a script to generate a content page with ML Kibana API groups - Updates the `apiDocs` npm command
This commit is contained in:
parent
d9d535ee67
commit
5636060d11
4 changed files with 81 additions and 2 deletions
1
x-pack/plugins/ml/.gitignore
vendored
1
x-pack/plugins/ml/.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
scripts/apidoc_scripts/ML_API.mdx
|
||||
scripts/apidoc_scripts/ml_kibana_api.mdx
|
||||
scripts/apidoc_scripts/header.md
|
||||
apidoc_config.json
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"scripts": {
|
||||
"generateHeader": "node scripts/apidoc_scripts/header_generator/index.js",
|
||||
"generateApidocConfig": "node scripts/apidoc_scripts/apidoc_config/index.js",
|
||||
"apiDocs": "yarn generateHeader && yarn generateApidocConfig && cd ./scripts/apidoc_scripts/ && ../../../../../node_modules/.bin/apidoc-markdown -i ../../server/routes -c ./apidoc_config.json -o ./ML_API.mdx --parse-workers apischema=./schema_worker/index.js --parse-parsers apischema=./schema_parser/index.js --parse-filters apiversion=./version_filter/index.js --header ./header.md --template ./template.md"
|
||||
"generateContentPage": "node scripts/apidoc_scripts/content_page/index.js",
|
||||
"apiDocs": "yarn generateContentPage && yarn generateHeader && yarn generateApidocConfig && cd ./scripts/apidoc_scripts/ && ../../../../../node_modules/.bin/apidoc-markdown -i ../../server/routes -c ./apidoc_config.json -o ./ML_API.mdx --parse-workers apischema=./schema_worker/index.js --parse-parsers apischema=./schema_parser/index.js --parse-filters apiversion=./version_filter/index.js --header ./header.md --template ./template.md"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
// @ts-ignore can only be default-imported using the 'esModuleInterop' flag
|
||||
import moment from 'moment';
|
||||
import { kibanaPackageJson } from '@kbn/repo-info';
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import { createDoc } from 'apidoc-light';
|
||||
|
||||
interface Group {
|
||||
anchor: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
const getContent = (groups: Group[]) => {
|
||||
const groupsStr = groups
|
||||
.map(({ anchor, text }) => `- <DocLink id="uiMlApi" section="${anchor}" text="${text} API" />`)
|
||||
.join('\n');
|
||||
|
||||
return `---
|
||||
id: uiMlKibanaRestApi
|
||||
slug: /ml-team/docs/ui/rest-api/ml-kibana-rest-api
|
||||
title: Machine Learning Kibana REST API
|
||||
image: https://source.unsplash.com/400x175/?Nature
|
||||
description: This page contains documentation for the ML Kibana REST API.
|
||||
date: ${moment().format('YYYY-MM-DD')}
|
||||
tags: ['machine learning','internal docs', 'UI']
|
||||
---
|
||||
|
||||
_Updated for ${kibanaPackageJson.version}_
|
||||
|
||||
Some of the features of the Machine Learning (ML) Kibana plugin are provided via a REST API, which is ideal for creating an integration with the ML plugin.
|
||||
|
||||
Each API is experimental and can include breaking changes in any version of the ML plugin, or might have been entirely removed from the plugin.
|
||||
|
||||
- <DocLink id="uiMlApi" text="View complete API documentation" />
|
||||
|
||||
The following APIs are available:
|
||||
|
||||
${groupsStr}
|
||||
`;
|
||||
};
|
||||
|
||||
export const generateContentPage = () => {
|
||||
const doc = createDoc({
|
||||
src: path.resolve(__dirname, '..', '..', '..', 'server', 'routes'),
|
||||
config: path.resolve(__dirname, '..', 'apidoc_config', 'apidoc.json'),
|
||||
// if you don't want to generate the output files:
|
||||
dryRun: true,
|
||||
// if you don't want to see any log output:
|
||||
silent: true,
|
||||
});
|
||||
|
||||
const groups = [...new Set(doc.data.map((v) => v.group))].map((group) => {
|
||||
return {
|
||||
anchor: `-${group.toLowerCase()}`,
|
||||
text: group.replace(/([a-z])([A-Z])/g, '$1 $2'),
|
||||
};
|
||||
});
|
||||
|
||||
fs.writeFileSync(path.resolve(__dirname, '..', 'ml_kibana_api.mdx'), getContent(groups));
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* 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; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
require('../../../../../../src/setup_node_env');
|
||||
require('./content_page').generateContentPage();
|
Loading…
Add table
Add a link
Reference in a new issue