Repository: provectus/kafka-ui
Issue: Error when trying to produce messages through Kafka-UI
Labels: type/bug
scope/backend
status/accepted

**Describe the bug**
When trying to produce a message, I get an error saying 'Content schema with key or id "http://unknown.unknown" already exists'

**Set up**
Install in Kubernetes in Azure (AKS) using a Helm chart, in the same Kubernetes cluster as my Kafka cluster. Accessing kafka-ui in a browser (port 8080) on my workstation by port forwarding in kubectl. Apart from this issue, everything else seems to work fine - I can connect to my brokers, create topics, view messages, etc.

**Steps to Reproduce**
Steps to reproduce the behavior:

1. Go to my cluster (local)
2. Choose a topic (test)
3. Click 'Produce message' button toward top-right (now at URL http://127.0.0.1:8080/ui/clusters/local/topics/test/message)
4. Leave default key and content or change it
5. Click send
6. Red error text appears at bottom of screen saying:  'Content schema with key or id "http://unknown.unknown" already exists'
7. Message is not sent

**Expected behavior**
In step 6, I expect the message to send. Note I can send messages fine from other producers, so don't think there's any issue with my Kafka cluster.

**Screenshots**
![image](https://user-images.githubusercontent.com/16637123/136668531-b8902ecc-1ca4-412c-b965-f20c2e7b6c22.png)




Issue comments:
@germanosin this happens when both key and content schemas have the same value for `$id` (`http://unknown.unknown` in this case). But I'm not sure if this is a frontend issue or a backend issue. The lib that we use for validating JSON doesn't allow having two schemas with the same id. This sounds reasonable to me. And I don't know where this `http://unknown.unknown` comes from.
Hey @samlangdon, thanks for reaching out. We've fixed this thing, you can pull "master" image to get your fix :)
Great stuff - many thanks for fixing this so quickly. I've pulled the master image and can confirm this resolves the issue for me :) 
You're most welcome!
Hey @Haarolean, thanks for responding so quickly on this one. This issue still exists in the latest Docker image. Is it possible that master is not published there yet? Thanks
> Hey @Haarolean, thanks for responding so quickly on this one. This issue still exists in the latest Docker image. Is it possible that master is not published there yet? Thanks

hi, which tag are you pulling? Try `master`, not `latest`.
Thank you! That was it. :)
You're welcome

Pull request review comments:

Patch that resolved the issue:
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/validateMessage.ts b/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/validateMessage.ts
index 242dd50f9fc..785c9fd2b05 100644
--- a/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/validateMessage.ts
+++ b/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/validateMessage.ts
@@ -8,14 +8,17 @@ const validateMessage = async (
   setSchemaErrors: React.Dispatch<React.SetStateAction<string[]>>
 ): Promise<boolean> => {
   setSchemaErrors([]);
-  const ajv = new Ajv();
+  const keyAjv = new Ajv();
+  const contentAjv = new Ajv();
   try {
     if (messageSchema) {
       let keyIsValid = false;
       let contentIsValid = false;
 
       try {
-        const validateKey = ajv.compile(JSON.parse(messageSchema.key.schema));
+        const validateKey = keyAjv.compile(
+          JSON.parse(messageSchema.key.schema)
+        );
         keyIsValid = validateKey(JSON.parse(key));
         if (!keyIsValid) {
           const errorString: string[] = [];
@@ -32,7 +35,7 @@ const validateMessage = async (
         setSchemaErrors((e) => [...e, `Key ${err.message}`]);
       }
       try {
-        const validateContent = ajv.compile(
+        const validateContent = contentAjv.compile(
           JSON.parse(messageSchema.value.schema)
         );
         contentIsValid = validateContent(JSON.parse(content));


Test patch: