Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
CREATE_DATA_VIEW_DESCRIPTION,
} from '../../constants';
import type { DataViewSpecRestResponse } from '../route_types';
import { toApiSpec } from './util/to_api_spec';

interface CreateDataViewArgs {
dataViewsService: DataViewsService;
Expand Down Expand Up @@ -122,7 +123,7 @@ const registerCreateDataViewRouteFactory =

const responseBody: Record<string, DataViewSpecRestResponse> = {
[serviceKey]: {
...(await dataView.toSpec(toSpecParams)),
...toApiSpec(await dataView.toSpec(toSpecParams)),
namespaces: dataView.namespaces,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
INITIAL_REST_VERSION,
UPDATE_DATA_VIEW_FIELDS_DESCRIPTION,
} from '../../../constants';
import { toApiSpec } from '../util/to_api_spec';

interface UpdateFieldsArgs {
dataViewsService: DataViewsService;
Expand Down Expand Up @@ -196,7 +197,7 @@ const updateFieldsActionRouteFactory = (path: string, serviceKey: string, descri
});

const body: Record<string, DataViewSpecRestResponse> = {
[serviceKey]: await dataView.toSpec({ fieldParams: { fieldName: ['*'] } }),
[serviceKey]: toApiSpec(await dataView.toSpec({ fieldParams: { fieldName: ['*'] } })),
};

return res.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
INITIAL_REST_VERSION,
GET_DATA_VIEW_DESCRIPTION,
} from '../../constants';
import { toApiSpec } from './util/to_api_spec';

interface GetDataViewArgs {
dataViewsService: DataViewsService;
Expand Down Expand Up @@ -113,7 +114,7 @@ const getDataViewRouteFactory =

const responseBody: Record<string, DataViewSpecRestResponse> = {
[serviceKey]: {
...(await dataView.toSpec({ fieldParams: { fieldName: ['*'] } })),
...toApiSpec(await dataView.toSpec({ fieldParams: { fieldName: ['*'] } })),
namespaces: dataView.namespaces,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type { DataViewField, DataViewLazy } from '../../../../common';
import type { SERVICE_KEY_TYPE } from '../../../constants';
import { SERVICE_KEY_LEGACY, SERVICE_KEY } from '../../../constants';
import { toApiSpec } from '../util/to_api_spec';

interface ResponseFormatterArgs {
serviceKey: SERVICE_KEY_TYPE;
Expand All @@ -25,13 +26,13 @@ export const responseFormatter = async ({
const response = {
body: {
fields: fields.map((field) => field.toSpec()),
[SERVICE_KEY]: await dataView.toSpec(),
[SERVICE_KEY]: toApiSpec(await dataView.toSpec()),
},
};

const legacyResponse = {
body: {
[SERVICE_KEY_LEGACY]: await dataView.toSpec(),
[SERVICE_KEY_LEGACY]: toApiSpec(await dataView.toSpec()),
field: fields[0].toSpec(),
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
import { INITIAL_REST_VERSION } from '../../../constants';
import { indexPatternsRuntimeResponseSchema } from '../../schema';
import type { IndexPatternsRuntimeResponseType } from '../../route_types';
import { toApiSpec } from '../util/to_api_spec';

export const registerCreateScriptedFieldRoute = (
router: IRouter,
Expand Down Expand Up @@ -99,7 +100,9 @@ export const registerCreateScriptedFieldRoute = (

const body: IndexPatternsRuntimeResponseType = {
field: fieldObject.toSpec(),
index_pattern: await indexPattern.toSpec({ fieldParams: { fieldName: ['*'] } }),
index_pattern: toApiSpec(
await indexPattern.toSpec({ fieldParams: { fieldName: ['*'] } })
),
};

return res.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
import { INITIAL_REST_VERSION } from '../../../constants';
import { indexPatternsRuntimeResponseSchema } from '../../schema';
import type { IndexPatternsRuntimeResponseType } from '../../route_types';
import { toApiSpec } from '../util/to_api_spec';

export const registerPutScriptedFieldRoute = (
router: IRouter,
Expand Down Expand Up @@ -94,7 +95,9 @@ export const registerPutScriptedFieldRoute = (

const body: IndexPatternsRuntimeResponseType = {
field: fieldObject.toSpec(),
index_pattern: await indexPattern.toSpec({ fieldParams: { fieldName: ['*'] } }),
index_pattern: toApiSpec(
await indexPattern.toSpec({ fieldParams: { fieldName: ['*'] } })
),
};

return res.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
import { INITIAL_REST_VERSION } from '../../../constants';
import { indexPatternsRuntimeResponseSchema } from '../../schema';
import type { IndexPatternsRuntimeResponseType } from '../../route_types';
import { toApiSpec } from '../util/to_api_spec';

export const registerUpdateScriptedFieldRoute = (
router: IRouter,
Expand Down Expand Up @@ -123,7 +124,9 @@ export const registerUpdateScriptedFieldRoute = (

const body: IndexPatternsRuntimeResponseType = {
field: fieldObject.toSpec(),
index_pattern: await indexPattern.toSpec({ fieldParams: { fieldName: ['*'] } }),
index_pattern: toApiSpec(
await indexPattern.toSpec({ fieldParams: { fieldName: ['*'] } })
),
};

return res.ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
INITIAL_REST_VERSION,
UPDATE_DATA_VIEW_DESCRIPTION,
} from '../../constants';
import { toApiSpec } from './util/to_api_spec';

const indexPatternUpdateSchema = schema.object({
title: schema.maybe(schema.string()),
Expand Down Expand Up @@ -215,7 +216,7 @@ const updateDataViewRouteFactory =
});

const body: Record<string, DataViewSpecRestResponse> = {
[serviceKey]: await dataView.toSpec({ fieldParams: { fieldName: ['*'] } }),
[serviceKey]: toApiSpec(await dataView.toSpec({ fieldParams: { fieldName: ['*'] } })),
};

return res.ok({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { DataViewSpec } from '../../../../common';

/**
* Converts a data view spec to an API compatible spec, removing unexposed properties
* @param dataViewSpec - The data view spec to convert to an API compatible spec
* @returns The API compatible data view spec
*/
export const toApiSpec = (dataViewSpec: DataViewSpec) => {
// Exclude managed property from the spec as it's not exposed in the API currently
const { managed, ...restSpec } = dataViewSpec;
return restSpec;
};
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export const saveDiscoverSession = createInternalStateAsyncThunk(
newDataViewSpec = {
...dataViewSpec,
id: uuidv4(),
managed: false,
};

// Clear out the old data view since it's no longer needed
Expand Down
Loading