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

[ML] Extract apiDoc params from the schema definitions #62933

Merged
merged 31 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
011edc2
[ML] WIP apiDoc schema extractor
darnautov Apr 6, 2020
4ef204c
[ML] extract actual type
darnautov Apr 6, 2020
95827f7
[ML] refactor schema definitions
darnautov Apr 8, 2020
4230d93
[ML] Update README.md
darnautov Apr 8, 2020
4cd0f09
[ML] extract nested
darnautov Apr 8, 2020
1108ecf
[ML] call job validation endpoint with complete payload
darnautov Apr 9, 2020
afbd0c7
[ML] escape special chars and fix line breaks
darnautov Apr 9, 2020
9c45092
[ML] clean up extractDocEntries
darnautov Apr 9, 2020
abebb69
[ML] serializeWithType
darnautov Apr 9, 2020
d50da55
[ML] add missing annotations
darnautov Apr 9, 2020
2ff4843
[ML] fix parent schema assigment
darnautov Apr 9, 2020
0a03db4
[ML] support object composition
darnautov Apr 10, 2020
e3ee24e
Merge remote-tracking branch 'upstream/master' into ML-apiDoc-gen
darnautov Apr 10, 2020
2d37294
[ML] support multiple schemas per block
darnautov Apr 10, 2020
78cf4c9
[ML] fix for collections
darnautov Apr 10, 2020
ba69cf9
Merge branch 'master' into ML-apiDoc-gen
elasticmachine Apr 14, 2020
e9ee5f2
[ML] fix calendarIdsSchema
darnautov Apr 14, 2020
65b1ef4
[ML] add ml package.json with apidoc commands
darnautov Apr 14, 2020
af0de0e
Merge remote-tracking branch 'upstream/master' into ML-apiDoc-gen
darnautov Apr 14, 2020
cb3e285
[ML] use the single output markdown file
darnautov Apr 14, 2020
ec9f680
[ML] fix typo
darnautov Apr 14, 2020
7ac83a4
[ML] change the Calendars order
darnautov Apr 14, 2020
2195ecb
[ML] adjust the order in adidoc.json
darnautov Apr 14, 2020
ab83920
[ML] update api version
darnautov Apr 15, 2020
b05b7bd
Merge branch 'master' into ML-apiDoc-gen
elasticmachine Apr 15, 2020
ee5c26c
[ML] update tsconfig.json include
darnautov Apr 15, 2020
d4b7b54
Merge remote-tracking branch 'origin/ML-apiDoc-gen' into ML-apiDoc-gen
darnautov Apr 15, 2020
9651853
[ML] update packages/kbn-pm/dist/index.js
darnautov Apr 15, 2020
f429087
[ML] update ML overrides in .eslintrc.js
darnautov Apr 15, 2020
07f0680
[ML] yarn.lock symlink
darnautov Apr 15, 2020
0160f0c
Revert "[ML] yarn.lock symlink"
darnautov Apr 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,15 @@ module.exports = {
* ML overrides
*/
{
files: ['x-pack/legacy/plugins/ml/**/*.js'],
files: ['x-pack/plugins/ml/**/*.js'],
rules: {
'no-shadow': 'error',
'import/no-extraneous-dependencies': [
'error',
{
packageDir: './x-pack',
},
],
},
},

Expand Down
31 changes: 12 additions & 19 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42623,28 +42623,21 @@ module.exports = require("tty");
const os = __webpack_require__(11);
const hasFlag = __webpack_require__(12);

const {env} = process;
const env = process.env;

let forceColor;
if (hasFlag('no-color') ||
hasFlag('no-colors') ||
hasFlag('color=false') ||
hasFlag('color=never')) {
forceColor = 0;
hasFlag('color=false')) {
forceColor = false;
} else if (hasFlag('color') ||
hasFlag('colors') ||
hasFlag('color=true') ||
hasFlag('color=always')) {
forceColor = 1;
forceColor = true;
}
if ('FORCE_COLOR' in env) {
if (env.FORCE_COLOR === true || env.FORCE_COLOR === 'true') {
forceColor = 1;
} else if (env.FORCE_COLOR === false || env.FORCE_COLOR === 'false') {
forceColor = 0;
} else {
forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
}
forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
}

function translateLevel(level) {
Expand All @@ -42661,7 +42654,7 @@ function translateLevel(level) {
}

function supportsColor(stream) {
if (forceColor === 0) {
if (forceColor === false) {
return 0;
}

Expand All @@ -42675,15 +42668,11 @@ function supportsColor(stream) {
return 2;
}

if (stream && !stream.isTTY && forceColor === undefined) {
if (stream && !stream.isTTY && forceColor !== true) {
return 0;
}

const min = forceColor || 0;

if (env.TERM === 'dumb') {
return min;
}
const min = forceColor ? 1 : 0;

if (process.platform === 'win32') {
// Node.js 7.5.0 is the first version of Node.js to include a patch to
Expand Down Expand Up @@ -42744,6 +42733,10 @@ function supportsColor(stream) {
return 1;
}

if (env.TERM === 'dumb') {
return min;
}

return min;
}

Expand Down
15 changes: 15 additions & 0 deletions x-pack/plugins/ml/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"author": "Elastic",
"name": "ml",
"version": "0.0.0",
"private": true,
"license": "Elastic-License",
"scripts": {
"build:apiDocScripts": "cd server/routes/apidoc_scripts && tsc",
"apiDocs": "yarn build:apiDocScripts && cd ./server/routes/ && apidoc --parse-workers apischema=./apidoc_scripts/target/schema_worker.js --parse-parsers apischema=./apidoc_scripts/target/schema_parser.js --parse-filters apiversion=./apidoc_scripts/target/version_filter.js -i . -o ../routes_doc && apidoc-markdown -p ../routes_doc -o ../routes_doc/ML_API.md"
},
"devDependencies": {
"apidoc": "^0.20.1",
"apidoc-markdown": "^5.0.0"
}
}
11 changes: 7 additions & 4 deletions x-pack/plugins/ml/server/routes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ Each route handler requires [apiDoc](https://github.com/apidoc/apidoc) annotatio
to generate documentation.
The [apidoc-markdown](https://github.com/rigwild/apidoc-markdown) package is also required in order to generate the markdown.

For now the process is pretty manual. You need to make sure the packages mentioned above are installed globally
to execute the following command from the directory in which this README file is located.
There are custom parser and worker (`x-pack/plugins/ml/server/routes/apidoc_scripts`) to process api schemas for each documentation entry. It's written with typescript so make sure all the scripts in the folder are compiled before executing `apidoc` command.

Make sure you have run `yarn kbn bootstrap` to get all requires dev dependencies. Then execute the following command from the ml plugin folder:
```
apidoc -i . -o ../routes_doc && apidoc-markdown -p ../routes_doc -o ../routes_doc/ML_API.md
yarn run apiDocs
```
It compiles all the required scripts and generates the documentation both in HTML and Markdown formats.


It will create a new directory `routes_doc` (next to the `routes` folder) which contains the documentation in HTML format
as well as `ML_API.md` file.
as well as `ML_API.md` file.
20 changes: 7 additions & 13 deletions x-pack/plugins/ml/server/routes/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
*/

import Boom from 'boom';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';

import { schema } from '@kbn/config-schema';
import { SecurityPluginSetup } from '../../../security/server';
import { isAnnotationsFeatureAvailable } from '../lib/check_annotations';
import { annotationServiceProvider } from '../models/annotation_service';
Expand Down Expand Up @@ -45,10 +43,7 @@ export function annotationRoutes(
* @apiName GetAnnotations
* @apiDescription Gets annotations.
*
* @apiParam {String[]} jobIds List of job IDs
* @apiParam {String} earliestMs
* @apiParam {Number} latestMs
* @apiParam {Number} maxAnnotations Max limit of annotations returned
* @apiSchema (body) getAnnotationsSchema
*
* @apiSuccess {Boolean} success
* @apiSuccess {Object} annotations
Expand All @@ -57,7 +52,7 @@ export function annotationRoutes(
{
path: '/api/ml/annotations',
validate: {
body: schema.object(getAnnotationsSchema),
body: getAnnotationsSchema,
},
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
Expand All @@ -83,14 +78,13 @@ export function annotationRoutes(
* @apiName IndexAnnotations
* @apiDescription Index the annotation.
*
* @apiParam {Object} annotation
* @apiParam {String} username
* @apiSchema (body) indexAnnotationSchema
*/
router.put(
{
path: '/api/ml/annotations/index',
validate: {
body: schema.object(indexAnnotationSchema),
body: indexAnnotationSchema,
},
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
Expand Down Expand Up @@ -124,17 +118,17 @@ export function annotationRoutes(
/**
* @apiGroup Annotations
*
* @api {delete} /api/ml/annotations/index Deletes annotation
* @api {delete} /api/ml/annotations/delete/:annotationId Deletes annotation
* @apiName DeleteAnnotation
* @apiDescription Deletes specified annotation
*
* @apiParam {String} annotationId
* @apiSchema (params) deleteAnnotationSchema
*/
router.delete(
{
path: '/api/ml/annotations/delete/{annotationId}',
validate: {
params: schema.object(deleteAnnotationSchema),
params: deleteAnnotationSchema,
},
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
Expand Down
Loading