Skip to content

Commit

Permalink
resolve allegro#1907 | handle record references when presenting avro …
Browse files Browse the repository at this point in the history
…schema
  • Loading branch information
MiloszKorman committed Nov 25, 2024
1 parent f4099e4 commit 86ec89c
Show file tree
Hide file tree
Showing 8 changed files with 491 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hermes-console/json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion hermes-console/json-server/topics.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion hermes-console/src/dummy/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions hermes-console/src/views/topic/schema-panel/AvroTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface AvroSchema {
type: Type;
name: string;
namespace?: string;
doc: string;
fields?: Field[];
default?: DefaultTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<script lang="ts" setup>
import { defineProps, ref } from 'vue';
import type { AvroSchema, Type } from '@/views/topic/schema-panel/AvroTypes';
import { getRecordTypesRegistryEntry } from '@/views/topic/schema-panel/avro-viewer/avro-record-types-registry';
import type {
AvroSchema,
RecordType,
Type,
} from '@/views/topic/schema-panel/AvroTypes';
const props = defineProps<{
field: AvroSchema;
recordReferenceTypes: Map<string, RecordType>;
root: boolean;
}>();
const expanded = ref(true);
Expand Down Expand Up @@ -62,10 +68,17 @@
};
const types = getTypes(props.field.type);
const isRecord = types.some((type: Type) => type.includes('record'));
const recordTypeReference = getRecordTypesRegistryEntry(
props.recordReferenceTypes,
props.field.type,
);
const isRecord =
!!recordTypeReference ||
types.some((type: Type) => type.includes('record'));
const isEnum = types.some((type: Type) => type.includes('enum'));
const expandable = isRecord || isEnum;
const nestedType = isRecord && findNestedType(props.field.type);
const nestedType =
isRecord && (recordTypeReference || findNestedType(props.field.type));
const enumSymbols = isEnum && findEnumSymbols(props.field.type);
const toggle = (event: Event) => {
Expand Down Expand Up @@ -100,6 +113,7 @@
v-for="nestedField in nestedType.fields"
:key="nestedField.name"
:field="nestedField"
:record-reference-types="props.recordReferenceTypes"
:root="false"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts" setup>
import { createRecordTypesRegistry } from '@/views/topic/schema-panel/avro-viewer/avro-record-types-registry';
import AvroNode from '@/views/topic/schema-panel/avro-viewer/AvroNode.vue';
import type { AvroSchema } from '@/views/topic/schema-panel/AvroTypes';
const props = defineProps<{
Expand All @@ -9,6 +10,7 @@
const jsonSchema: AvroSchema = JSON.parse(props.schema);
return {
name: jsonSchema.name,
namespace: jsonSchema.namespace,
doc: jsonSchema.doc,
type: {
type: 'record',
Expand All @@ -22,7 +24,12 @@

<template>
<div class="avro-schema">
<AvroNode v-if="rootField()" :field="rootField()" :root="true" />
<AvroNode
v-if="rootField()"
:field="rootField()"
:record-reference-types="createRecordTypesRegistry(rootField())"
:root="true"
/>
</div>
</template>

Expand Down
Loading

0 comments on commit 86ec89c

Please sign in to comment.