Skip to content

Commit

Permalink
feat: first support of bindings for kafka key
Browse files Browse the repository at this point in the history
Close #67
  • Loading branch information
M3lkior committed Sep 9, 2021
1 parent c8c9ce5 commit 721731f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ module.exports.parse = async ({ message, defaultSchemaFormat }) => {
message['x-parser-original-payload'] = message.payload;
message.payload = transformed;
delete message.schemaFormat;

async function handleProtocolKey() {
for (const protocol of Object.keys(message.bindings)) {
var key = message.bindings[protocol].key;
if (key) {
const bindingsTransformed = await avroToJsonSchema(key);
message[`x-parser-original-bindings-${protocol}-key`] = key;
message.bindings[protocol].key = bindingsTransformed;
}
}
}

await handleProtocolKey();
};

module.exports.getMimeTypes = () => {
Expand Down
19 changes: 19 additions & 0 deletions tests/asyncapi-avro-1.9.0-bindings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
asyncapi: 2.0.0
info:
title: My API
version: '1.0.0'
channels:
mychannel:
publish:
message:
schemaFormat: application/vnd.apache.avro;version=1.9.0
payload:
$ref: 'schemas/Person-1.9.0-namespace.avsc'
bindings:
kafka:
key:
$ref: 'schemas/Person-1.9.0-namespace.avsc'
mqtt:
x-test:
type: string

7 changes: 7 additions & 0 deletions tests/parse.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 721731f

Please sign in to comment.