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

[Dashboards][OAS] Generate API docs for Dashboards API #199215

Merged
merged 26 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9d80b11
Generate OAS docs from Dashboards API
nickpeihl Nov 6, 2024
317f17f
Merge branch 'main' into dashboardApi_oasDocs
nickpeihl Nov 8, 2024
5a43d8f
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Nov 8, 2024
3b64884
Merge remote-tracking branch 'upstream/main' into dashboardApi_oasDocs
nickpeihl Nov 12, 2024
0f3bde4
Do not generate random values from CM schema
nickpeihl Nov 13, 2024
3b5dd3c
Merge remote-tracking branch 'upstream/main' into dashboardApi_oasDocs
nickpeihl Nov 13, 2024
f5b5a68
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Nov 13, 2024
3dff92f
Revert "Do not generate random values from CM schema"
nickpeihl Nov 13, 2024
94e7929
Reapply "Do not generate random values from CM schema"
nickpeihl Nov 13, 2024
76824f2
Harden response types
nickpeihl Nov 13, 2024
400c5b1
Merge remote-tracking branch 'refs/remotes/origin/dashboardApi_oasDoc…
nickpeihl Nov 13, 2024
b433029
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Nov 13, 2024
2f7fe15
Update oas
nickpeihl Nov 13, 2024
0d9e4e3
Merge remote-tracking branch 'refs/remotes/origin/dashboardApi_oasDoc…
nickpeihl Nov 13, 2024
524af8c
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Nov 13, 2024
424777a
Merge remote-tracking branch 'upstream/main' into dashboardApi_oasDocs
nickpeihl Nov 14, 2024
045c8bf
Merge branch 'main' into dashboardApi_oasDocs
nickpeihl Nov 14, 2024
dfe1981
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Nov 14, 2024
b3a6fd7
Add API descriptions and availability
lcawl Nov 14, 2024
94ec6f3
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Nov 14, 2024
952cafb
Merge branch 'main' into dashboardApi_oasDocs
nickpeihl Nov 18, 2024
abfffa8
Review feedback
nickpeihl Nov 27, 2024
17223bc
Merge branch 'main' into dashboardApi_oasDocs
nickpeihl Nov 27, 2024
dc450df
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Nov 27, 2024
0b115ed
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Nov 27, 2024
16a6b56
Merge branch 'main' into dashboardApi_oasDocs
nickpeihl Dec 4, 2024
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
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/checks/capture_oas_snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source .buildkite/scripts/common/util.sh
.buildkite/scripts/copy_es_snapshot_cache.sh

echo --- Capture OAS snapshot
cmd="node scripts/capture_oas_snapshot --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --include-path /api/security/role --include-path /api/spaces --include-path /api/fleet"
cmd="node scripts/capture_oas_snapshot --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --include-path /api/actions --include-path /api/security/role --include-path /api/spaces --include-path /api/fleet --include-path /api/dashboards"
if is_pr && ! is_auto_commit_disabled; then
cmd="$cmd --update"
fi
Expand Down
3,238 changes: 3,238 additions & 0 deletions oas_docs/bundle.json

Large diffs are not rendered by default.

3,238 changes: 3,238 additions & 0 deletions oas_docs/bundle.serverless.json

Large diffs are not rendered by default.

2,313 changes: 2,313 additions & 0 deletions oas_docs/output/kibana.serverless.yaml

Large diffs are not rendered by default.

2,308 changes: 2,308 additions & 0 deletions oas_docs/output/kibana.yaml

Large diffs are not rendered by default.

56 changes: 46 additions & 10 deletions src/plugins/dashboard/server/api/register_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export function registerAPIRoutes({
description: TECHNICAL_PREVIEW_WARNING,
options: {
tags: ['oas-tag:Dashboards'],
availability: {
stability: 'experimental',
},
},
});

