@asyncapi/avro-schema-parser
Advanced tools
Comparing version 0.4.0 to 0.5.0
14
index.js
@@ -10,2 +10,16 @@ const { avroToJsonSchema } = require('./to-json-schema.js'); | ||
delete message.schemaFormat; | ||
// remove that function when https://github.com/asyncapi/spec/issues/622 will be introduced in AsyncAPI spec | ||
async function handleKafkaProtocolKey() { | ||
if (message.bindings && message.bindings.kafka) { | ||
const key = message.bindings.kafka.key; | ||
if (key) { | ||
const bindingsTransformed = await avroToJsonSchema(key); | ||
message['x-parser-original-bindings-kafka-key'] = key; | ||
message.bindings.kafka.key = bindingsTransformed; | ||
} | ||
} | ||
} | ||
await handleKafkaProtocolKey(); | ||
}; | ||
@@ -12,0 +26,0 @@ |
{ | ||
"name": "@asyncapi/avro-schema-parser", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "An AsyncAPI schema parser for Avro 1.x schemas.", | ||
@@ -33,3 +33,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@asyncapi/parser": "^1.8.1", | ||
"@asyncapi/parser": "^1.9.0", | ||
"@semantic-release/commit-analyzer": "^8.0.1", | ||
@@ -36,0 +36,0 @@ "@semantic-release/github": "^7.0.4", |
@@ -15,2 +15,5 @@ const fs = require('fs'); | ||
const inputWithAvro190WithBindings = fs.readFileSync(path.resolve(__dirname, './asyncapi-avro-1.9.0-bindings.yaml'), 'utf8'); | ||
const outputWithAvro190WithBindings = '{"asyncapi":"2.0.0","info":{"title":"My API","version":"1.0.0"},"channels":{"mychannel":{"publish":{"message":{"payload":{"type":"object","properties":{"name":{"type":"string","examples":["Donkey"],"x-parser-schema-id":"<anonymous-schema-1>"},"age":{"oneOf":[{"type":"integer","minimum":-2147483648,"maximum":2147483647,"examples":[123],"x-parser-schema-id":"<anonymous-schema-3>"},{"type":"null","x-parser-schema-id":"<anonymous-schema-4>"}],"default":null,"x-parser-schema-id":"<anonymous-schema-2>"},"favoriteProgrammingLanguage":{"type":"string","enum":["JS","Java","Go","Rust","C"],"default":"JS","x-parser-schema-id":"<anonymous-schema-5>"},"address":{"type":"object","properties":{"zipcode":{"type":"integer","minimum":-2147483648,"maximum":2147483647,"examples":[53003],"x-parser-schema-id":"<anonymous-schema-7>"}},"x-parser-schema-id":"<anonymous-schema-6>"},"someid":{"type":"string","x-parser-schema-id":"<anonymous-schema-8>"}},"x-parser-schema-id":"com.company.Person"},"bindings":{"kafka":{"key":{"type":"object","properties":{"name":{"type":"string","examples":["Donkey"]},"age":{"oneOf":[{"type":"integer","minimum":-2147483648,"maximum":2147483647,"examples":[123]},{"type":"null"}],"default":null},"favoriteProgrammingLanguage":{"type":"string","enum":["JS","Java","Go","Rust","C"],"default":"JS"},"address":{"type":"object","properties":{"zipcode":{"type":"integer","minimum":-2147483648,"maximum":2147483647,"examples":[53003]}}},"someid":{"type":"string"}},"x-parser-schema-id":"com.company.Person"}},"mqtt":{"x-test":{"type":"string"}}},"x-parser-original-schema-format":"application/vnd.apache.avro;version=1.9.0","x-parser-original-payload":{"name":"Person","namespace":"com.company","type":"record","fields":[{"name":"name","type":"string","example":"Donkey"},{"name":"age","type":["null","int"],"default":null,"example":"123"},{"name":"favoriteProgrammingLanguage","type":{"name":"ProgrammingLanguage","type":"enum","symbols":["JS","Java","Go","Rust","C"],"default":"JS"}},{"name":"address","type":{"name":"Address","type":"record","fields":[{"name":"zipcode","type":"int","example":"53003"}]}},{"name":"someid","type":"uuid"}]},"x-parser-original-bindings-kafka-key":{"name":"Person","namespace":"com.company","type":"record","fields":[{"name":"name","type":"string","example":"Donkey"},{"name":"age","type":["null","int"],"default":null,"example":"123"},{"name":"favoriteProgrammingLanguage","type":{"name":"ProgrammingLanguage","type":"enum","symbols":["JS","Java","Go","Rust","C"],"default":"JS"}},{"name":"address","type":{"name":"Address","type":"record","fields":[{"name":"zipcode","type":"int","example":"53003"}]}},{"name":"someid","type":"uuid"}]},"schemaFormat":"application/vnd.aai.asyncapi;version=2.0.0","x-parser-message-parsed":true,"x-parser-message-name":"<anonymous-message-1>"}}}},"x-parser-spec-parsed":true}'; | ||
parser.registerSchemaParser(avroSchemaParser); | ||
@@ -31,2 +34,6 @@ | ||
}); | ||
it('should parse Avro schema in kafka bindings', async function() { | ||
const result = await parser.parse(inputWithAvro190WithBindings, { path: __filename }); | ||
expect(JSON.stringify(result.json())).toEqual(outputWithAvro190WithBindings); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
199646
31
323
5