From 33f82980f5d3f25846be33711296a2c807388e7e Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 1 Mar 2019 17:37:35 +0530 Subject: [PATCH 1/5] Fix Path separator --- src/components/Compiler/Compiler.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/Compiler/Compiler.ts b/src/components/Compiler/Compiler.ts index 9c8c741..89fc1b1 100644 --- a/src/components/Compiler/Compiler.ts +++ b/src/components/Compiler/Compiler.ts @@ -10,7 +10,7 @@ import { BaseCompiler } from "./base/BaseCompiler"; export class Compiler extends BaseCompiler { public exports: ExportModel[]; - public constructor(outputDir: string, public logicalTypes?: { [key: string ]: string}) { + public constructor(outputDir: string, public logicalTypes?: { [key: string]: string }) { super(); this.classPath = path.resolve(outputDir); @@ -20,7 +20,7 @@ export class Compiler extends BaseCompiler { try { fs.readdir(schemaPath, async (err, files) => { for (const file of files) { - const fullPath = schemaPath + "/" + file; + const fullPath = schemaPath + path.sep + file; if (fs.statSync(fullPath).isDirectory()) { await this.compileFolder(fullPath); @@ -41,8 +41,8 @@ export class Compiler extends BaseCompiler { const classConverter = new ClassConverter(this.logicalTypes); data = classConverter.getData(data); - const namespace = data.namespace.replace(/\./g, "/"); - const outputDir = `${this.classPath}/${namespace}`; + const namespace = data.namespace.replace(/\./g, path.sep); + const outputDir = `${this.classPath}${path.sep}${namespace}`; if (TypeHelper.isRecordType(data)) { classConverter.convert(data); @@ -63,20 +63,20 @@ export class Compiler extends BaseCompiler { } protected saveClass(outputDir: string, data: any, result: string) { - const classFile = `${outputDir}/${data.name}.ts`; + const classFile = `${outputDir}${path.sep}${data.name}.ts`; fs.writeFileSync(classFile, result); } protected saveEnums(enums: ExportModel[], outputDir: string) { for (const enumFile of enums) { - const savePath = `${outputDir}/${enumFile.name}Enum.ts`; + const savePath = `${outputDir}${path.sep}${enumFile.name}Enum.ts`; fs.writeFileSync(savePath, enumFile.content); } } protected saveBaseAvroRecord() { - const avroRecordPath = `${this.classPath}/BaseAvroRecord.ts`; + const avroRecordPath = `${this.classPath}${path.sep}BaseAvroRecord.ts`; if (!fs.existsSync(avroRecordPath)) { fs.writeFileSync( From 1777457ef560cfd53eff5c61c076b537de53ae10 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Wed, 27 Mar 2019 16:37:21 +0530 Subject: [PATCH 2/5] Add classname to Default enum value Default enums only had the value and not the class name. This was causing compile error. Now it will be ClassName.EnumName --- src/helpers/TypeHelper.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/helpers/TypeHelper.ts b/src/helpers/TypeHelper.ts index 5c20367..d92f100 100644 --- a/src/helpers/TypeHelper.ts +++ b/src/helpers/TypeHelper.ts @@ -83,6 +83,10 @@ export class TypeHelper { return `[]`; } + if (this.isEnumType(field.type)) { + return `${field.type.name}.${field.default}`; + } + return field.default; } } From 97672f8d119d611b4c295bc0ba8d4bd1eb9b30d6 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 5 Apr 2019 12:26:10 +0530 Subject: [PATCH 3/5] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9909c02..c3d9878 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@degordian/avro-to-typescript", + "name": "@sidv/avro-to-typescript", "version": "2.2.3", "description": "Package for converting Avro schema files (.avsc) to TypeScript class files", "keywords": [ From 48137c23c38bc33dcb1b81f329b90ddb41e91df8 Mon Sep 17 00:00:00 2001 From: Sidharth V Date: Fri, 5 Apr 2019 07:22:20 -0700 Subject: [PATCH 4/5] Revert "Update package.json" This reverts commit 97672f8d119d611b4c295bc0ba8d4bd1eb9b30d6. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c3d9878..9909c02 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@sidv/avro-to-typescript", + "name": "@degordian/avro-to-typescript", "version": "2.2.3", "description": "Package for converting Avro schema files (.avsc) to TypeScript class files", "keywords": [ From b8a7887830b348fe6fdc4d6e27f5c4bc05c59920 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 17 Oct 2019 14:05:27 +0530 Subject: [PATCH 5/5] Update RecordConverter.ts Handle "type": { "type": "string", "avro.java.string": "String" } --- src/components/Converters/RecordConverter.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Converters/RecordConverter.ts b/src/components/Converters/RecordConverter.ts index edfddef..703a5ac 100644 --- a/src/components/Converters/RecordConverter.ts +++ b/src/components/Converters/RecordConverter.ts @@ -40,15 +40,19 @@ export class RecordConverter extends BaseConverter { } protected convertType(type: Type): string { + if(typeof type === "object" && typeof type.type === "string") { + type = type.type; + } + if (typeof type === "string") { const converter = new PrimitiveConverter(); - + return converter.convert(type); } if (TypeHelper.isLogicalType(type)) { const converter = new LogicalTypeConverter(this.logicalTypesMap); - + return converter.convert(type); }