Hi Jing H,
Thank you for posting query in Microsoft Q&A Platform.
Based on the error message you received, it seems that the issue is related to the schema definition. The error message "Json schema validation failed: An item with the same key has already been added" indicates that there is a duplicate key in the schema definition.
In your example, the "union_field" is defined as a union of two records, "RecordA" and "RecordB". However, the "name" field in both records is the same, which is causing a conflict. To fix this issue, you can rename the "name" field in one of the records to a different name.
Here is an updated schema definition with the "name" field in "RecordB" renamed to "baz":
Java
Copy var schemaDefinition = """ { "type": "record", "name": "TestRecord", "fields": [{ "name": "union_field", "type": [{ "type": "record", "name": "RecordA", "fields": [{ "name": "foo", "type": "string" }] }, { "type": "record", "name": "RecordB", "fields": [{ "name": "baz", "type": "string" }] }] }] } """;
After making this change, you should be able to register the schema without any issues.
Please try above and let me know how it goes.