From c6785f1a4fe201c0cb09eaf1387587acc1f30c62 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 20 Jun 2023 20:20:47 +0600 Subject: [PATCH] fixes in types generation --- CHANGELOG.md | 4 ++++ repos/generator/src/main/kotlin/Processor.kt | 6 +++++- .../src/commonMain/kotlin/GeneratedModelsTest.kt | 16 +++++++++------- .../generator/test/src/commonMain/kotlin/Test.kt | 1 + 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3295927ce03..5c773c885f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.19.5 +* `Repos`: + * `Generator`: + * Fixes in new type generation + ## 0.19.4 * `Versions`: diff --git a/repos/generator/src/main/kotlin/Processor.kt b/repos/generator/src/main/kotlin/Processor.kt index 9e8780b826c..1e64040a48b 100644 --- a/repos/generator/src/main/kotlin/Processor.kt +++ b/repos/generator/src/main/kotlin/Processor.kt @@ -100,7 +100,11 @@ class Processor( primaryConstructor( FunSpec.constructorBuilder().apply { ksClassProperties.forEach { - addParameter(it.simpleName.getShortName(), it.typeName) + addParameter( + ParameterSpec.builder(it.simpleName.getShortName(), it.typeName).apply { + annotations += it.annotations.map { it.toAnnotationSpec() } + }.build() + ) typeBuilder.addProperty( PropertySpec.builder(it.simpleName.getShortName(), it.typeName, KModifier.OVERRIDE).apply { initializer(it.simpleName.getShortName()) diff --git a/repos/generator/test/src/commonMain/kotlin/GeneratedModelsTest.kt b/repos/generator/test/src/commonMain/kotlin/GeneratedModelsTest.kt index 27111d44cc8..97332c73711 100644 --- a/repos/generator/test/src/commonMain/kotlin/GeneratedModelsTest.kt +++ b/repos/generator/test/src/commonMain/kotlin/GeneratedModelsTest.kt @@ -11,18 +11,20 @@ import kotlinx.serialization.Serializable @Serializable @SerialName(value = "NewTest") public data class NewTest( - public override val property1: String, - public override val property2: Int, - public override val parent: ParentTypeId?, + override val property1: String, + override val property2: Int, + @Serializable + override val parent: ParentTypeId?, ) : Test @Serializable @SerialName(value = "RegisteredTest") public data class RegisteredTest( - public override val id: TestId, - public override val property1: String, - public override val property2: Int, - public override val parent: ParentTypeId?, + override val id: TestId, + override val property1: String, + override val property2: Int, + @Serializable + override val parent: ParentTypeId?, ) : Test, IRegisteredTest public fun Test.asNew(): NewTest = NewTest(property1, property2, parent) diff --git a/repos/generator/test/src/commonMain/kotlin/Test.kt b/repos/generator/test/src/commonMain/kotlin/Test.kt index 24bc9a92f4b..6046eb4071a 100644 --- a/repos/generator/test/src/commonMain/kotlin/Test.kt +++ b/repos/generator/test/src/commonMain/kotlin/Test.kt @@ -17,6 +17,7 @@ typealias ParentTypeId = TestId sealed interface Test { val property1: String val property2: Int + @Serializable val parent: ParentTypeId? @GenerateCRUDModelExcludeOverride