From f3ed099ceeceeba56baaea326742a93642d300b2 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 25 Sep 2024 16:28:11 +0200 Subject: [PATCH 1/2] renamed CMObject to CMObjectField and added the name --- .../main/java/com/schwarz/crystalapi/schema/CMType.kt | 9 +++++---- .../generation/model/SchemaGeneration.kt | 7 ++++--- .../src/test/resources/ExpectedSchema.txt | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt index 51d16a5..f086421 100644 --- a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt +++ b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt @@ -3,16 +3,17 @@ package com.schwarz.crystalapi.schema import com.schwarz.crystalapi.ITypeConverter sealed interface CMType { + val name: String val path: String } -open class CMJsonField(val name: String, override val path: String) : CMType +open class CMJsonField(override val name: String, override val path: String) : CMType -open class CMJsonList(val name: String, override val path: String) : CMType +open class CMJsonList(override val name: String, override val path: String) : CMType -class CMObject(val element: T, override val path: String) : CMType +class CMObjectField(val element: T, override val name: String, override val path: String) : CMType -class CMObjectList(val element: T, val name: String, override val path: String) : CMType +class CMObjectList(val element: T, override val name: String, override val path: String) : CMType class CMConverterField( name: String, diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt index 8402976..38f28ce 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt @@ -170,7 +170,7 @@ class SchemaGeneration { return when { isIterable && isObject -> buildObjectListFormat(propertyType, fieldName, propertyAccessPath) - isObject -> buildObjectFormat(propertyType, propertyAccessPath) + isObject -> buildObjectFormat(propertyType, fieldName, propertyAccessPath) else -> buildSimpleFormat(fieldName) } } @@ -188,9 +188,10 @@ class SchemaGeneration { private fun buildSimpleFormat(fieldName: String): String = """%T("$fieldName", $pathAttributeName)""" - private fun buildObjectFormat(propertyType: TypeName, propertyAccessPath: String): String = + private fun buildObjectFormat(propertyType: TypeName, fieldName: String, propertyAccessPath: String): String = """%T( $propertyType($propertyAccessPath), + "$fieldName", $pathAttributeName, )""" @@ -203,7 +204,7 @@ class SchemaGeneration { hasProperty -> CMConverterField::class.asTypeName() isIterable && isObject -> CMObjectList::class.asTypeName() isIterable -> CMJsonList::class.asTypeName() - isObject -> CMObject::class.asTypeName() + isObject -> CMObjectField::class.asTypeName() else -> CMJsonField::class.asTypeName() } diff --git a/crystal-map-processor/src/test/resources/ExpectedSchema.txt b/crystal-map-processor/src/test/resources/ExpectedSchema.txt index 484dd5f..1fe6b72 100644 --- a/crystal-map-processor/src/test/resources/ExpectedSchema.txt +++ b/crystal-map-processor/src/test/resources/ExpectedSchema.txt @@ -30,6 +30,7 @@ public open class SubSchema( public val someObject: CMObject = CMObject( com.kaufland.testModels.TestObjectSchema(if (path.isBlank()) "someObject" else "$path.someObject"), + "someObject", path, ) From 58cbea928987bd8a49b445f9ff957815984ec12e Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Thu, 26 Sep 2024 09:08:12 +0200 Subject: [PATCH 2/2] fix expectedSchema --- crystal-map-processor/src/test/resources/ExpectedSchema.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crystal-map-processor/src/test/resources/ExpectedSchema.txt b/crystal-map-processor/src/test/resources/ExpectedSchema.txt index 1fe6b72..a76ad1f 100644 --- a/crystal-map-processor/src/test/resources/ExpectedSchema.txt +++ b/crystal-map-processor/src/test/resources/ExpectedSchema.txt @@ -9,7 +9,7 @@ import com.schwarz.crystalapi.schema.CMConverterField import com.schwarz.crystalapi.schema.CMConverterList import com.schwarz.crystalapi.schema.CMJsonField import com.schwarz.crystalapi.schema.CMJsonList -import com.schwarz.crystalapi.schema.CMObject +import com.schwarz.crystalapi.schema.CMObjectField import com.schwarz.crystalapi.schema.CMObjectList import com.schwarz.crystalapi.schema.Schema import java.time.OffsetDateTime @@ -27,7 +27,7 @@ public open class SubSchema( public val list: CMJsonList = CMJsonList("list", path) - public val someObject: CMObject = CMObject( + public val someObject: CMObjectField = CMObjectField( com.kaufland.testModels.TestObjectSchema(if (path.isBlank()) "someObject" else "$path.someObject"), "someObject",