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 dcfcc72
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
const { avroToJsonSchema } = require('./to-json-schema.js');

module.exports.parse = async ({ message, defaultSchemaFormat }) => {
console.log("link ok")
const transformed = await avroToJsonSchema(message.payload);


message['x-parser-original-schema-format'] = message.schemaFormat || defaultSchemaFormat;
message['x-parser-original-payload'] = message.payload;
message.payload = transformed;
delete message.schemaFormat;

async function handleKafkaKeyBindings() {
// not available from test but what about from generator ?
// if (message.hasBinding('kafka')) {
if (message.bindings && message.bindings.kafka && message.bindings.kafka.key) {
const bindingsTransformed = await avroToJsonSchema(message.bindings.kafka.key);
message['x-parser-original-bindings-kafka-key'] = message.bindings.kafka.key;
message.bindings.kafka.key = bindingsTransformed;
}
}

await handleKafkaKeyBindings();
};

module.exports.getMimeTypes = () => {
Expand Down
15 changes: 15 additions & 0 deletions tests/asyncapi-avro-1.9.0-bindings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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'
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 dcfcc72

Please sign in to comment.