Expand All @@ -62,7 +65,11 @@ export function registerAPIRoutes({
validate: {
request: {
params: schema.object({
id: schema.maybe(schema.string()),
id: schema.maybe(
schema.string({
meta: { description: 'A unique identifier for the dashboard.' },
})
),
}),
body: schema.object({
attributes: dashboardAttributesSchema,
Expand Down Expand Up @@ -115,10 +122,13 @@ export function registerAPIRoutes({
const updateRoute = versionedRouter.put({
path: `${PUBLIC_API_PATH}/{id}`,
access: 'public',
summary: `Update an existing dashboard.`,
summary: `Update an existing dashboard`,
description: TECHNICAL_PREVIEW_WARNING,
options: {
tags: ['oas-tag:Dashboards'],
availability: {
stability: 'experimental',
},
},
});

Expand All @@ -128,7 +138,9 @@ export function registerAPIRoutes({
validate: {
request: {
params: schema.object({
id: schema.string(),
id: schema.string({
meta: { description: 'A unique identifier for the dashboard.' },
}),
}),
body: schema.object({
attributes: dashboardAttributesSchema,
Expand Down Expand Up @@ -172,10 +184,13 @@ export function registerAPIRoutes({
const listRoute = versionedRouter.get({
path: `${PUBLIC_API_PATH}`,
access: 'public',
summary: `Get a list of dashboards.`,
summary: `Get a list of dashboards`,
description: TECHNICAL_PREVIEW_WARNING,
options: {
tags: ['oas-tag:Dashboards'],
availability: {
stability: 'experimental',
},
},
});

Expand All @@ -185,8 +200,15 @@ export function registerAPIRoutes({
validate: {
request: {
query: schema.object({
page: schema.number({ defaultValue: 1 }),
perPage: schema.maybe(schema.number()),
page: schema.number({
meta: { description: 'The page number to return.' },
nreese marked this conversation as resolved.
Show resolved Hide resolved
defaultValue: 1,
}),
perPage: schema.maybe(
Copy link
Contributor

Choose a reason for hiding this comment

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

how about including defaults in the description for when value is not provided.

Is there a max perPage value? Lets mention that as well.

Copy link
Member Author

@nickpeihl nickpeihl Nov 27, 2024

Choose a reason for hiding this comment

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

I've added a max perPage value of 1000 which matches the internal RPC default for the Dashboard listing page. abfffa8

schema.number({
meta: { description: 'The number of dashboards to display on each page.' },
})
),
}),
},
response: {
Expand Down Expand Up @@ -229,10 +251,13 @@ export function registerAPIRoutes({
const getRoute = versionedRouter.get({
path: `${PUBLIC_API_PATH}/{id}`,
access: 'public',
summary: `Get a dashboard.`,
summary: `Get a dashboard`,
description: TECHNICAL_PREVIEW_WARNING,
options: {
tags: ['oas-tag:Dashboards'],
availability: {
stability: 'experimental',
},
},
});

Expand All @@ -242,7 +267,11 @@ export function registerAPIRoutes({
validate: {
request: {
params: schema.object({
id: schema.string(),
id: schema.string({
meta: {
description: 'A unique identifier for the dashboard.',
},
}),
}),
},
response: {
Expand Down Expand Up @@ -283,10 +312,13 @@ export function registerAPIRoutes({
const deleteRoute = versionedRouter.delete({
path: `${PUBLIC_API_PATH}/{id}`,
access: 'public',
summary: `Delete a dashboard.`,
summary: `Delete a dashboard`,
description: TECHNICAL_PREVIEW_WARNING,
options: {
tags: ['oas-tag:Dashboards'],
availability: {
stability: 'experimental',
},
},
});

Expand All @@ -296,7 +328,11 @@ export function registerAPIRoutes({
validate: {
request: {
params: schema.object({
id: schema.string(),
id: schema.string({
meta: {
description: 'A unique identifier for the dashboard.',
},
}),
}),
},
},
Expand Down
43 changes: 29 additions & 14 deletions src/plugins/dashboard/server/content_management/v3/cm_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { v4 as uuidv4 } from 'uuid';
import { schema, Type } from '@kbn/config-schema';
import { createOptionsSchemas, updateOptionsSchema } from '@kbn/content-management-utils';
import type { ContentManagementServicesDefinition as ServicesDefinition } from '@kbn/object-versioning';
Expand Down Expand Up @@ -50,10 +49,11 @@ export const controlGroupInputSchema = schema.object({
{
type: schema.string({ meta: { description: 'The type of the control panel.' } }),
controlConfig: schema.maybe(schema.recordOf(schema.string(), schema.any())),
id: schema.string({
defaultValue: uuidv4(),
meta: { description: 'The unique ID of the control.' },
}),
id: schema.maybe(
schema.string({
meta: { description: 'The unique ID of the control.' },
})
),
order: schema.number({
meta: {
description: 'The order of the control panel in the control group.',
Expand Down Expand Up @@ -243,10 +243,11 @@ export const gridDataSchema = schema.object({
min: 1,
meta: { description: 'The height of the panel in grid units' },
}),
i: schema.string({
meta: { description: 'The unique identifier of the panel' },
defaultValue: uuidv4(),
}),
i: schema.maybe(
schema.string({
meta: { description: 'The unique identifier of the panel' },
})
),
});

export const panelSchema = schema.object({
Expand Down Expand Up @@ -284,10 +285,11 @@ export const panelSchema = schema.object({
type: schema.string({ meta: { description: 'The embeddable type' } }),
panelRefName: schema.maybe(schema.string()),
gridData: gridDataSchema,
panelIndex: schema.string({
meta: { description: 'The unique ID of the panel.' },
defaultValue: schema.siblingRef('gridData.i'),
}),
panelIndex: schema.maybe(
schema.string({
meta: { description: 'The unique ID of the panel.' },
nreese marked this conversation as resolved.
Show resolved Hide resolved
})
),
title: schema.maybe(schema.string({ meta: { description: 'The title of the panel' } })),
version: schema.maybe(
schema.string({
Expand Down Expand Up @@ -409,6 +411,19 @@ export const referenceSchema = schema.object(
{ unknowns: 'forbid' }
);

const dashboardAttributesSchemaResponse = dashboardAttributesSchema.extends({
panels: schema.arrayOf(
panelSchema.extends({
// Responses always include the panel index and gridData.i
panelIndex: schema.string(),
gridData: gridDataSchema.extends({
i: schema.string(),
}),
}),
{ defaultValue: [] }
),
});

export const dashboardItemSchema = schema.object(
{
id: schema.string(),
Expand All @@ -420,7 +435,7 @@ export const dashboardItemSchema = schema.object(
updatedBy: schema.maybe(schema.string()),
managed: schema.maybe(schema.boolean()),
error: schema.maybe(apiError),
attributes: dashboardAttributesSchema,
attributes: dashboardAttributesSchemaResponse,
references: schema.arrayOf(referenceSchema),
namespaces: schema.maybe(schema.arrayOf(schema.string())),
originId: schema.maybe(schema.string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
UpdateIn,
} from '@kbn/content-management-plugin/common';
import { SavedObjectReference } from '@kbn/core-saved-objects-api-server';
import { WithRequiredProperty } from '@kbn/utility-types';
import {
dashboardItemSchema,
controlGroupInputSchema,
Expand All @@ -40,6 +41,7 @@ export type DashboardOptions = TypeOf<typeof optionsSchema>;
// recognize this, so we need to manually extend the type here.
export type DashboardPanel = Omit<TypeOf<typeof panelSchema>, 'panelConfig'> & {
panelConfig: TypeOf<typeof panelSchema>['panelConfig'] & { [key: string]: any };
gridData: GridData;
};
export type DashboardAttributes = Omit<TypeOf<typeof dashboardAttributesSchema>, 'panels'> & {
panels: DashboardPanel[];
Expand All @@ -52,7 +54,7 @@ export type PartialDashboardItem = Omit<DashboardItem, 'attributes' | 'reference
};

export type ControlGroupAttributes = TypeOf<typeof controlGroupInputSchema>;
export type GridData = TypeOf<typeof gridDataSchema>;
export type GridData = WithRequiredProperty<TypeOf<typeof gridDataSchema>, 'i'>;

export type DashboardGetIn = GetIn<typeof CONTENT_ID>;
export type DashboardGetOut = TypeOf<typeof dashboardGetResultSchema>;
Expand Down