Skip to content

Commit fdb4854

Browse files
authored
resolve #1907 | handle record references when presenting avro schema (#1911)
1 parent ff00205 commit fdb4854

File tree

8 files changed

+491
-7
lines changed

8 files changed

+491
-7
lines changed

hermes-console/json-server/db.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
"topics": [
201201
{
202202
"id": "pl.allegro.public.group.DummyEvent",
203-
"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\"}]}",
203+
"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\"}]}",
204204
"name": "pl.allegro.public.group.DummyEvent",
205205
"description": "Events emitted when notification is sent to a user.",
206206
"owner": {

hermes-console/json-server/topics.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"id": "pl.allegro.public.group.DummyEvent",
4-
"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\"}]}",
4+
"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\"}]}",
55
"name": "pl.allegro.public.group.DummyEvent",
66
"description": "Events emitted when notification is sent to a user.",
77
"owner": {

hermes-console/src/dummy/topic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { Owner } from '@/api/owner';
1212

1313
export const dummyTopic: TopicWithSchema = {
1414
schema:
15-
'{"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"}]}',
15+
'{"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"}]}',
1616
name: 'pl.allegro.public.group.DummyEvent',
1717
description: 'Events emitted when notification is sent to a user.',
1818
owner: {

hermes-console/src/views/topic/schema-panel/AvroTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface AvroSchema {
22
type: Type;
33
name: string;
4+
namespace?: string;
45
doc: string;
56
fields?: Field[];
67
default?: DefaultTypes;

hermes-console/src/views/topic/schema-panel/avro-viewer/AvroNode.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
<script lang="ts" setup>
22
import { defineProps, ref } from 'vue';
3-
import type { AvroSchema, Type } from '@/views/topic/schema-panel/AvroTypes';
3+
import { getRecordTypesRegistryEntry } from '@/views/topic/schema-panel/avro-viewer/avro-record-types-registry';
4+
import type {
5+
AvroSchema,
6+
RecordType,
7+
Type,
8+
} from '@/views/topic/schema-panel/AvroTypes';
49
510
const props = defineProps<{
611
field: AvroSchema;
12+
recordReferenceTypes: Map<string, RecordType>;
713
root: boolean;
814
}>();
915
const expanded = ref(true);
@@ -62,10 +68,17 @@
6268
};
6369
6470
const types = getTypes(props.field.type);
65-
const isRecord = types.some((type: Type) => type.includes('record'));
71+
const recordTypeReference = getRecordTypesRegistryEntry(
72+
props.recordReferenceTypes,
73+
props.field.type,
74+
);
75+
const isRecord =
76+
!!recordTypeReference ||
77+
types.some((type: Type) => type.includes('record'));
6678
const isEnum = types.some((type: Type) => type.includes('enum'));
6779
const expandable = isRecord || isEnum;
68-
const nestedType = isRecord && findNestedType(props.field.type);
80+
const nestedType =
81+
isRecord && (recordTypeReference || findNestedType(props.field.type));
6982
const enumSymbols = isEnum && findEnumSymbols(props.field.type);
7083
7184
const toggle = (event: Event) => {
@@ -100,6 +113,7 @@
100113
v-for="nestedField in nestedType.fields"
101114
:key="nestedField.name"
102115
:field="nestedField"
116+
:record-reference-types="props.recordReferenceTypes"
103117
:root="false"
104118
/>
105119
</div>

hermes-console/src/views/topic/schema-panel/avro-viewer/AvroViewer.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts" setup>
2+
import { createRecordTypesRegistry } from '@/views/topic/schema-panel/avro-viewer/avro-record-types-registry';
23
import AvroNode from '@/views/topic/schema-panel/avro-viewer/AvroNode.vue';
34
import type { AvroSchema } from '@/views/topic/schema-panel/AvroTypes';
45
const props = defineProps<{
@@ -9,6 +10,7 @@
910
const jsonSchema: AvroSchema = JSON.parse(props.schema);
1011
return {
1112
name: jsonSchema.name,
13+
namespace: jsonSchema.namespace,
1214
doc: jsonSchema.doc,
1315
type: {
1416
type: 'record',
@@ -22,7 +24,12 @@
2224

2325
<template>
2426
<div class="avro-schema">
25-
<AvroNode v-if="rootField()" :field="rootField()" :root="true" />
27+
<AvroNode
28+
v-if="rootField()"
29+
:field="rootField()"
30+
:record-reference-types="createRecordTypesRegistry(rootField())"
31+
:root="true"
32+
/>
2633
</div>
2734
</template>
2835

0 commit comments

Comments
 (0)