Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve #1907 | handle record references when presenting avro schema #1911

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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\"}]}",
Copy link
Author

@MiloszKorman MiloszKorman Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if this change and feature are significant enough to warrant adding new field with such record type reference to the DummyEvent, or should I just work with this more complex type locally, but merge to master with DummyEvent schema unchanged

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is, it may be helpful in case of any debug related to this feature

"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
Loading