Skip to content

Commit

Permalink
feat: adding support for avro 1.8.2 (#6)
Browse files Browse the repository at this point in the history
* Added support for 1.8.2

* Bumped up version

* Added uuid test

* Fixed indentation

* Undo version change since pipeline will handle it
  • Loading branch information
germanschnyder authored Aug 24, 2020
1 parent 91bd251 commit 6447ab8
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 6 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ module.exports.getMimeTypes = () => {
'application/vnd.apache.avro;version=1.9.0',
'application/vnd.apache.avro+json;version=1.9.0',
'application/vnd.apache.avro+yaml;version=1.9.0',
'application/vnd.apache.avro;version=1.8.2',
'application/vnd.apache.avro+json;version=1.8.2',
'application/vnd.apache.avro+yaml;version=1.8.2'
];
};
11 changes: 11 additions & 0 deletions tests/asyncapi-avro-1.8.2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
asyncapi: 2.0.0
info:
title: My API
version: '1.0.0'
channels:
mychannel:
publish:
message:
schemaFormat: application/vnd.apache.avro;version=1.8.2
payload:
$ref: 'schemas/Person-1.8.2.avsc'
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ channels:
message:
schemaFormat: application/vnd.apache.avro;version=1.9.0
payload:
$ref: 'schemas/Person.avsc'
$ref: 'schemas/Person-1.9.0.avsc'
17 changes: 12 additions & 5 deletions tests/parse.test.js

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

File renamed without changes.
21 changes: 21 additions & 0 deletions tests/schemas/Person-1.9.0.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Person",
"type": "record",
"fields": [
{"name": "name", "type": "string"},
{"name": "age", "type": ["null", "int"], "default": null},
{
"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"}]
}
},
{"name": "someid", "type": "uuid"}
]
}
5 changes: 5 additions & 0 deletions tests/to-json-schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ describe('avroToJsonSchema()', function () {
const result = await avroToJsonSchema({ type: 'string' });
expect(result).toEqual({ type: 'string' });
});

it('transforms uuid values', async function () {
const result = await avroToJsonSchema({ type: 'uuid' });
expect(result).toEqual({ type: 'string' });
});

it('transforms fixed values', async function () {
const result = await avroToJsonSchema({ type: 'fixed', size: 5 });
Expand Down
1 change: 1 addition & 0 deletions to-json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const typeMappings = {
array: 'array',
enum: 'string',
record: 'object',
uuid: 'string',
};

module.exports.avroToJsonSchema = async function avroToJsonSchema(avroDefinition) {
Expand Down

0 comments on commit 6447ab8

Please sign in to comment.