Skip to content

Commit be78b76

Browse files
feat: first support of bindings for AVRO key (#77)
* feat: support of AVRO bindings key Close #67 * fixup: PR review, only handle kafka key on bindings * fix linter errors * fixup: magicmatatjahu PR suggestion Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com> Co-authored-by: Maciej Urbańczyk <urbanczyk.maciej.95@gmail.com>
1 parent c8c9ce5 commit be78b76

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ module.exports.parse = async ({ message, defaultSchemaFormat }) => {
77
message['x-parser-original-payload'] = message.payload;
88
message.payload = transformed;
99
delete message.schemaFormat;
10+
11+
// remove that function when https://github.com/asyncapi/spec/issues/622 will be introduced in AsyncAPI spec
12+
async function handleKafkaProtocolKey() {
13+
if (message.bindings && message.bindings.kafka) {
14+
const key = message.bindings.kafka.key;
15+
if (key) {
16+
const bindingsTransformed = await avroToJsonSchema(key);
17+
message['x-parser-original-bindings-kafka-key'] = key;
18+
message.bindings.kafka.key = bindingsTransformed;
19+
}
20+
}
21+
}
22+
23+
await handleKafkaProtocolKey();
1024
};
1125

1226
module.exports.getMimeTypes = () => {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
asyncapi: 2.0.0
2+
info:
3+
title: My API
4+
version: '1.0.0'
5+
channels:
6+
mychannel:
7+
publish:
8+
message:
9+
schemaFormat: application/vnd.apache.avro;version=1.9.0
10+
payload:
11+
$ref: 'schemas/Person-1.9.0-namespace.avsc'
12+
bindings:
13+
kafka:
14+
key:
15+
$ref: 'schemas/Person-1.9.0-namespace.avsc'
16+
mqtt:
17+
x-test:
18+
type: string
19+

tests/parse.test.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)