diff --git a/src/core/server/saved_objects/routes/copy.ts b/src/core/server/saved_objects/routes/copy.ts index 7bace54db583..95e79ffd40a1 100644 --- a/src/core/server/saved_objects/routes/copy.ts +++ b/src/core/server/saved_objects/routes/copy.ts @@ -1,19 +1,12 @@ /* + * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Any modifications Copyright OpenSearch Contributors. See - * GitHub history for details. */ import { schema } from '@osd/config-schema'; import { IRouter } from '../../http'; import { SavedObjectConfig } from '../saved_objects_config'; import { exportSavedObjectsToStream } from '../export'; -import { validateObjects } from './utils'; import { importSavedObjectsFromStream } from '../import'; export const registerCopyRoute = (router: IRouter, config: SavedObjectConfig) => { @@ -24,14 +17,11 @@ export const registerCopyRoute = (router: IRouter, config: SavedObjectConfig) => path: '/_copy', validate: { body: schema.object({ - objects: schema.maybe( - schema.arrayOf( - schema.object({ - type: schema.string(), - id: schema.string(), - }), - { maxSize: maxImportExportSize } - ) + objects: schema.arrayOf( + schema.object({ + type: schema.string(), + id: schema.string(), + }) ), includeReferencesDeep: schema.boolean({ defaultValue: false }), targetWorkspace: schema.string(), @@ -47,15 +37,15 @@ export const registerCopyRoute = (router: IRouter, config: SavedObjectConfig) => .getImportableAndExportableTypes() .map((t) => t.name); - if (objects) { - const validationError = validateObjects(objects, supportedTypes); - if (validationError) { - return res.badRequest({ - body: { - message: validationError, - }, - }); - } + const invalidObjects = objects.filter((obj) => !supportedTypes.includes(obj.type)); + if (invalidObjects.length) { + return res.badRequest({ + body: { + message: `Trying to copy object(s) with unsupported types: ${invalidObjects + .map((obj) => `${obj.type}:${obj.id}`) + .join(', ')}`, + }, + }); } const objectsListStream = await exportSavedObjectsToStream({ diff --git a/src/core/server/saved_objects/routes/integration_tests/copy.test.ts b/src/core/server/saved_objects/routes/integration_tests/copy.test.ts index 5ec1caf5a3f6..e8a9d83b30ea 100644 --- a/src/core/server/saved_objects/routes/integration_tests/copy.test.ts +++ b/src/core/server/saved_objects/routes/integration_tests/copy.test.ts @@ -114,7 +114,7 @@ describe(`POST ${URL}`, () => { const result = await supertest(httpSetup.server.listener).post(URL).send({}).expect(400); expect(result.body.message).toMatchInlineSnapshot( - `"[request body.targetWorkspace]: expected value of type [string] but got [undefined]"` + `"[request body.objects]: expected value of type [array] but got [undefined]"` ); }); @@ -157,7 +157,7 @@ describe(`POST ${URL}`, () => { .expect(400); expect(result.body.message).toMatchInlineSnapshot( - `"Trying to export object(s) with non-exportable types: unknown:my-pattern"` + `"Trying to copy object(s) with unsupported types: unknown:my-pattern"` ); });