From 6990dde183dcc6e7fabd4e8e3a24ddecf4e6e1bc Mon Sep 17 00:00:00 2001 From: davitbejanyan Date: Thu, 27 Apr 2023 20:43:23 +0400 Subject: [PATCH] remove protobuf validation --- .../src/components/Schemas/Edit/Form.tsx | 2 +- .../src/lib/__test__/yupExtended.spec.ts | 59 +------------------ kafka-ui-react-app/src/lib/yupExtended.ts | 29 --------- 3 files changed, 2 insertions(+), 88 deletions(-) diff --git a/kafka-ui-react-app/src/components/Schemas/Edit/Form.tsx b/kafka-ui-react-app/src/components/Schemas/Edit/Form.tsx index 6f7208ec41..56d7bdc817 100644 --- a/kafka-ui-react-app/src/components/Schemas/Edit/Form.tsx +++ b/kafka-ui-react-app/src/components/Schemas/Edit/Form.tsx @@ -55,7 +55,7 @@ const Form: React.FC = () => { yup.object().shape({ newSchema: schema?.schemaType === SchemaType.PROTOBUF - ? yup.string().required().isSchema('Schema syntax is not valid') + ? yup.string().required() : yup.string().required().isJsonObject('Schema syntax is not valid'), }); const methods = useForm({ diff --git a/kafka-ui-react-app/src/lib/__test__/yupExtended.spec.ts b/kafka-ui-react-app/src/lib/__test__/yupExtended.spec.ts index 38362b41df..bd43dd3f72 100644 --- a/kafka-ui-react-app/src/lib/__test__/yupExtended.spec.ts +++ b/kafka-ui-react-app/src/lib/__test__/yupExtended.spec.ts @@ -1,39 +1,5 @@ -import { isValidSchema, isValidJsonObject } from 'lib/yupExtended'; +import { isValidJsonObject } from 'lib/yupExtended'; -const invalidEnum = ` -ennum SchemType { - AVRO = 0; - JSON = 1; - PROTOBUF = 3; -} -`; -const validEnum = ` -enum SchemType { - AVRO = 0; - JSON = 1; - PROTOBUF = 3; -} -`; -const invalidSchema = ` -ssssyntax = "proto3"; -package com.provectus; - -message TestProtoRecord { - string f1 = 1; - int32 f2 = 2; - int32 f6 = 3; -} -`; -const validSchema = ` -syntax = "proto3"; -package com.provectus; - -message TestProtoRecord { - string f1 = 1; - int32 f2 = 2; - int32 f6 = 3; -} -`; describe('yup extended', () => { describe('isValidJsonObject', () => { it('returns false for no value', () => { @@ -55,27 +21,4 @@ describe('yup extended', () => { expect(isValidJsonObject('{ "foo": "bar" }')).toBeTruthy(); }); }); - - describe('isValidSchema', () => { - it('returns false for invalid enum', () => { - expect(isValidSchema(invalidEnum)).toBeFalsy(); - }); - it('returns false for invalid schema', () => { - expect(isValidSchema(invalidSchema)).toBeFalsy(); - }); - it('returns false for no value', () => { - expect(isValidSchema()).toBeFalsy(); - }); - it('returns true should trim value', () => { - expect( - isValidSchema(` enum SchemType {AVRO = 0; PROTOBUF = 3;} `) - ).toBeTruthy(); - }); - it('returns true for valid enum', () => { - expect(isValidSchema(validEnum)).toBeTruthy(); - }); - it('returns true for valid schema', () => { - expect(isValidSchema(validSchema)).toBeTruthy(); - }); - }); }); diff --git a/kafka-ui-react-app/src/lib/yupExtended.ts b/kafka-ui-react-app/src/lib/yupExtended.ts index f7b36d0ab0..241dac9770 100644 --- a/kafka-ui-react-app/src/lib/yupExtended.ts +++ b/kafka-ui-react-app/src/lib/yupExtended.ts @@ -10,7 +10,6 @@ declare module 'yup' { TFlags extends yup.Flags = '' > extends yup.Schema { isJsonObject(message?: string): StringSchema; - isSchema(message?: string): StringSchema; } } @@ -40,33 +39,6 @@ const isJsonObject = (message?: string) => { isValidJsonObject ); }; - -export const isValidSchema = (value?: string) => { - try { - if (!value) return false; - const trimmedValue = value.trim(); - if ( - (trimmedValue.indexOf('syntax') === 0 || - trimmedValue.indexOf('enum') === 0) && - trimmedValue.lastIndexOf('}') === trimmedValue.length - 1 - ) { - return true; - } - } catch { - // do nothing - } - return false; -}; - -const isSchema = (message?: string) => { - return yup.string().test( - 'isSchema', - // eslint-disable-next-line no-template-curly-in-string - message || '${path} is not valid schema', - isValidSchema - ); -}; - /** * due to yup rerunning all the object validiation during any render, * it makes sense to cache the async results @@ -89,7 +61,6 @@ export function cacheTest( } yup.addMethod(yup.StringSchema, 'isJsonObject', isJsonObject); -yup.addMethod(yup.StringSchema, 'isSchema', isSchema); export const topicFormValidationSchema = yup.object().shape({ name: yup