Skip to content

Commit

Permalink
[ResponseOps][Rules] OAS schema registration for newly versioned Rule…
Browse files Browse the repository at this point in the history
… APIs (#189153)

## Summary

Issue:  #187574

This PR updates `request` and `response` schemas below for rule APIs to
generate OAS documentation:
- `POST /api/alerting/rule/{id?}/_enable`
- `POST /api/alerting/rule/{id?}/_disable`
- `POST /api/alerting/rule/{id?}/_update_api_key`


### How to test

1. Start ES
2. Add `server.oas.enabled: true` to `kibana.dev.yml`
3. Start Kibana `yarn start --no-base-path`
4. `curl -s -u elastic:changeme
http://localhost:5601/api/oas\?pathStartsWith\=/api/alerting/rule/ | jq`
5. Look for `_enable`, `_disable` and `_update_api_key` in the resulting
JSON
  • Loading branch information
adcoelho authored Jul 26, 2024
1 parent dd9e94d commit 64b45e0
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@ import { schema } from '@kbn/config-schema';
export const disableRuleRequestBodySchema = schema.nullable(
schema.maybe(
schema.object({
untrack: schema.maybe(schema.boolean({ defaultValue: false })),
untrack: schema.maybe(
schema.boolean({
defaultValue: false,
meta: {
description: "Defines whether this rule's alerts should be untracked.",
},
})
),
})
)
);

export const disableRuleRequestParamsSchema = schema.object({
id: schema.string(),
id: schema.string({
meta: {
description: 'The identifier for the rule.',
},
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
import { schema } from '@kbn/config-schema';

export const enableRuleRequestParamsSchema = schema.object({
id: schema.string(),
id: schema.string({
meta: {
description: 'The identifier for the rule.',
},
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
import { schema } from '@kbn/config-schema';

export const updateApiKeyParamsSchema = schema.object({
id: schema.string(),
id: schema.string({
meta: {
description: 'The identifier for the rule.',
},
}),
});
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { updateRuleRoute } from './rule/apis/update/update_rule_route';
import { deleteRuleRoute } from './rule/apis/delete/delete_rule_route';
import { aggregateRulesRoute } from './rule/apis/aggregate/aggregate_rules_route';
import { disableRuleRoute } from './rule/apis/disable/disable_rule_route';
import { enableRuleRoute } from './rule/apis/enable/enable_rule';
import { enableRuleRoute } from './rule/apis/enable/enable_rule_route';
import { findRulesRoute, findInternalRulesRoute } from './rule/apis/find/find_rules_route';
import { getRuleAlertSummaryRoute } from './get_rule_alert_summary';
import { getRuleExecutionLogRoute } from './get_rule_execution_log';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ export const disableRuleRoute = (
summary: 'Disable a rule',
},
validate: {
params: disableRuleRequestParamsSchemaV1,
body: disableRuleRequestBodySchemaV1,
request: {
params: disableRuleRequestParamsSchemaV1,
body: disableRuleRequestBodySchemaV1,
},
response: {
204: {
description: 'Indicates a successful call.',
},
},
},
},
router.handleLegacyErrors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { enableRuleRoute } from './enable_rule';
import { enableRuleRoute } from './enable_rule_route';
import { httpServiceMock } from '@kbn/core/server/mocks';
import { licenseStateMock } from '../../../../lib/license_state.mock';
import { mockHandlerArguments } from '../../../_mock_handler_arguments';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ export const enableRuleRoute = (
summary: 'Enable a rule',
},
validate: {
params: enableRuleRequestParamsSchemaV1,
request: {
params: enableRuleRequestParamsSchemaV1,
},
response: {
204: {
description: 'Indicates a successful call.',
},
},
},
},
router.handleLegacyErrors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export const updateRuleApiKeyRoute = (
summary: 'Update the API key for a rule',
},
validate: {
params: updateApiKeyParamsSchemaV1,
request: {
params: updateApiKeyParamsSchemaV1,
},
response: {
204: {
description: 'Indicates a successful call.',
},
},
},
},
router.handleLegacyErrors(
Expand Down

0 comments on commit 64b45e0

Please sign in to comment.