Repository: provectus/kafka-ui
Issue: SR: Updating an existing schema with valid syntax says the syntax is invalid
Labels: type/bug
good first issue
scope/frontend
status/accepted
status/confirmed

1. Create a schema:
```
syntax = "proto3";
package com.provectus;

message TestProtoRecord {
  string f1 = 1;
  int32 f2 = 2;
  int32 f3 = 3;
}
```
2. Edit this schema, change something with keeping the syntax valid, e.g. replace `int32 f3 = 3;` with `int32 f4 = 3;`
3. Profit

Issue comments:

Pull request review comments:

Patch that resolved the issue:
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 2fce1ad7d79..56d7bdc8175 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().isEnum('Schema syntax is not valid')
+          ? yup.string().required()
           : yup.string().required().isJsonObject('Schema syntax is not valid'),
     });
   const methods = useForm<NewSchemaSubjectRaw>({
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 8100b9a3264..bd43dd3f72a 100644
--- a/kafka-ui-react-app/src/lib/__test__/yupExtended.spec.ts
+++ b/kafka-ui-react-app/src/lib/__test__/yupExtended.spec.ts
@@ -1,19 +1,5 @@
-import { isValidEnum, 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;
-}
-`;
 describe('yup extended', () => {
   describe('isValidJsonObject', () => {
     it('returns false for no value', () => {
@@ -35,21 +21,4 @@ describe('yup extended', () => {
       expect(isValidJsonObject('{ "foo": "bar" }')).toBeTruthy();
     });
   });
-
-  describe('isValidEnum', () => {
-    it('returns false for invalid enum', () => {
-      expect(isValidEnum(invalidEnum)).toBeFalsy();
-    });
-    it('returns false for no value', () => {
-      expect(isValidEnum()).toBeFalsy();
-    });
-    it('returns true should trim value', () => {
-      expect(
-        isValidEnum(`  enum SchemType {AVRO = 0; PROTOBUF = 3;}   `)
-      ).toBeTruthy();
-    });
-    it('returns true for valid enum', () => {
-      expect(isValidEnum(validEnum)).toBeTruthy();
-    });
-  });
 });
diff --git a/kafka-ui-react-app/src/lib/yupExtended.ts b/kafka-ui-react-app/src/lib/yupExtended.ts
index 4c662ca8222..241dac9770a 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<TType, TContext, TDefault, TFlags> {
     isJsonObject(message?: string): StringSchema<TType, TContext>;
-    isEnum(message?: string): StringSchema<TType, TContext>;
   }
 }
 
@@ -40,32 +39,6 @@ const isJsonObject = (message?: string) => {
     isValidJsonObject
   );
 };
-
-export const isValidEnum = (value?: string) => {
-  try {
-    if (!value) return false;
-    const trimmedValue = value.trim();
-    if (
-      trimmedValue.indexOf('enum') === 0 &&
-      trimmedValue.lastIndexOf('}') === trimmedValue.length - 1
-    ) {
-      return true;
-    }
-  } catch {
-    // do nothing
-  }
-  return false;
-};
-
-const isEnum = (message?: string) => {
-  return yup.string().test(
-    'isEnum',
-    // eslint-disable-next-line no-template-curly-in-string
-    message || '${path} is not Enum object',
-    isValidEnum
-  );
-};
-
 /**
  * due to yup rerunning all the object validiation during any render,
  * it makes sense to cache the async results
@@ -88,7 +61,6 @@ export function cacheTest(
 }
 
 yup.addMethod(yup.StringSchema, 'isJsonObject', isJsonObject);
-yup.addMethod(yup.StringSchema, 'isEnum', isEnum);
 
 export const topicFormValidationSchema = yup.object().shape({
   name: yup


Test patch: