Skip to content

Commit 8493fc1

Browse files
committed
feat: added support for type fixed and bytes, now they get converted to string model
1 parent 7443f1c commit 8493fc1

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/helpers/AvroToMetaModel.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,15 @@ export function toStringModel(
176176
name: string
177177
): StringModel | undefined {
178178
if (
179-
(typeof avroSchemaModel.type === 'string' ||
179+
((typeof avroSchemaModel.type === 'string' ||
180+
Array.isArray(avroSchemaModel.type)) &&
181+
avroSchemaModel.type.includes('string')) ||
182+
((typeof avroSchemaModel.type === 'string' ||
183+
Array.isArray(avroSchemaModel.type)) &&
184+
avroSchemaModel.type.includes('fixed')) ||
185+
((typeof avroSchemaModel.type === 'string' ||
180186
Array.isArray(avroSchemaModel.type)) &&
181-
avroSchemaModel.type.includes('string')
187+
avroSchemaModel.type.includes('bytes'))
182188
) {
183189
return new StringModel(
184190
name,

test/helpers/AvroToMetaModel.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,26 @@ describe('AvroToMetaModel', () => {
178178
expect(model).not.toBeUndefined();
179179
expect(model instanceof ArrayModel).toBeTruthy();
180180
});
181+
test('should handle AvroSchema value of type fixed', () => {
182+
const av = new AvroSchema();
183+
av.name = 'test';
184+
av.type = { name: 'test1', type: 'fixed' };
185+
186+
const model = AvroToMetaModel(av);
187+
188+
expect(model).not.toBeUndefined();
189+
expect(model instanceof StringModel).toBeTruthy();
190+
});
191+
test('should handle AvroSchema value of type bytes', () => {
192+
const av = new AvroSchema();
193+
av.name = 'test';
194+
av.type = { name: 'test1', type: 'bytes' };
195+
196+
const model = AvroToMetaModel(av);
197+
198+
expect(model).not.toBeUndefined();
199+
expect(model instanceof StringModel).toBeTruthy();
200+
});
181201
test('should handle AvroSchema value of type', () => {
182202
const av = new AvroSchema();
183203
av.name = 'test';

0 commit comments

Comments
 (0)