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

feat: first support of bindings for AVRO key #77

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can go straight to Kafka protocol instead of iterating. I don't know any other protocol that has a key property that can be defined with Avro.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if fact this was my first approach but i guess maybe new EDI technologies in future can handle message key like nats.io ... but ok i will change this implementation to only support the kafka protocol

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done @fmvilas

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.