19
19
import org .apache .kafka .common .message .RequestHeaderData ;
20
20
import org .apache .kafka .common .message .ResponseHeaderData ;
21
21
import org .apache .kafka .common .protocol .types .BoundField ;
22
+ import org .apache .kafka .common .protocol .types .Field ;
22
23
import org .apache .kafka .common .protocol .types .Schema ;
23
24
import org .apache .kafka .common .protocol .types .TaggedFields ;
24
25
import org .apache .kafka .common .protocol .types .Type ;
27
28
import java .util .LinkedHashSet ;
28
29
import java .util .Map ;
29
30
import java .util .Set ;
31
+ import java .util .TreeMap ;
30
32
31
33
public class Protocol {
32
34
@@ -49,7 +51,23 @@ private static void schemaToBnfHtml(Schema schema, StringBuilder b, int indentSi
49
51
subTypes .put (field .def .name , type .arrayElementType ().get ());
50
52
}
51
53
} else if (type instanceof TaggedFields ) {
52
- b .append ("_tagged_fields " );
54
+ Map <Integer , Field > taggedFields = new TreeMap <>(((TaggedFields ) type ).fields ());
55
+ taggedFields .forEach ((tag , taggedField ) -> {
56
+ if (taggedField .type .isArray ()) {
57
+ b .append ("[" );
58
+ b .append (taggedField .name );
59
+ b .append ("]" );
60
+ if (!subTypes .containsKey (taggedField .name ))
61
+ subTypes .put (taggedField .name + "<tag: " + tag .toString () + ">" , taggedField .type .arrayElementType ().get ());
62
+ } else {
63
+ b .append (taggedField .name );
64
+ if (!subTypes .containsKey (taggedField .name ))
65
+ subTypes .put (taggedField .name + "<tag: " + tag .toString () + ">" , taggedField .type );
66
+ }
67
+ b .append ("<tag: " );
68
+ b .append (tag );
69
+ b .append ("> " );
70
+ });
53
71
} else {
54
72
b .append (field .def .name );
55
73
b .append (" " );
@@ -90,6 +108,12 @@ private static void populateSchemaFields(Schema schema, Set<BoundField> fields)
90
108
}
91
109
}
92
110
111
+ private static void appendFieldNameToTable (String name , StringBuilder b ) {
112
+ b .append ("<td>" );
113
+ b .append (name );
114
+ b .append ("</td>" );
115
+ }
116
+
93
117
private static void schemaToFieldTableHtml (Schema schema , StringBuilder b ) {
94
118
Set <BoundField > fields = new LinkedHashSet <>();
95
119
populateSchemaFields (schema , fields );
@@ -101,28 +125,12 @@ private static void schemaToFieldTableHtml(Schema schema, StringBuilder b) {
101
125
b .append ("</tr>" );
102
126
for (BoundField field : fields ) {
103
127
b .append ("<tr>\n " );
104
- b .append ("<td>" );
105
- b .append (field .def .name );
106
- b .append ("</td>" );
107
- b .append ("<td>" );
108
128
if (field .def .type instanceof TaggedFields ) {
109
129
TaggedFields taggedFields = (TaggedFields ) field .def .type ;
110
130
// Only include the field in the table if there are actually tags defined
111
131
if (taggedFields .numFields () > 0 ) {
112
- b .append ("<table class=\" data-table\" ><tbody>\n " );
113
- b .append ("<tr>" );
114
- b .append ("<th>Tag</th>\n " );
115
- b .append ("<th>Tagged field</th>\n " );
116
- b .append ("<th>Description</th>\n " );
117
- b .append ("</tr>" );
118
132
taggedFields .fields ().forEach ((tag , taggedField ) -> {
119
- b .append ("<tr>\n " );
120
- b .append ("<td>" );
121
- b .append (tag );
122
- b .append ("</td>" );
123
- b .append ("<td>" );
124
- b .append (taggedField .name );
125
- b .append ("</td>" );
133
+ appendFieldNameToTable (taggedField .name + "<tag: " + tag .toString () + ">" , b );
126
134
b .append ("<td>" );
127
135
b .append (taggedField .docString );
128
136
if (taggedField .type .isArray ()) {
@@ -136,11 +144,10 @@ private static void schemaToFieldTableHtml(Schema schema, StringBuilder b) {
136
144
b .append ("</td>" );
137
145
b .append ("</tr>\n " );
138
146
});
139
- b .append ("</tbody></table>\n " );
140
- } else {
141
- b .append (field .def .docString );
142
147
}
143
148
} else {
149
+ appendFieldNameToTable (field .def .name , b );
150
+ b .append ("<td>" );
144
151
b .append (field .def .docString );
145
152
}
146
153
b .append ("</td>" );
0 commit comments