From 7e809bd68b529f18b7e41a105555d9ac266c692a Mon Sep 17 00:00:00 2001 From: Devin Hurley Date: Wed, 27 Nov 2024 15:11:31 -0500 Subject: [PATCH 01/13] initial tests and changes --- packages/kbn-openapi-common/jest.config.js | 14 +++++++++++ .../schemas/primitives.gen.test.ts | 24 +++++++++++++++++++ .../schemas/primitives.gen.ts | 1 + 3 files changed, 39 insertions(+) create mode 100644 packages/kbn-openapi-common/jest.config.js create mode 100644 packages/kbn-openapi-common/schemas/primitives.gen.test.ts diff --git a/packages/kbn-openapi-common/jest.config.js b/packages/kbn-openapi-common/jest.config.js new file mode 100644 index 0000000000000..c8e533f9d7ed8 --- /dev/null +++ b/packages/kbn-openapi-common/jest.config.js @@ -0,0 +1,14 @@ +/* + * 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". + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../..', + roots: ['/packages/kbn-openapi-common'], +}; diff --git a/packages/kbn-openapi-common/schemas/primitives.gen.test.ts b/packages/kbn-openapi-common/schemas/primitives.gen.test.ts new file mode 100644 index 0000000000000..27142719819da --- /dev/null +++ b/packages/kbn-openapi-common/schemas/primitives.gen.test.ts @@ -0,0 +1,24 @@ +/* + * 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 { NonEmptyString } from './primitives.gen'; + +describe('NonEmptyString', () => { + test('accepts newline chars', () => { + expect(() => NonEmptyString.parse('hello \nworld')).not.toThrow(); + }); + test('rejects comment with just spaces', () => { + expect(() => NonEmptyString.parse(' ')).toThrow(); + }); + test('accepts null', () => { + expect(() => NonEmptyString.parse(null)).not.toThrow(); + }); + test('accepts undefined', () => { + expect(() => NonEmptyString.parse(undefined)).not.toThrow(); + }); +}); diff --git a/packages/kbn-openapi-common/schemas/primitives.gen.ts b/packages/kbn-openapi-common/schemas/primitives.gen.ts index 4f8b19495022d..e3c861ceb8b6e 100644 --- a/packages/kbn-openapi-common/schemas/primitives.gen.ts +++ b/packages/kbn-openapi-common/schemas/primitives.gen.ts @@ -25,6 +25,7 @@ export type NonEmptyString = z.infer; export const NonEmptyString = z .string() .min(1) + // .refine((data) => data.trim() !== '', { message: 'cannot allow empty comment' }); .regex(/^(?! *$).+$/); /** From 376ae06f96c45f136ee637acf3eec8dab762d5a6 Mon Sep 17 00:00:00 2001 From: Devin Hurley Date: Tue, 3 Dec 2024 12:06:29 -0500 Subject: [PATCH 02/13] provide custom validation for non empty strings in openapi and zod --- .../schemas/primitives.gen.ts | 7 +- .../schemas/primitives.schema.yaml | 4 +- ...mitives.gen.test.ts => primitives.test.ts} | 6 -- .../templates/zod_operation_schema.handlebars | 2 +- .../templates/zod_schema_item.handlebars | 3 + .../kbn-zod-helpers/src/is_valid_date_math.ts | 9 +++ .../items/create_exception_list_items.ts | 80 +++++++++++++++++++ .../items/find_exception_list_items.ts | 47 +++++++++++ 8 files changed, 145 insertions(+), 13 deletions(-) rename packages/kbn-openapi-common/schemas/{primitives.gen.test.ts => primitives.test.ts} (79%) diff --git a/packages/kbn-openapi-common/schemas/primitives.gen.ts b/packages/kbn-openapi-common/schemas/primitives.gen.ts index e3c861ceb8b6e..3239afbb6e5af 100644 --- a/packages/kbn-openapi-common/schemas/primitives.gen.ts +++ b/packages/kbn-openapi-common/schemas/primitives.gen.ts @@ -17,16 +17,13 @@ */ import { z } from '@kbn/zod'; +import { isNonEmptyString } from '@kbn/zod-helpers'; /** * A string that is not empty and does not contain only whitespace */ export type NonEmptyString = z.infer; -export const NonEmptyString = z - .string() - .min(1) - // .refine((data) => data.trim() !== '', { message: 'cannot allow empty comment' }); - .regex(/^(?! *$).+$/); +export const NonEmptyString = z.string().min(1).superRefine(isNonEmptyString); /** * A universally unique identifier diff --git a/packages/kbn-openapi-common/schemas/primitives.schema.yaml b/packages/kbn-openapi-common/schemas/primitives.schema.yaml index 177ad2ed30ecc..1244b259fd92b 100644 --- a/packages/kbn-openapi-common/schemas/primitives.schema.yaml +++ b/packages/kbn-openapi-common/schemas/primitives.schema.yaml @@ -8,8 +8,10 @@ components: schemas: NonEmptyString: type: string - pattern: ^(?! *$).+$ + # pattern: ^(?! *$).+$ minLength: 1 + # format: trim + format: nonempty description: A string that is not empty and does not contain only whitespace UUID: diff --git a/packages/kbn-openapi-common/schemas/primitives.gen.test.ts b/packages/kbn-openapi-common/schemas/primitives.test.ts similarity index 79% rename from packages/kbn-openapi-common/schemas/primitives.gen.test.ts rename to packages/kbn-openapi-common/schemas/primitives.test.ts index 27142719819da..5f781791c4680 100644 --- a/packages/kbn-openapi-common/schemas/primitives.gen.test.ts +++ b/packages/kbn-openapi-common/schemas/primitives.test.ts @@ -15,10 +15,4 @@ describe('NonEmptyString', () => { test('rejects comment with just spaces', () => { expect(() => NonEmptyString.parse(' ')).toThrow(); }); - test('accepts null', () => { - expect(() => NonEmptyString.parse(null)).not.toThrow(); - }); - test('accepts undefined', () => { - expect(() => NonEmptyString.parse(undefined)).not.toThrow(); - }); }); diff --git a/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars b/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars index 759b0d9294b8a..b3b1b72bf4154 100644 --- a/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars +++ b/packages/kbn-openapi-generator/src/template_service/templates/zod_operation_schema.handlebars @@ -9,7 +9,7 @@ import type { ZodTypeDef } from '@kbn/zod'; import { z } from '@kbn/zod'; -import { requiredOptional, isValidDateMath, ArrayFromString, BooleanFromString } from '@kbn/zod-helpers'; +import { requiredOptional, isValidDateMath, isNonEmptyString, ArrayFromString, BooleanFromString } from '@kbn/zod-helpers'; {{#each imports}} import { diff --git a/packages/kbn-openapi-generator/src/template_service/templates/zod_schema_item.handlebars b/packages/kbn-openapi-generator/src/template_service/templates/zod_schema_item.handlebars index 8e4c5aef616fb..de9b66cee31d6 100644 --- a/packages/kbn-openapi-generator/src/template_service/templates/zod_schema_item.handlebars +++ b/packages/kbn-openapi-generator/src/template_service/templates/zod_schema_item.handlebars @@ -124,5 +124,8 @@ z.unknown() {{~#if (eq format 'date-math')}}.superRefine(isValidDateMath){{/if~}} {{~#if (eq format 'uuid')}}.uuid(){{/if~}} {{~#if pattern}}.regex(/{{pattern}}/){{/if~}} + {{~#if (eq format 'trim')}}.trim(){{/if~}} + {{~#if (eq format 'nonempty')}}.superRefine(isNonEmptyString){{/if~}} + {{~/if~}} {{~/inline~}} diff --git a/packages/kbn-zod-helpers/src/is_valid_date_math.ts b/packages/kbn-zod-helpers/src/is_valid_date_math.ts index dcb015f921763..04b89eb055ac6 100644 --- a/packages/kbn-zod-helpers/src/is_valid_date_math.ts +++ b/packages/kbn-zod-helpers/src/is_valid_date_math.ts @@ -30,3 +30,12 @@ export function isValidDateMath(input: string, ctx: z.RefinementCtx) { }); } } + +export function isNonEmptyString(input: string, ctx: z.RefinementCtx) { + if (typeof input === 'string' && input.trim() === '') { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'No empty strings allowed', + }); + } +} diff --git a/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/items/create_exception_list_items.ts b/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/items/create_exception_list_items.ts index b9a602c9fbaa3..4eed89e8d83c4 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/items/create_exception_list_items.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/items/create_exception_list_items.ts @@ -68,6 +68,86 @@ export default ({ getService }: FtrProviderContext) => { ); }); + it('should create a simple exception list item with a list item id and a comment containing newline chars', async () => { + await supertest + .post(EXCEPTION_LIST_URL) + .set('kbn-xsrf', 'true') + .send(getCreateExceptionListMinimalSchemaMock()) + .expect(200); + + const { body } = await supertest + .post(EXCEPTION_LIST_ITEM_URL) + .set('kbn-xsrf', 'true') + .send({ + ...getCreateExceptionListItemMinimalSchemaMock(), + comments: [{ comment: 'hello\nworld' }], + }) + .expect(200); + + const { comments } = removeExceptionListItemServerGeneratedProperties(body); + + expect(comments?.[0]?.comment).to.eql('hello\nworld'); + }); + + it('should not create an item when the comment is empty', async () => { + await supertest + .post(EXCEPTION_LIST_URL) + .set('kbn-xsrf', 'true') + .send(getCreateExceptionListMinimalSchemaMock()) + .expect(200); + + const { body } = await supertest + .post(EXCEPTION_LIST_ITEM_URL) + .set('kbn-xsrf', 'true') + .send({ + ...getCreateExceptionListItemMinimalSchemaMock(), + comments: [{ comment: '' }], + }) + .expect(400); + expect(body.message).to.contain('No empty strings allowed'); + }); + + it('should not create an item when the comment is only newline chars', async () => { + await supertest + .post(EXCEPTION_LIST_URL) + .set('kbn-xsrf', 'true') + .send(getCreateExceptionListMinimalSchemaMock()) + .expect(200); + + const { body } = await supertest + .post(EXCEPTION_LIST_ITEM_URL) + .set('kbn-xsrf', 'true') + .send({ + ...getCreateExceptionListItemMinimalSchemaMock(), + comments: [{ comment: '\n\n\n\n' }], + }) + .expect(400); + expect(body.message).to.contain('No empty strings allowed'); + }); + + it('should create an item when the comments array is empty', async () => { + await supertest + .post(EXCEPTION_LIST_URL) + .set('kbn-xsrf', 'true') + .send(getCreateExceptionListMinimalSchemaMock()) + .expect(200); + + const { body } = await supertest + .post(EXCEPTION_LIST_ITEM_URL) + .set('kbn-xsrf', 'true') + .send({ + ...getCreateExceptionListItemMinimalSchemaMock(), + comments: [], + }) + .expect(200); + + const bodyToCompare = removeExceptionListItemServerGeneratedProperties(body); + + expect(bodyToCompare).to.eql( + getExceptionListItemResponseMockWithoutAutoGeneratedValues(await utils.getUsername()) + ); + }); + it('should create a match any exception item with multiple case sensitive values', async () => { const entries = [ { diff --git a/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/items/find_exception_list_items.ts b/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/items/find_exception_list_items.ts index 3753c63ff7693..a13f339cac37c 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/items/find_exception_list_items.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/exception_lists_items/trial_license_complete_tier/items/find_exception_list_items.ts @@ -135,6 +135,53 @@ export default ({ getService }: FtrProviderContext): void => { }); }); + it('should return matching items when search is passed in and comments have newline chars', async () => { + // create exception list + await supertest + .post(EXCEPTION_LIST_URL) + .set('kbn-xsrf', 'true') + .send(getCreateExceptionListDetectionSchemaMock()) + .expect(200); + + // create exception list items + await supertest + .post(EXCEPTION_LIST_ITEM_URL) + .set('kbn-xsrf', 'true') + .send({ + ...getCreateExceptionListItemMinimalSchemaMockWithoutId(), + list_id: getCreateExceptionListDetectionSchemaMock().list_id, + item_id: '1', + entries: [ + { field: 'host.name', value: 'some host', operator: 'included', type: 'match' }, + ], + comments: [{ comment: 'hello\nworld' }], + }) + .expect(200); + await supertest + .post(EXCEPTION_LIST_ITEM_URL) + .set('kbn-xsrf', 'true') + .send({ + ...getCreateExceptionListItemMinimalSchemaMockWithoutId(), + item_id: '2', + list_id: getCreateExceptionListDetectionSchemaMock().list_id, + entries: [{ field: 'foo', operator: 'included', type: 'exists' }], + }) + .expect(200); + + const { body } = await supertest + .get( + `${EXCEPTION_LIST_ITEM_URL}/_find?list_id=${ + getCreateExceptionListMinimalSchemaMock().list_id + }&namespace_type=single&page=1&per_page=25&search=host&sort_field=exception-list.created_at&sort_order=desc` + ) + .set('kbn-xsrf', 'true') + .send() + .expect(200); + + body.data = [removeExceptionListItemServerGeneratedProperties(body.data[0])]; + expect(body.data[0].comments[0].comment).to.eql('hello\nworld'); + }); + it('should return 404 if given a list_id that does not exist', async () => { const { body } = await supertest .get(`${EXCEPTION_LIST_ITEM_URL}/_find?list_id=non_exist`) From 416dcd3d864edac9e1dcd86fc732727ceecfd348 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:22:38 +0000 Subject: [PATCH 03/13] [CI] Auto-commit changed files from 'node scripts/notice' --- packages/kbn-openapi-common/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kbn-openapi-common/tsconfig.json b/packages/kbn-openapi-common/tsconfig.json index ca7d7e4715362..29a271ba4840d 100644 --- a/packages/kbn-openapi-common/tsconfig.json +++ b/packages/kbn-openapi-common/tsconfig.json @@ -8,5 +8,6 @@ "include": ["**/*.ts"], "kbn_references": [ "@kbn/zod", + "@kbn/zod-helpers", ] } From 8c6ec807ebc3082e1ac654999acf121402996dc8 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:30:38 +0000 Subject: [PATCH 04/13] [CI] Auto-commit changed files from 'yarn openapi:bundle' --- ...ution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml | 2 +- ...ution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml | 2 +- ...urity_solution_exceptions_api_2023_10_31.bundled.schema.yaml | 2 +- ...urity_solution_exceptions_api_2023_10_31.bundled.schema.yaml | 2 +- .../security_solution_lists_api_2023_10_31.bundled.schema.yaml | 2 +- .../security_solution_lists_api_2023_10_31.bundled.schema.yaml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/ess/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/ess/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml index 366efe23d586b..800dbf3930660 100644 --- a/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/ess/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/ess/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml @@ -847,8 +847,8 @@ components: type: string NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string PlatformErrorResponse: type: object diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/serverless/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/serverless/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml index 0ecce40ef34d3..92b597cd8a0bf 100644 --- a/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/serverless/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/serverless/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml @@ -847,8 +847,8 @@ components: type: string NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string PlatformErrorResponse: type: object diff --git a/packages/kbn-securitysolution-exceptions-common/docs/openapi/ess/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-exceptions-common/docs/openapi/ess/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml index bf290e872f915..0166c3c95821e 100644 --- a/packages/kbn-securitysolution-exceptions-common/docs/openapi/ess/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/docs/openapi/ess/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml @@ -1847,8 +1847,8 @@ components: type: string NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string PlatformErrorResponse: type: object diff --git a/packages/kbn-securitysolution-exceptions-common/docs/openapi/serverless/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-exceptions-common/docs/openapi/serverless/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml index 115658261c909..8fcae9fb348cb 100644 --- a/packages/kbn-securitysolution-exceptions-common/docs/openapi/serverless/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/docs/openapi/serverless/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml @@ -1847,8 +1847,8 @@ components: type: string NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string PlatformErrorResponse: type: object diff --git a/packages/kbn-securitysolution-lists-common/docs/openapi/ess/security_solution_lists_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-lists-common/docs/openapi/ess/security_solution_lists_api_2023_10_31.bundled.schema.yaml index 17eef19505e40..d9d892d160783 100644 --- a/packages/kbn-securitysolution-lists-common/docs/openapi/ess/security_solution_lists_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-lists-common/docs/openapi/ess/security_solution_lists_api_2023_10_31.bundled.schema.yaml @@ -1529,8 +1529,8 @@ components: type: string NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string PlatformErrorResponse: type: object diff --git a/packages/kbn-securitysolution-lists-common/docs/openapi/serverless/security_solution_lists_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-lists-common/docs/openapi/serverless/security_solution_lists_api_2023_10_31.bundled.schema.yaml index 5348d9404a0e3..8a956172ac3be 100644 --- a/packages/kbn-securitysolution-lists-common/docs/openapi/serverless/security_solution_lists_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-lists-common/docs/openapi/serverless/security_solution_lists_api_2023_10_31.bundled.schema.yaml @@ -1529,8 +1529,8 @@ components: type: string NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string PlatformErrorResponse: type: object From 1881b1bbb6068fc5e3c10a1cf1f87687996d363c Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 4 Dec 2024 01:03:24 +0000 Subject: [PATCH 05/13] [CI] Auto-commit changed files from 'make api-docs' --- oas_docs/output/kibana.serverless.yaml | 6 +++--- oas_docs/output/kibana.yaml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/oas_docs/output/kibana.serverless.yaml b/oas_docs/output/kibana.serverless.yaml index 142c0742614fb..caa7429c8324b 100644 --- a/oas_docs/output/kibana.serverless.yaml +++ b/oas_docs/output/kibana.serverless.yaml @@ -45082,8 +45082,8 @@ components: type: string Security_Endpoint_Exceptions_API_NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_Endpoint_Exceptions_API_PlatformErrorResponse: type: object @@ -46568,8 +46568,8 @@ components: type: string Security_Exceptions_API_NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_Exceptions_API_PlatformErrorResponse: type: object @@ -46814,8 +46814,8 @@ components: type: string Security_Lists_API_NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_Lists_API_PlatformErrorResponse: type: object diff --git a/oas_docs/output/kibana.yaml b/oas_docs/output/kibana.yaml index 0abbcc4b4a102..e0354ec86f521 100644 --- a/oas_docs/output/kibana.yaml +++ b/oas_docs/output/kibana.yaml @@ -52808,8 +52808,8 @@ components: type: string Security_Endpoint_Exceptions_API_NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_Endpoint_Exceptions_API_PlatformErrorResponse: type: object @@ -54294,8 +54294,8 @@ components: type: string Security_Exceptions_API_NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_Exceptions_API_PlatformErrorResponse: type: object @@ -54540,8 +54540,8 @@ components: type: string Security_Lists_API_NonEmptyString: description: A string that is not empty and does not contain only whitespace + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_Lists_API_PlatformErrorResponse: type: object From a8f342823aac4f2074d6663ccda04aab0d376f89 Mon Sep 17 00:00:00 2001 From: Devin Hurley Date: Wed, 4 Dec 2024 07:45:48 -0500 Subject: [PATCH 06/13] cleanup --- .../schemas/primitives.schema.yaml | 2 -- packages/kbn-zod-helpers/index.ts | 1 + .../kbn-zod-helpers/src/is_valid_date_math.ts | 9 --------- .../kbn-zod-helpers/src/non_empty_string.ts | 18 ++++++++++++++++++ 4 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 packages/kbn-zod-helpers/src/non_empty_string.ts diff --git a/packages/kbn-openapi-common/schemas/primitives.schema.yaml b/packages/kbn-openapi-common/schemas/primitives.schema.yaml index 1244b259fd92b..b6794d01f15b9 100644 --- a/packages/kbn-openapi-common/schemas/primitives.schema.yaml +++ b/packages/kbn-openapi-common/schemas/primitives.schema.yaml @@ -8,9 +8,7 @@ components: schemas: NonEmptyString: type: string - # pattern: ^(?! *$).+$ minLength: 1 - # format: trim format: nonempty description: A string that is not empty and does not contain only whitespace diff --git a/packages/kbn-zod-helpers/index.ts b/packages/kbn-zod-helpers/index.ts index cbd864e327a20..65624b7ec6c80 100644 --- a/packages/kbn-zod-helpers/index.ts +++ b/packages/kbn-zod-helpers/index.ts @@ -16,3 +16,4 @@ export * from './src/required_optional'; export * from './src/safe_parse_result'; export * from './src/stringify_zod_error'; export * from './src/build_route_validation_with_zod'; +export * from './src/non_empty_string'; diff --git a/packages/kbn-zod-helpers/src/is_valid_date_math.ts b/packages/kbn-zod-helpers/src/is_valid_date_math.ts index 04b89eb055ac6..dcb015f921763 100644 --- a/packages/kbn-zod-helpers/src/is_valid_date_math.ts +++ b/packages/kbn-zod-helpers/src/is_valid_date_math.ts @@ -30,12 +30,3 @@ export function isValidDateMath(input: string, ctx: z.RefinementCtx) { }); } } - -export function isNonEmptyString(input: string, ctx: z.RefinementCtx) { - if (typeof input === 'string' && input.trim() === '') { - ctx.addIssue({ - code: z.ZodIssueCode.custom, - message: 'No empty strings allowed', - }); - } -} diff --git a/packages/kbn-zod-helpers/src/non_empty_string.ts b/packages/kbn-zod-helpers/src/non_empty_string.ts new file mode 100644 index 0000000000000..0a02219f3e77b --- /dev/null +++ b/packages/kbn-zod-helpers/src/non_empty_string.ts @@ -0,0 +1,18 @@ +/* + * 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 * as z from '@kbn/zod'; +export function isNonEmptyString(input: string, ctx: z.RefinementCtx) { + if (typeof input === 'string' && input.trim() === '') { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'No empty strings allowed', + }); + } +} From 09b275ed9983756fbb9852d61db6b8bda03a6994 Mon Sep 17 00:00:00 2001 From: Devin Hurley Date: Wed, 4 Dec 2024 09:51:00 -0500 Subject: [PATCH 07/13] remove typeof check, possibly use the standard zod trim function instead of this? --- packages/kbn-zod-helpers/src/non_empty_string.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-zod-helpers/src/non_empty_string.ts b/packages/kbn-zod-helpers/src/non_empty_string.ts index 0a02219f3e77b..bb10ee0d3b45d 100644 --- a/packages/kbn-zod-helpers/src/non_empty_string.ts +++ b/packages/kbn-zod-helpers/src/non_empty_string.ts @@ -9,7 +9,7 @@ import * as z from '@kbn/zod'; export function isNonEmptyString(input: string, ctx: z.RefinementCtx) { - if (typeof input === 'string' && input.trim() === '') { + if (input.trim() === '') { ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'No empty strings allowed', From 3c9a456750f6ff423bdb6fae3b1f011fdeca868b Mon Sep 17 00:00:00 2001 From: Devin Hurley Date: Wed, 4 Dec 2024 22:34:33 -0500 Subject: [PATCH 08/13] update unit tests, add space between import and function declaration, declare function return type, adds format: nonempty to recommended specs --- .../schemas/primitives.schema.yaml | 2 +- .../schemas/primitives.test.ts | 34 ++++++++++++++++--- .../kbn-zod-helpers/src/non_empty_string.ts | 3 +- .../impl/schemas/common_attributes.gen.ts | 8 ++--- .../schemas/common_attributes.schema.yaml | 5 ++- .../common/api/model/primitives.gen.ts | 8 ++--- .../common/api/model/primitives.schema.yaml | 4 +-- .../siem_migrations/model/common.gen.ts | 8 ++--- .../siem_migrations/model/common.schema.yaml | 4 +-- 9 files changed, 48 insertions(+), 28 deletions(-) diff --git a/packages/kbn-openapi-common/schemas/primitives.schema.yaml b/packages/kbn-openapi-common/schemas/primitives.schema.yaml index b6794d01f15b9..0120a64e2afee 100644 --- a/packages/kbn-openapi-common/schemas/primitives.schema.yaml +++ b/packages/kbn-openapi-common/schemas/primitives.schema.yaml @@ -10,7 +10,7 @@ components: type: string minLength: 1 format: nonempty - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace UUID: type: string diff --git a/packages/kbn-openapi-common/schemas/primitives.test.ts b/packages/kbn-openapi-common/schemas/primitives.test.ts index 5f781791c4680..b83f5e6d34637 100644 --- a/packages/kbn-openapi-common/schemas/primitives.test.ts +++ b/packages/kbn-openapi-common/schemas/primitives.test.ts @@ -9,10 +9,36 @@ import { NonEmptyString } from './primitives.gen'; describe('NonEmptyString', () => { - test('accepts newline chars', () => { - expect(() => NonEmptyString.parse('hello \nworld')).not.toThrow(); + describe('accepts ', () => { + // \t\r\n\f + test('accepts newline chars', () => { + expect(() => NonEmptyString.parse('hello \nworld')).not.toThrow(); + }); + test('accepts tab chars', () => { + expect(() => NonEmptyString.parse('hello \tworld')).not.toThrow(); + }); + test('accepts carriage return chars', () => { + expect(() => NonEmptyString.parse('hello \rworld')).not.toThrow(); + }); + test('accepts form feed return chars', () => { + expect(() => NonEmptyString.parse('hello \fworld')).not.toThrow(); + }); }); - test('rejects comment with just spaces', () => { - expect(() => NonEmptyString.parse(' ')).toThrow(); + describe('rejects', () => { + test('rejects only tab chars chars', () => { + expect(() => NonEmptyString.parse('\t\t\t\t')).toThrow(); + }); + test('rejects only newline chars chars', () => { + expect(() => NonEmptyString.parse('\n\n\n\n\n')).toThrow(); + }); + test('rejects only carriage return chars chars', () => { + expect(() => NonEmptyString.parse('\r\r\r\r')).toThrow(); + }); + test('rejects only form feed chars chars', () => { + expect(() => NonEmptyString.parse('\f\f\f\f\f')).toThrow(); + }); + test('rejects comment with just spaces', () => { + expect(() => NonEmptyString.parse(' ')).toThrow(); + }); }); }); diff --git a/packages/kbn-zod-helpers/src/non_empty_string.ts b/packages/kbn-zod-helpers/src/non_empty_string.ts index bb10ee0d3b45d..d007c2f4f0a25 100644 --- a/packages/kbn-zod-helpers/src/non_empty_string.ts +++ b/packages/kbn-zod-helpers/src/non_empty_string.ts @@ -8,7 +8,8 @@ */ import * as z from '@kbn/zod'; -export function isNonEmptyString(input: string, ctx: z.RefinementCtx) { + +export function isNonEmptyString(input: string, ctx: z.RefinementCtx): void { if (input.trim() === '') { ctx.addIssue({ code: z.ZodIssueCode.custom, diff --git a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.gen.ts b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.gen.ts index 1697011a08532..c0ab8b221fcff 100644 --- a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.gen.ts +++ b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.gen.ts @@ -15,15 +15,13 @@ */ import { z } from '@kbn/zod'; +import { isNonEmptyString } from '@kbn/zod-helpers'; /** - * A string that is not empty and does not contain only whitespace + * A string that does not contain only whitespace */ export type NonEmptyString = z.infer; -export const NonEmptyString = z - .string() - .min(1) - .regex(/^(?! *$).+$/); +export const NonEmptyString = z.string().min(1).superRefine(isNonEmptyString); /** * A universally unique identifier diff --git a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.schema.yaml b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.schema.yaml index 348868746fb6c..1e21e6d9fd65e 100644 --- a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.schema.yaml +++ b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.schema.yaml @@ -8,9 +8,9 @@ components: schemas: NonEmptyString: type: string - pattern: ^(?! *$).+$ + format: nonempty minLength: 1 - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace UUID: type: string @@ -33,4 +33,3 @@ components: enum: - 'asc' - 'desc' - diff --git a/x-pack/plugins/security_solution/common/api/model/primitives.gen.ts b/x-pack/plugins/security_solution/common/api/model/primitives.gen.ts index ed3174434cb36..dcc7bb66649ee 100644 --- a/x-pack/plugins/security_solution/common/api/model/primitives.gen.ts +++ b/x-pack/plugins/security_solution/common/api/model/primitives.gen.ts @@ -15,15 +15,13 @@ */ import { z } from '@kbn/zod'; +import { isNonEmptyString } from '@kbn/zod-helpers'; /** - * A string that is not empty and does not contain only whitespace + * A string that does not contain only whitespace */ export type NonEmptyString = z.infer; -export const NonEmptyString = z - .string() - .min(1) - .regex(/^(?! *$).+$/); +export const NonEmptyString = z.string().min(1).superRefine(isNonEmptyString); /** * A universally unique identifier diff --git a/x-pack/plugins/security_solution/common/api/model/primitives.schema.yaml b/x-pack/plugins/security_solution/common/api/model/primitives.schema.yaml index 177ad2ed30ecc..3c0791361402c 100644 --- a/x-pack/plugins/security_solution/common/api/model/primitives.schema.yaml +++ b/x-pack/plugins/security_solution/common/api/model/primitives.schema.yaml @@ -8,9 +8,9 @@ components: schemas: NonEmptyString: type: string - pattern: ^(?! *$).+$ + format: nonempty minLength: 1 - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace UUID: type: string diff --git a/x-pack/plugins/security_solution/common/siem_migrations/model/common.gen.ts b/x-pack/plugins/security_solution/common/siem_migrations/model/common.gen.ts index 9b1d0756c3a3b..533b3f682a50b 100644 --- a/x-pack/plugins/security_solution/common/siem_migrations/model/common.gen.ts +++ b/x-pack/plugins/security_solution/common/siem_migrations/model/common.gen.ts @@ -15,15 +15,13 @@ */ import { z } from '@kbn/zod'; +import { isNonEmptyString } from '@kbn/zod-helpers'; /** - * A string that is not empty and does not contain only whitespace + * A string that does not contain only whitespace */ export type NonEmptyString = z.infer; -export const NonEmptyString = z - .string() - .min(1) - .regex(/^(?! *$).+$/); +export const NonEmptyString = z.string().min(1).superRefine(isNonEmptyString); /** * The GenAI connector id to use. diff --git a/x-pack/plugins/security_solution/common/siem_migrations/model/common.schema.yaml b/x-pack/plugins/security_solution/common/siem_migrations/model/common.schema.yaml index a50225df778ad..49abc9a1a9c2b 100644 --- a/x-pack/plugins/security_solution/common/siem_migrations/model/common.schema.yaml +++ b/x-pack/plugins/security_solution/common/siem_migrations/model/common.schema.yaml @@ -8,9 +8,9 @@ components: schemas: NonEmptyString: type: string - pattern: ^(?! *$).+$ + format: nonempty minLength: 1 - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace ConnectorId: type: string description: The GenAI connector id to use. From 78bea3fb1e5688f01f50c863a40b63f42a670bfd Mon Sep 17 00:00:00 2001 From: Devin Hurley Date: Wed, 4 Dec 2024 22:40:13 -0500 Subject: [PATCH 09/13] forgot 'characters' --- packages/kbn-openapi-common/schemas/primitives.schema.yaml | 2 +- .../impl/schemas/common_attributes.schema.yaml | 2 +- .../security_solution/common/api/model/primitives.schema.yaml | 2 +- .../common/siem_migrations/model/common.schema.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/kbn-openapi-common/schemas/primitives.schema.yaml b/packages/kbn-openapi-common/schemas/primitives.schema.yaml index 0120a64e2afee..84e4367192725 100644 --- a/packages/kbn-openapi-common/schemas/primitives.schema.yaml +++ b/packages/kbn-openapi-common/schemas/primitives.schema.yaml @@ -10,7 +10,7 @@ components: type: string minLength: 1 format: nonempty - description: A string that does not contain only whitespace + description: A string that does not contain only whitespace characters UUID: type: string diff --git a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.schema.yaml b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.schema.yaml index 1e21e6d9fd65e..b400548631ed1 100644 --- a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.schema.yaml +++ b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.schema.yaml @@ -10,7 +10,7 @@ components: type: string format: nonempty minLength: 1 - description: A string that does not contain only whitespace + description: A string that does not contain only whitespace characters UUID: type: string diff --git a/x-pack/plugins/security_solution/common/api/model/primitives.schema.yaml b/x-pack/plugins/security_solution/common/api/model/primitives.schema.yaml index 3c0791361402c..2d4e184928fca 100644 --- a/x-pack/plugins/security_solution/common/api/model/primitives.schema.yaml +++ b/x-pack/plugins/security_solution/common/api/model/primitives.schema.yaml @@ -10,7 +10,7 @@ components: type: string format: nonempty minLength: 1 - description: A string that does not contain only whitespace + description: A string that does not contain only whitespace characters UUID: type: string diff --git a/x-pack/plugins/security_solution/common/siem_migrations/model/common.schema.yaml b/x-pack/plugins/security_solution/common/siem_migrations/model/common.schema.yaml index 49abc9a1a9c2b..9e15bd857c728 100644 --- a/x-pack/plugins/security_solution/common/siem_migrations/model/common.schema.yaml +++ b/x-pack/plugins/security_solution/common/siem_migrations/model/common.schema.yaml @@ -10,7 +10,7 @@ components: type: string format: nonempty minLength: 1 - description: A string that does not contain only whitespace + description: A string that does not contain only whitespace characters ConnectorId: type: string description: The GenAI connector id to use. From 61065f53ab874afe8b629d3ecb9d4a8f943eba9e Mon Sep 17 00:00:00 2001 From: Devin Hurley Date: Wed, 4 Dec 2024 22:43:02 -0500 Subject: [PATCH 10/13] regenerate spec to include changes in description --- packages/kbn-openapi-common/schemas/primitives.gen.ts | 2 +- .../impl/schemas/common_attributes.gen.ts | 2 +- .../security_solution/common/api/model/primitives.gen.ts | 2 +- .../common/siem_migrations/model/common.gen.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/kbn-openapi-common/schemas/primitives.gen.ts b/packages/kbn-openapi-common/schemas/primitives.gen.ts index 3239afbb6e5af..03977a29b9973 100644 --- a/packages/kbn-openapi-common/schemas/primitives.gen.ts +++ b/packages/kbn-openapi-common/schemas/primitives.gen.ts @@ -20,7 +20,7 @@ import { z } from '@kbn/zod'; import { isNonEmptyString } from '@kbn/zod-helpers'; /** - * A string that is not empty and does not contain only whitespace + * A string that does not contain only whitespace characters */ export type NonEmptyString = z.infer; export const NonEmptyString = z.string().min(1).superRefine(isNonEmptyString); diff --git a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.gen.ts b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.gen.ts index c0ab8b221fcff..a49d6bc6e41b7 100644 --- a/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.gen.ts +++ b/x-pack/packages/kbn-elastic-assistant-common/impl/schemas/common_attributes.gen.ts @@ -18,7 +18,7 @@ import { z } from '@kbn/zod'; import { isNonEmptyString } from '@kbn/zod-helpers'; /** - * A string that does not contain only whitespace + * A string that does not contain only whitespace characters */ export type NonEmptyString = z.infer; export const NonEmptyString = z.string().min(1).superRefine(isNonEmptyString); diff --git a/x-pack/plugins/security_solution/common/api/model/primitives.gen.ts b/x-pack/plugins/security_solution/common/api/model/primitives.gen.ts index dcc7bb66649ee..393cfe7a21c53 100644 --- a/x-pack/plugins/security_solution/common/api/model/primitives.gen.ts +++ b/x-pack/plugins/security_solution/common/api/model/primitives.gen.ts @@ -18,7 +18,7 @@ import { z } from '@kbn/zod'; import { isNonEmptyString } from '@kbn/zod-helpers'; /** - * A string that does not contain only whitespace + * A string that does not contain only whitespace characters */ export type NonEmptyString = z.infer; export const NonEmptyString = z.string().min(1).superRefine(isNonEmptyString); diff --git a/x-pack/plugins/security_solution/common/siem_migrations/model/common.gen.ts b/x-pack/plugins/security_solution/common/siem_migrations/model/common.gen.ts index 533b3f682a50b..f55b87f7af703 100644 --- a/x-pack/plugins/security_solution/common/siem_migrations/model/common.gen.ts +++ b/x-pack/plugins/security_solution/common/siem_migrations/model/common.gen.ts @@ -18,7 +18,7 @@ import { z } from '@kbn/zod'; import { isNonEmptyString } from '@kbn/zod-helpers'; /** - * A string that does not contain only whitespace + * A string that does not contain only whitespace characters */ export type NonEmptyString = z.infer; export const NonEmptyString = z.string().min(1).superRefine(isNonEmptyString); From 6cbee35dc43957413883833814847c34fb3a7fe4 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 5 Dec 2024 04:33:33 +0000 Subject: [PATCH 11/13] [CI] Auto-commit changed files from 'yarn openapi:bundle' --- ...ion_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml | 2 +- ...ion_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml | 2 +- ...ity_solution_exceptions_api_2023_10_31.bundled.schema.yaml | 2 +- ...ity_solution_exceptions_api_2023_10_31.bundled.schema.yaml | 2 +- ...security_solution_lists_api_2023_10_31.bundled.schema.yaml | 2 +- ...security_solution_lists_api_2023_10_31.bundled.schema.yaml | 2 +- .../ess/elastic_assistant_api_2023_10_31.bundled.schema.yaml | 4 ++-- .../elastic_assistant_api_2023_10_31.bundled.schema.yaml | 4 ++-- ...ity_solution_detections_api_2023_10_31.bundled.schema.yaml | 4 ++-- ...ion_endpoint_management_api_2023_10_31.bundled.schema.yaml | 4 ++-- ...ity_solution_detections_api_2023_10_31.bundled.schema.yaml | 4 ++-- ...ion_endpoint_management_api_2023_10_31.bundled.schema.yaml | 4 ++-- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/ess/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/ess/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml index 800dbf3930660..2aac93167d2a9 100644 --- a/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/ess/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/ess/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml @@ -846,7 +846,7 @@ components: - text type: string NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string diff --git a/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/serverless/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/serverless/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml index 92b597cd8a0bf..1257b37622add 100644 --- a/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/serverless/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-endpoint-exceptions-common/docs/openapi/serverless/security_solution_endpoint_exceptions_api_2023_10_31.bundled.schema.yaml @@ -846,7 +846,7 @@ components: - text type: string NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string diff --git a/packages/kbn-securitysolution-exceptions-common/docs/openapi/ess/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-exceptions-common/docs/openapi/ess/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml index 0166c3c95821e..d02bd360cc313 100644 --- a/packages/kbn-securitysolution-exceptions-common/docs/openapi/ess/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/docs/openapi/ess/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml @@ -1846,7 +1846,7 @@ components: - text type: string NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string diff --git a/packages/kbn-securitysolution-exceptions-common/docs/openapi/serverless/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-exceptions-common/docs/openapi/serverless/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml index 8fcae9fb348cb..885028d7e2d94 100644 --- a/packages/kbn-securitysolution-exceptions-common/docs/openapi/serverless/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-exceptions-common/docs/openapi/serverless/security_solution_exceptions_api_2023_10_31.bundled.schema.yaml @@ -1846,7 +1846,7 @@ components: - text type: string NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string diff --git a/packages/kbn-securitysolution-lists-common/docs/openapi/ess/security_solution_lists_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-lists-common/docs/openapi/ess/security_solution_lists_api_2023_10_31.bundled.schema.yaml index d9d892d160783..ef88149b49b32 100644 --- a/packages/kbn-securitysolution-lists-common/docs/openapi/ess/security_solution_lists_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-lists-common/docs/openapi/ess/security_solution_lists_api_2023_10_31.bundled.schema.yaml @@ -1528,7 +1528,7 @@ components: - text type: string NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string diff --git a/packages/kbn-securitysolution-lists-common/docs/openapi/serverless/security_solution_lists_api_2023_10_31.bundled.schema.yaml b/packages/kbn-securitysolution-lists-common/docs/openapi/serverless/security_solution_lists_api_2023_10_31.bundled.schema.yaml index 8a956172ac3be..e3558193b30da 100644 --- a/packages/kbn-securitysolution-lists-common/docs/openapi/serverless/security_solution_lists_api_2023_10_31.bundled.schema.yaml +++ b/packages/kbn-securitysolution-lists-common/docs/openapi/serverless/security_solution_lists_api_2023_10_31.bundled.schema.yaml @@ -1528,7 +1528,7 @@ components: - text type: string NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string diff --git a/x-pack/packages/kbn-elastic-assistant-common/docs/openapi/ess/elastic_assistant_api_2023_10_31.bundled.schema.yaml b/x-pack/packages/kbn-elastic-assistant-common/docs/openapi/ess/elastic_assistant_api_2023_10_31.bundled.schema.yaml index 8f80e61c07040..726f5faba2edb 100644 --- a/x-pack/packages/kbn-elastic-assistant-common/docs/openapi/ess/elastic_assistant_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/packages/kbn-elastic-assistant-common/docs/openapi/ess/elastic_assistant_api_2023_10_31.bundled.schema.yaml @@ -978,9 +978,9 @@ components: - assistant type: string NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string NormalizedAnonymizationFieldError: type: object diff --git a/x-pack/packages/kbn-elastic-assistant-common/docs/openapi/serverless/elastic_assistant_api_2023_10_31.bundled.schema.yaml b/x-pack/packages/kbn-elastic-assistant-common/docs/openapi/serverless/elastic_assistant_api_2023_10_31.bundled.schema.yaml index 97c18a2f77b6e..81112f1470547 100644 --- a/x-pack/packages/kbn-elastic-assistant-common/docs/openapi/serverless/elastic_assistant_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/packages/kbn-elastic-assistant-common/docs/openapi/serverless/elastic_assistant_api_2023_10_31.bundled.schema.yaml @@ -978,9 +978,9 @@ components: - assistant type: string NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string NormalizedAnonymizationFieldError: type: object diff --git a/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_detections_api_2023_10_31.bundled.schema.yaml b/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_detections_api_2023_10_31.bundled.schema.yaml index 7e8d7a61bff2c..ba95e20f3e86a 100644 --- a/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_detections_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_detections_api_2023_10_31.bundled.schema.yaml @@ -4182,9 +4182,9 @@ components: - severity - $ref: '#/components/schemas/NewTermsRuleCreateFields' NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string NormalizedRuleAction: additionalProperties: false diff --git a/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_endpoint_management_api_2023_10_31.bundled.schema.yaml b/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_endpoint_management_api_2023_10_31.bundled.schema.yaml index 585dec4f3074d..62d604ec727db 100644 --- a/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_endpoint_management_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/plugins/security_solution/docs/openapi/ess/security_solution_endpoint_management_api_2023_10_31.bundled.schema.yaml @@ -706,9 +706,9 @@ components: required: - hostStatuses NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string NoParametersRequestSchema: type: object diff --git a/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_detections_api_2023_10_31.bundled.schema.yaml b/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_detections_api_2023_10_31.bundled.schema.yaml index 58456e71140a0..f81cc1227c893 100644 --- a/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_detections_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_detections_api_2023_10_31.bundled.schema.yaml @@ -3335,9 +3335,9 @@ components: - severity - $ref: '#/components/schemas/NewTermsRuleCreateFields' NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string NormalizedRuleAction: additionalProperties: false diff --git a/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_endpoint_management_api_2023_10_31.bundled.schema.yaml b/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_endpoint_management_api_2023_10_31.bundled.schema.yaml index ded6f6558b017..ee89d61a58b52 100644 --- a/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_endpoint_management_api_2023_10_31.bundled.schema.yaml +++ b/x-pack/plugins/security_solution/docs/openapi/serverless/security_solution_endpoint_management_api_2023_10_31.bundled.schema.yaml @@ -706,9 +706,9 @@ components: required: - hostStatuses NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string NoParametersRequestSchema: type: object From f29533216c0edbf66a0052d48affccb30e639177 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 5 Dec 2024 05:27:43 +0000 Subject: [PATCH 12/13] [CI] Auto-commit changed files from 'make api-docs' --- oas_docs/output/kibana.serverless.yaml | 18 +++++++++--------- oas_docs/output/kibana.yaml | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/oas_docs/output/kibana.serverless.yaml b/oas_docs/output/kibana.serverless.yaml index caa7429c8324b..97ada7e2c532c 100644 --- a/oas_docs/output/kibana.serverless.yaml +++ b/oas_docs/output/kibana.serverless.yaml @@ -39111,9 +39111,9 @@ components: - assistant type: string Security_AI_Assistant_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_AI_Assistant_API_NormalizedAnonymizationFieldError: type: object @@ -41877,9 +41877,9 @@ components: - severity - $ref: '#/components/schemas/Security_Detections_API_NewTermsRuleCreateFields' Security_Detections_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_Detections_API_NormalizedRuleAction: additionalProperties: false @@ -45081,7 +45081,7 @@ components: - text type: string Security_Endpoint_Exceptions_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string @@ -45384,9 +45384,9 @@ components: required: - hostStatuses Security_Endpoint_Management_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_Endpoint_Management_API_NoParametersRequestSchema: type: object @@ -46567,7 +46567,7 @@ components: - text type: string Security_Exceptions_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string @@ -46813,7 +46813,7 @@ components: - text type: string Security_Lists_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string diff --git a/oas_docs/output/kibana.yaml b/oas_docs/output/kibana.yaml index e0354ec86f521..e747d2f06c081 100644 --- a/oas_docs/output/kibana.yaml +++ b/oas_docs/output/kibana.yaml @@ -46650,9 +46650,9 @@ components: - assistant type: string Security_AI_Assistant_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_AI_Assistant_API_NormalizedAnonymizationFieldError: type: object @@ -49596,9 +49596,9 @@ components: - severity - $ref: '#/components/schemas/Security_Detections_API_NewTermsRuleCreateFields' Security_Detections_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_Detections_API_NormalizedRuleAction: additionalProperties: false @@ -52807,7 +52807,7 @@ components: - text type: string Security_Endpoint_Exceptions_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string @@ -53110,9 +53110,9 @@ components: required: - hostStatuses Security_Endpoint_Management_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters + format: nonempty minLength: 1 - pattern: ^(?! *$).+$ type: string Security_Endpoint_Management_API_NoParametersRequestSchema: type: object @@ -54293,7 +54293,7 @@ components: - text type: string Security_Exceptions_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string @@ -54539,7 +54539,7 @@ components: - text type: string Security_Lists_API_NonEmptyString: - description: A string that is not empty and does not contain only whitespace + description: A string that does not contain only whitespace characters format: nonempty minLength: 1 type: string From 4cc57da30f04e03b129898e0bc859b49307d936f Mon Sep 17 00:00:00 2001 From: Devin Hurley Date: Mon, 9 Dec 2024 12:20:29 -0500 Subject: [PATCH 13/13] update snapshot and expected error messages --- .../serverless_upgrade_and_rollback_checks.test.ts.snap | 7 ------- .../routes/signals/set_alert_assignees_route.test.ts | 2 +- .../trial_license_complete_tier/assignments/assignments.ts | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/alerting/server/integration_tests/__snapshots__/serverless_upgrade_and_rollback_checks.test.ts.snap b/x-pack/plugins/alerting/server/integration_tests/__snapshots__/serverless_upgrade_and_rollback_checks.test.ts.snap index c283cc1087682..0f5a4143a5c99 100644 --- a/x-pack/plugins/alerting/server/integration_tests/__snapshots__/serverless_upgrade_and_rollback_checks.test.ts.snap +++ b/x-pack/plugins/alerting/server/integration_tests/__snapshots__/serverless_upgrade_and_rollback_checks.test.ts.snap @@ -5737,7 +5737,6 @@ Object { "field_names": Object { "items": Object { "minLength": 1, - "pattern": "^(?! *$).+$", "type": "string", }, "minItems": 1, @@ -6405,7 +6404,6 @@ Object { "field_names": Object { "items": Object { "minLength": 1, - "pattern": "^(?! *$).+$", "type": "string", }, "minItems": 1, @@ -7136,7 +7134,6 @@ Object { "field_names": Object { "items": Object { "minLength": 1, - "pattern": "^(?! *$).+$", "type": "string", }, "minItems": 1, @@ -7785,7 +7782,6 @@ Object { "field_names": Object { "items": Object { "minLength": 1, - "pattern": "^(?! *$).+$", "type": "string", }, "minItems": 1, @@ -8489,7 +8485,6 @@ Object { "field_names": Object { "items": Object { "minLength": 1, - "pattern": "^(?! *$).+$", "type": "string", }, "minItems": 1, @@ -9195,7 +9190,6 @@ Object { "field_names": Object { "items": Object { "minLength": 1, - "pattern": "^(?! *$).+$", "type": "string", }, "minItems": 1, @@ -9901,7 +9895,6 @@ Object { "field_names": Object { "items": Object { "minLength": 1, - "pattern": "^(?! *$).+$", "type": "string", }, "minItems": 1, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_assignees_route.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_assignees_route.test.ts index dfc0603598a00..4b4653d194745 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_assignees_route.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_assignees_route.test.ts @@ -92,7 +92,7 @@ describe('setAlertAssigneesRoute', () => { const result = server.validate(request); expect(result.badRequest).toHaveBeenCalledWith( - 'ids.0: String must contain at least 1 character(s), ids.0: Invalid' + 'ids.0: String must contain at least 1 character(s), ids.0: No empty strings allowed' ); }); }); diff --git a/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/trial_license_complete_tier/assignments/assignments.ts b/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/trial_license_complete_tier/assignments/assignments.ts index b445c6f81f99c..436ebc469c25e 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/trial_license_complete_tier/assignments/assignments.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/alerts/trial_license_complete_tier/assignments/assignments.ts @@ -65,7 +65,7 @@ export default ({ getService }: FtrProviderContext) => { expect(body).to.eql({ error: 'Bad Request', message: - '[request body]: ids.1: String must contain at least 1 character(s), ids.1: Invalid', + '[request body]: ids.1: String must contain at least 1 character(s), ids.1: No empty strings allowed', statusCode: 400, }); });