From 86ec89cacd36b850a6a29887a86833cc0cc28e8c Mon Sep 17 00:00:00 2001 From: Milosz Korman Date: Wed, 16 Oct 2024 12:57:12 +0200 Subject: [PATCH] resolve #1907 | handle record references when presenting avro schema --- hermes-console/json-server/db.json | 2 +- hermes-console/json-server/topics.json | 2 +- hermes-console/src/dummy/topic.ts | 2 +- .../src/views/topic/schema-panel/AvroTypes.ts | 1 + .../schema-panel/avro-viewer/AvroNode.vue | 20 +- .../schema-panel/avro-viewer/AvroViewer.vue | 9 +- .../avro-record-types-registry.spec.ts | 340 ++++++++++++++++++ .../avro-viewer/avro-record-types-registry.ts | 122 +++++++ 8 files changed, 491 insertions(+), 7 deletions(-) create mode 100644 hermes-console/src/views/topic/schema-panel/avro-viewer/avro-record-types-registry.spec.ts create mode 100644 hermes-console/src/views/topic/schema-panel/avro-viewer/avro-record-types-registry.ts diff --git a/hermes-console/json-server/db.json b/hermes-console/json-server/db.json index 12f97d5dd3..061e982505 100644 --- a/hermes-console/json-server/db.json +++ b/hermes-console/json-server/db.json @@ -190,7 +190,7 @@ "topics": [ { "id": "pl.allegro.public.group.DummyEvent", - "schema": "{\"type\":\"record\",\"name\":\"DummyEvent\",\"namespace\":\"pl.allegro.public.group.DummyEvent\",\"doc\":\"Event emitted when notification is sent to a user\",\"fields\":[{\"name\":\"__metadata\",\"type\":[\"null\",{\"type\":\"map\",\"values\":\"string\"}],\"doc\":\"Field internally used by Hermes to propagate metadata.\",\"default\":null},{\"name\":\"waybillId\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"WaybillId\",\"fields\":[{\"name\":\"waybill\",\"type\":\"string\",\"doc\":\"Waybill\"},{\"name\":\"carrierId\",\"type\":\"string\",\"doc\":\"CarrierId\"}]}],\"doc\":\"WaybillId\",\"default\":null},{\"name\":\"notificationId\",\"type\":\"string\",\"doc\":\"Notification Id\"},{\"name\":\"userId\",\"type\":\"string\",\"doc\":\"User Id\"}]}", + "schema": "{\"type\":\"record\",\"name\":\"DummyEvent\",\"namespace\":\"pl.allegro.public.group.DummyEvent\",\"doc\":\"Event emitted when notification is sent to a user\",\"fields\":[{\"name\":\"__metadata\",\"type\":[\"null\",{\"type\":\"map\",\"values\":\"string\"}],\"doc\":\"Field internally used by Hermes to propagate metadata.\",\"default\":null},{\"name\":\"waybillId\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"WaybillId\",\"fields\":[{\"name\":\"waybill\",\"type\":\"string\",\"doc\":\"Waybill\"},{\"name\":\"carrierId\",\"type\":\"string\",\"doc\":\"CarrierId\"}]}],\"doc\":\"WaybillId\",\"default\":null},{\"name\":\"otherWaybillId\",\"type\":[\"null\",\"WaybillId\"],\"doc\":\"other WaybillId\",\"default\":null},{\"name\":\"notificationId\",\"type\":\"string\",\"doc\":\"Notification Id\"},{\"name\":\"userId\",\"type\":\"string\",\"doc\":\"User Id\"}]}", "name": "pl.allegro.public.group.DummyEvent", "description": "Events emitted when notification is sent to a user.", "owner": { diff --git a/hermes-console/json-server/topics.json b/hermes-console/json-server/topics.json index bea9c1b3e6..ef667b9756 100644 --- a/hermes-console/json-server/topics.json +++ b/hermes-console/json-server/topics.json @@ -1,7 +1,7 @@ [ { "id": "pl.allegro.public.group.DummyEvent", - "schema": "{\"type\":\"record\",\"name\":\"DummyEvent\",\"namespace\":\"pl.allegro.public.group.DummyEvent\",\"doc\":\"Event emitted when notification is sent to a user\",\"fields\":[{\"name\":\"__metadata\",\"type\":[\"null\",{\"type\":\"map\",\"values\":\"string\"}],\"doc\":\"Field internally used by Hermes to propagate metadata.\",\"default\":null},{\"name\":\"waybillId\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"WaybillId\",\"fields\":[{\"name\":\"waybill\",\"type\":\"string\",\"doc\":\"Waybill\"},{\"name\":\"carrierId\",\"type\":\"string\",\"doc\":\"CarrierId\"}]}],\"doc\":\"WaybillId\",\"default\":null},{\"name\":\"notificationId\",\"type\":\"string\",\"doc\":\"Notification Id\"},{\"name\":\"userId\",\"type\":\"string\",\"doc\":\"User Id\"}]}", + "schema": "{\"type\":\"record\",\"name\":\"DummyEvent\",\"namespace\":\"pl.allegro.public.group.DummyEvent\",\"doc\":\"Event emitted when notification is sent to a user\",\"fields\":[{\"name\":\"__metadata\",\"type\":[\"null\",{\"type\":\"map\",\"values\":\"string\"}],\"doc\":\"Field internally used by Hermes to propagate metadata.\",\"default\":null},{\"name\":\"waybillId\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"WaybillId\",\"fields\":[{\"name\":\"waybill\",\"type\":\"string\",\"doc\":\"Waybill\"},{\"name\":\"carrierId\",\"type\":\"string\",\"doc\":\"CarrierId\"}]}],\"doc\":\"WaybillId\",\"default\":null},{\"name\":\"otherWaybillId\",\"type\":[\"null\",\"WaybillId\"],\"doc\":\"other WaybillId\",\"default\":null},{\"name\":\"notificationId\",\"type\":\"string\",\"doc\":\"Notification Id\"},{\"name\":\"userId\",\"type\":\"string\",\"doc\":\"User Id\"}]}", "name": "pl.allegro.public.group.DummyEvent", "description": "Events emitted when notification is sent to a user.", "owner": { diff --git a/hermes-console/src/dummy/topic.ts b/hermes-console/src/dummy/topic.ts index 4697e7ddac..e02fb9fe92 100644 --- a/hermes-console/src/dummy/topic.ts +++ b/hermes-console/src/dummy/topic.ts @@ -11,7 +11,7 @@ import type { Owner } from '@/api/owner'; export const dummyTopic: TopicWithSchema = { schema: - '{"type":"record","name":"DummyEvent","namespace":"pl.allegro.public.group.DummyEvent","doc":"Event emitted when notification is sent to a user","fields":[{"name":"__metadata","type":["null",{"type":"map","values":"string"}],"doc":"Field internally used by Hermes to propagate metadata.","default":null},{"name":"waybillId","type":["null",{"type":"record","name":"WaybillId","fields":[{"name":"waybill","type":"string","doc":"Waybill"},{"name":"carrierId","type":"string","doc":"CarrierId"}]}],"doc":"WaybillId","default":null},{"name":"notificationId","type":"string","doc":"Notification Id"},{"name":"userId","type":"string","doc":"User Id"}]}', + '{"type":"record","name":"DummyEvent","namespace":"pl.allegro.public.group.DummyEvent","doc":"Event emitted when notification is sent to a user","fields":[{"name":"__metadata","type":["null",{"type":"map","values":"string"}],"doc":"Field internally used by Hermes to propagate metadata.","default":null},{"name":"waybillId","type":["null",{"type":"record","name":"WaybillId","fields":[{"name":"waybill","type":"string","doc":"Waybill"},{"name":"carrierId","type":"string","doc":"CarrierId"}]}],"doc":"WaybillId","default":null},{"name":"otherWaybillId","type":["null","WaybillId"],"doc":"other WaybillId","default":null},{"name":"notificationId","type":"string","doc":"Notification Id"},{"name":"userId","type":"string","doc":"User Id"}]}', name: 'pl.allegro.public.group.DummyEvent', description: 'Events emitted when notification is sent to a user.', owner: { diff --git a/hermes-console/src/views/topic/schema-panel/AvroTypes.ts b/hermes-console/src/views/topic/schema-panel/AvroTypes.ts index 79cee71078..42f9027f32 100644 --- a/hermes-console/src/views/topic/schema-panel/AvroTypes.ts +++ b/hermes-console/src/views/topic/schema-panel/AvroTypes.ts @@ -1,6 +1,7 @@ export interface AvroSchema { type: Type; name: string; + namespace?: string; doc: string; fields?: Field[]; default?: DefaultTypes; diff --git a/hermes-console/src/views/topic/schema-panel/avro-viewer/AvroNode.vue b/hermes-console/src/views/topic/schema-panel/avro-viewer/AvroNode.vue index 4782218ed0..38adaed0f9 100644 --- a/hermes-console/src/views/topic/schema-panel/avro-viewer/AvroNode.vue +++ b/hermes-console/src/views/topic/schema-panel/avro-viewer/AvroNode.vue @@ -1,9 +1,15 @@