Skip to content

Commit

Permalink
[Security Solution] Use more specific bulk action operationIds (elast…
Browse files Browse the repository at this point in the history
…ic#190040)

**Addresses:** elastic#190035

## Summary

This PR fixes `operationId` conflicts in Security Solution OpenAPI specs.

## Details

API reference documentation platform (Bump.sh) expects unique `operationId`s to build proper navigation on the documentation page. It's expected each `operationId` throughout whole Kibana since Kibana API reference documentation will contain all available API endpoints.
  • Loading branch information
maximpn authored and bryce-b committed Aug 13, 2024
1 parent 79e41af commit c82269d
Show file tree
Hide file tree
Showing 35 changed files with 229 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ paths:
description: >-
The bulk action is applied to all anonymization fields that match the
filter or to the list of anonymization fields by their IDs.
operationId: PerformBulkAction
operationId: PerformAnonymizationFieldsBulkAction
requestBody:
content:
application/json:
Expand Down Expand Up @@ -422,7 +422,7 @@ paths:
description: >-
The bulk action is applied to all prompts that match the filter or to
the list of prompts by their IDs.
operationId: PerformBulkAction
operationId: PerformPromptsBulkAction
requestBody:
content:
application/json:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ paths:
description: >-
The bulk action is applied to all anonymization fields that match the
filter or to the list of anonymization fields by their IDs.
operationId: PerformBulkAction
operationId: PerformAnonymizationFieldsBulkAction
requestBody:
content:
application/json:
Expand Down Expand Up @@ -422,7 +422,7 @@ paths:
description: >-
The bulk action is applied to all prompts that match the filter or to
the list of prompts by their IDs.
operationId: PerformBulkAction
operationId: PerformPromptsBulkAction
requestBody:
content:
application/json:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,20 @@ export const AnonymizationFieldUpdateProps = z.object({
anonymized: z.boolean().optional(),
});

export type PerformBulkActionRequestBody = z.infer<typeof PerformBulkActionRequestBody>;
export const PerformBulkActionRequestBody = z.object({
export type PerformAnonymizationFieldsBulkActionRequestBody = z.infer<
typeof PerformAnonymizationFieldsBulkActionRequestBody
>;
export const PerformAnonymizationFieldsBulkActionRequestBody = z.object({
delete: BulkActionBase.optional(),
create: z.array(AnonymizationFieldCreateProps).optional(),
update: z.array(AnonymizationFieldUpdateProps).optional(),
});
export type PerformBulkActionRequestBodyInput = z.input<typeof PerformBulkActionRequestBody>;
export type PerformAnonymizationFieldsBulkActionRequestBodyInput = z.input<
typeof PerformAnonymizationFieldsBulkActionRequestBody
>;

export type PerformBulkActionResponse = z.infer<typeof PerformBulkActionResponse>;
export const PerformBulkActionResponse = AnonymizationFieldsBulkCrudActionResponse;
export type PerformAnonymizationFieldsBulkActionResponse = z.infer<
typeof PerformAnonymizationFieldsBulkActionResponse
>;
export const PerformAnonymizationFieldsBulkActionResponse =
AnonymizationFieldsBulkCrudActionResponse;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ paths:
post:
x-codegen-enabled: true
x-labels: [ess, serverless]
operationId: PerformBulkAction
operationId: PerformAnonymizationFieldsBulkAction
summary: Applies a bulk action to multiple anonymization fields
description: The bulk action is applied to all anonymization fields that match the filter or to the list of anonymization fields by their IDs.
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,17 @@ export const PromptUpdateProps = z.object({
consumer: z.string().optional(),
});

export type PerformBulkActionRequestBody = z.infer<typeof PerformBulkActionRequestBody>;
export const PerformBulkActionRequestBody = z.object({
export type PerformPromptsBulkActionRequestBody = z.infer<
typeof PerformPromptsBulkActionRequestBody
>;
export const PerformPromptsBulkActionRequestBody = z.object({
delete: BulkActionBase.optional(),
create: z.array(PromptCreateProps).optional(),
update: z.array(PromptUpdateProps).optional(),
});
export type PerformBulkActionRequestBodyInput = z.input<typeof PerformBulkActionRequestBody>;
export type PerformPromptsBulkActionRequestBodyInput = z.input<
typeof PerformPromptsBulkActionRequestBody
>;

export type PerformBulkActionResponse = z.infer<typeof PerformBulkActionResponse>;
export const PerformBulkActionResponse = PromptsBulkCrudActionResponse;
export type PerformPromptsBulkActionResponse = z.infer<typeof PerformPromptsBulkActionResponse>;
export const PerformPromptsBulkActionResponse = PromptsBulkCrudActionResponse;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ paths:
post:
x-codegen-enabled: true
x-labels: [ess, serverless]
operationId: PerformBulkAction
operationId: PerformPromptsBulkAction
summary: Applies a bulk action to multiple prompts
description: The bulk action is applied to all prompts that match the filter or to the list of prompts by their IDs.
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import {
API_VERSIONS,
} from '@kbn/elastic-assistant-common';
import {
PerformBulkActionRequestBody,
PerformBulkActionResponse,
PerformAnonymizationFieldsBulkActionRequestBody,
PerformAnonymizationFieldsBulkActionResponse,
} from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';

export const bulkUpdateAnonymizationFields = async (
http: HttpSetup,
anonymizationFieldsActions: PerformBulkActionRequestBody,
anonymizationFieldsActions: PerformAnonymizationFieldsBulkActionRequestBody,
toasts?: IToasts
) => {
try {
const result = await http.fetch<PerformBulkActionResponse>(
const result = await http.fetch<PerformAnonymizationFieldsBulkActionResponse>(
ELASTIC_AI_ASSISTANT_ANONYMIZATION_FIELDS_URL_BULK_ACTION,
{
method: 'POST',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import {
API_VERSIONS,
} from '@kbn/elastic-assistant-common';
import {
PerformBulkActionRequestBody,
PerformBulkActionResponse,
PerformPromptsBulkActionRequestBody,
PerformPromptsBulkActionResponse,
} from '@kbn/elastic-assistant-common/impl/schemas/prompts/bulk_crud_prompts_route.gen';

export const bulkUpdatePrompts = async (
http: HttpSetup,
prompts: PerformBulkActionRequestBody,
prompts: PerformPromptsBulkActionRequestBody,
toasts?: IToasts
) => {
try {
const result = await http.fetch<PerformBulkActionResponse>(
const result = await http.fetch<PerformPromptsBulkActionResponse>(
ELASTIC_AI_ASSISTANT_PROMPTS_URL_BULK_ACTION,
{
method: 'POST',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { keyBy } from 'lodash/fp';
import { css } from '@emotion/react';
import {
PromptResponse,
PerformBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
PerformPromptsBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
} from '@kbn/elastic-assistant-common/impl/schemas/prompts/bulk_crud_prompts_route.gen';
import { ApiConfig } from '@kbn/elastic-assistant-common';
import { AIConnector } from '../../../../connectorland/connector_selector';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import {
PromptResponse,
PerformBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
PerformPromptsBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
} from '@kbn/elastic-assistant-common/impl/schemas/prompts/bulk_crud_prompts_route.gen';
import { AIConnector } from '../../../../connectorland/connector_selector';
import { Conversation } from '../../../../..';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import {
PromptResponse,
PerformBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
PerformPromptsBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
} from '@kbn/elastic-assistant-common/impl/schemas/prompts/bulk_crud_prompts_route.gen';
import { useCallback } from 'react';
import { useAssistantContext } from '../../../../..';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { EuiSetColorMethod } from '@elastic/eui/src/services/color_picker/color_
import { css } from '@emotion/react';
import {
PromptResponse,
PerformBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
PerformPromptsBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
} from '@kbn/elastic-assistant-common/impl/schemas/prompts/bulk_crud_prompts_route.gen';
import { PromptContextTemplate } from '../../../..';
import * as i18n from './translations';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EuiTitle, EuiText, EuiHorizontalRule, EuiSpacer } from '@elastic/eui';

import {
PromptResponse,
PerformBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
PerformPromptsBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
} from '@kbn/elastic-assistant-common/impl/schemas/prompts/bulk_crud_prompts_route.gen';
import * as i18n from './translations';
import { QuickPromptSettingsEditor } from './quick_prompt_editor';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {
PromptResponse,
PromptTypeEnum,
PerformBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
PerformPromptsBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
} from '@kbn/elastic-assistant-common/impl/schemas/prompts/bulk_crud_prompts_route.gen';
import { useCallback } from 'react';
import { useAssistantContext } from '../../../..';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import React, { useCallback, useEffect, useState } from 'react';
import { FindAnonymizationFieldsResponse } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/find_anonymization_fields_route.gen';
import { PerformBulkActionRequestBody } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';
import { PerformAnonymizationFieldsBulkActionRequestBody } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';
import {
PerformBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
PerformPromptsBulkActionRequestBody as PromptsPerformBulkActionRequestBody,
PromptResponse,
PromptTypeEnum,
} from '@kbn/elastic-assistant-common/impl/schemas/prompts/bulk_crud_prompts_route.gen';
Expand Down Expand Up @@ -50,9 +50,9 @@ interface UseSettingsUpdater {
setConversationsSettingsBulkActions: React.Dispatch<
React.SetStateAction<ConversationsBulkActions>
>;
anonymizationFieldsBulkActions: PerformBulkActionRequestBody;
anonymizationFieldsBulkActions: PerformAnonymizationFieldsBulkActionRequestBody;
setAnonymizationFieldsBulkActions: React.Dispatch<
React.SetStateAction<PerformBulkActionRequestBody>
React.SetStateAction<PerformAnonymizationFieldsBulkActionRequestBody>
>;
promptsBulkActions: PromptsPerformBulkActionRequestBody;
setPromptsBulkActions: React.Dispatch<React.SetStateAction<PromptsPerformBulkActionRequestBody>>;
Expand Down Expand Up @@ -99,7 +99,7 @@ export const useSettingsUpdater = (
);
// Anonymization
const [anonymizationFieldsBulkActions, setAnonymizationFieldsBulkActions] =
useState<PerformBulkActionRequestBody>({});
useState<PerformAnonymizationFieldsBulkActionRequestBody>({});
// Prompts
const [promptsBulkActions, setPromptsBulkActions] = useState<PromptsPerformBulkActionRequestBody>(
{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EuiFlexGroup, EuiHorizontalRule, EuiSpacer, EuiText, EuiTitle } from '@
import React from 'react';

import { FindAnonymizationFieldsResponse } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/find_anonymization_fields_route.gen';
import { PerformBulkActionRequestBody } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';
import { PerformAnonymizationFieldsBulkActionRequestBody } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';
import { Stats } from '../../../data_anonymization_editor/stats';
import { ContextEditor } from '../../../data_anonymization_editor/context_editor';
import * as i18n from './translations';
Expand All @@ -18,9 +18,9 @@ import { useAnonymizationListUpdate } from './use_anonymization_list_update';
export interface Props {
defaultPageSize?: number;
anonymizationFields: FindAnonymizationFieldsResponse;
anonymizationFieldsBulkActions: PerformBulkActionRequestBody;
anonymizationFieldsBulkActions: PerformAnonymizationFieldsBulkActionRequestBody;
setAnonymizationFieldsBulkActions: React.Dispatch<
React.SetStateAction<PerformBulkActionRequestBody>
React.SetStateAction<PerformAnonymizationFieldsBulkActionRequestBody>
>;
setUpdatedAnonymizationData: React.Dispatch<
React.SetStateAction<FindAnonymizationFieldsResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import { useCallback } from 'react';
import { FindAnonymizationFieldsResponse } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/find_anonymization_fields_route.gen';
import { PerformBulkActionRequestBody } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';
import { PerformAnonymizationFieldsBulkActionRequestBody } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';

import { BatchUpdateListItem } from '../../../data_anonymization_editor/context_editor/types';

interface Props {
anonymizationFields: FindAnonymizationFieldsResponse;
anonymizationFieldsBulkActions: PerformBulkActionRequestBody;
anonymizationFieldsBulkActions: PerformAnonymizationFieldsBulkActionRequestBody;
setAnonymizationFieldsBulkActions: React.Dispatch<
React.SetStateAction<PerformBulkActionRequestBody>
React.SetStateAction<PerformAnonymizationFieldsBulkActionRequestBody>
>;
setUpdatedAnonymizationData: React.Dispatch<
React.SetStateAction<FindAnonymizationFieldsResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { css } from '@emotion/react';
import { euiThemeVars } from '@kbn/ui-theme';
import {
AnonymizationFieldResponse,
PerformBulkActionRequestBody,
PerformAnonymizationFieldsBulkActionRequestBody,
} from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';
import { find, uniqBy } from 'lodash';
import { ContextEditor } from '../context_editor';
Expand Down Expand Up @@ -57,7 +57,7 @@ const SelectedPromptContextEditorModalComponent = ({ onClose, onSave, promptCont
const [contextUpdates, setContextUpdates] = React.useState<BatchUpdateListItem[]>([]);
const [selectedPromptContext, setSelectedPromptContext] = React.useState(promptContext);
const [anonymizationFieldsBulkActions, setAnonymizationFieldsBulkActions] =
useState<PerformBulkActionRequestBody>({
useState<PerformAnonymizationFieldsBulkActionRequestBody>({
create: [],
update: [],
delete: {},
Expand Down Expand Up @@ -94,7 +94,7 @@ const SelectedPromptContextEditorModalComponent = ({ onClose, onSave, promptCont
setContextUpdates((prev) => [...prev, ...updates]);

setAnonymizationFieldsBulkActions((prev) => {
return updates.reduce<PerformBulkActionRequestBody>(
return updates.reduce<PerformAnonymizationFieldsBulkActionRequestBody>(
(acc, item) => {
const persistedField = find(anonymizationFields.data, ['field', item.field]) as
| AnonymizationFieldResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
AnonymizationFieldCreateProps,
AnonymizationFieldResponse,
AnonymizationFieldUpdateProps,
PerformBulkActionRequestBody,
PerformAnonymizationFieldsBulkActionRequestBody,
} from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';
import { EsAnonymizationFieldsSchema } from '../ai_assistant_data_clients/anonymization_fields/types';

Expand Down Expand Up @@ -95,10 +95,11 @@ export const getQueryAnonymizationFieldParams = (
};
};

export const getPerformBulkActionSchemaMock = (): PerformBulkActionRequestBody => ({
create: [getQueryAnonymizationFieldParams(false) as AnonymizationFieldCreateProps],
delete: {
ids: ['99403909-ca9b-49ba-9d7a-7e5320e68d05'],
},
update: [getQueryAnonymizationFieldParams(true) as AnonymizationFieldUpdateProps],
});
export const getPerformBulkActionSchemaMock =
(): PerformAnonymizationFieldsBulkActionRequestBody => ({
create: [getQueryAnonymizationFieldParams(false) as AnonymizationFieldCreateProps],
delete: {
ids: ['99403909-ca9b-49ba-9d7a-7e5320e68d05'],
},
update: [getQueryAnonymizationFieldParams(true) as AnonymizationFieldUpdateProps],
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { estypes } from '@elastic/elasticsearch';
import { EsPromptsSchema } from '../ai_assistant_data_clients/prompts/types';
import {
PerformBulkActionRequestBody,
PerformPromptsBulkActionRequestBody,
PromptCreateProps,
PromptResponse,
PromptUpdateProps,
Expand Down Expand Up @@ -123,7 +123,7 @@ export const getQueryPromptParams = (isUpdate?: boolean): PromptCreateProps | Pr
};
};

export const getPerformBulkActionSchemaMock = (): PerformBulkActionRequestBody => ({
export const getPerformBulkActionSchemaMock = (): PerformPromptsBulkActionRequestBody => ({
create: [getQueryPromptParams(false) as PromptCreateProps],
delete: {
ids: ['99403909-ca9b-49ba-9d7a-7e5320e68d05'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
AnonymizationFieldsBulkCrudActionResponse,
AnonymizationFieldsBulkCrudActionResults,
BulkCrudActionSummary,
PerformBulkActionRequestBody,
PerformBulkActionResponse,
PerformAnonymizationFieldsBulkActionRequestBody,
PerformAnonymizationFieldsBulkActionResponse,
} from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';
import { buildRouteValidationWithZod } from '@kbn/elastic-assistant-common/impl/schemas/common';
import { ANONYMIZATION_FIELDS_TABLE_MAX_PAGE_SIZE } from '../../../common/constants';
Expand Down Expand Up @@ -132,11 +132,15 @@ export const bulkActionAnonymizationFieldsRoute = (
version: API_VERSIONS.public.v1,
validate: {
request: {
body: buildRouteValidationWithZod(PerformBulkActionRequestBody),
body: buildRouteValidationWithZod(PerformAnonymizationFieldsBulkActionRequestBody),
},
},
},
async (context, request, response): Promise<IKibanaResponse<PerformBulkActionResponse>> => {
async (
context,
request,
response
): Promise<IKibanaResponse<PerformAnonymizationFieldsBulkActionResponse>> => {
const { body } = request;
const assistantResponse = buildResponse(response);

Expand Down
Loading

0 comments on commit c82269d

Please sign in to comment.