From dc1b8e4cac299d60af921627a37c6ecf6e03abdc Mon Sep 17 00:00:00 2001 From: Ulrik Andersen Date: Mon, 18 Nov 2024 21:19:26 +0100 Subject: [PATCH] JacksonModelGenerator is now simply ModelGenerator (#330) --- .../com/cjbooms/fabrikt/cli/CodeGenerator.kt | 5 ++--- .../fabrikt/generators/GeneratorUtils.kt | 2 +- .../generators/client/ClientGeneratorUtils.kt | 2 +- .../controller/ControllerGeneratorUtils.kt | 2 +- ...sonModelGenerator.kt => ModelGenerator.kt} | 2 +- .../KotlinSerializationModelGeneratorTest.kt | 8 +++---- .../fabrikt/generators/ModelGeneratorTest.kt | 22 +++++++++---------- .../generators/OkHttpClientGeneratorTest.kt | 6 ++--- .../OpenFeignClientGeneratorTest.kt | 4 ++-- .../generators/ResourceGeneratorTest.kt | 4 ++-- 10 files changed, 28 insertions(+), 29 deletions(-) rename src/main/kotlin/com/cjbooms/fabrikt/generators/model/{JacksonModelGenerator.kt => ModelGenerator.kt} (99%) diff --git a/src/main/kotlin/com/cjbooms/fabrikt/cli/CodeGenerator.kt b/src/main/kotlin/com/cjbooms/fabrikt/cli/CodeGenerator.kt index 448347d5..7abd53b9 100644 --- a/src/main/kotlin/com/cjbooms/fabrikt/cli/CodeGenerator.kt +++ b/src/main/kotlin/com/cjbooms/fabrikt/cli/CodeGenerator.kt @@ -11,11 +11,10 @@ import com.cjbooms.fabrikt.generators.client.OpenFeignInterfaceGenerator import com.cjbooms.fabrikt.generators.controller.KtorControllerInterfaceGenerator import com.cjbooms.fabrikt.generators.controller.MicronautControllerInterfaceGenerator import com.cjbooms.fabrikt.generators.controller.SpringControllerInterfaceGenerator -import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator +import com.cjbooms.fabrikt.generators.model.ModelGenerator import com.cjbooms.fabrikt.generators.model.QuarkusReflectionModelGenerator import com.cjbooms.fabrikt.model.GeneratedFile import com.cjbooms.fabrikt.model.KotlinSourceSet -import com.cjbooms.fabrikt.model.KotlinTypes import com.cjbooms.fabrikt.model.Models import com.cjbooms.fabrikt.model.ResourceFile import com.cjbooms.fabrikt.model.ResourceSourceSet @@ -63,7 +62,7 @@ class CodeGenerator( private fun resourceSet(resFiles: Collection) = setOf(ResourceSourceSet(resFiles, resourcesPath)) private fun models(): Models = - JacksonModelGenerator(packages, sourceApi).generate() + ModelGenerator(packages, sourceApi).generate() private fun resources(models: Models): List = listOfNotNull(QuarkusReflectionModelGenerator(models).generate()) diff --git a/src/main/kotlin/com/cjbooms/fabrikt/generators/GeneratorUtils.kt b/src/main/kotlin/com/cjbooms/fabrikt/generators/GeneratorUtils.kt index 5e6028e6..876d2007 100644 --- a/src/main/kotlin/com/cjbooms/fabrikt/generators/GeneratorUtils.kt +++ b/src/main/kotlin/com/cjbooms/fabrikt/generators/GeneratorUtils.kt @@ -1,6 +1,6 @@ package com.cjbooms.fabrikt.generators -import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator.Companion.toModelType +import com.cjbooms.fabrikt.generators.model.ModelGenerator.Companion.toModelType import com.cjbooms.fabrikt.model.BodyParameter import com.cjbooms.fabrikt.model.IncomingParameter import com.cjbooms.fabrikt.model.KotlinTypeInfo diff --git a/src/main/kotlin/com/cjbooms/fabrikt/generators/client/ClientGeneratorUtils.kt b/src/main/kotlin/com/cjbooms/fabrikt/generators/client/ClientGeneratorUtils.kt index a80eaa2a..53a28300 100644 --- a/src/main/kotlin/com/cjbooms/fabrikt/generators/client/ClientGeneratorUtils.kt +++ b/src/main/kotlin/com/cjbooms/fabrikt/generators/client/ClientGeneratorUtils.kt @@ -9,7 +9,7 @@ import com.cjbooms.fabrikt.generators.GeneratorUtils.hasMultipleSuccessResponseS import com.cjbooms.fabrikt.generators.GeneratorUtils.toClassName import com.cjbooms.fabrikt.generators.GeneratorUtils.toIncomingParameters import com.cjbooms.fabrikt.generators.OasDefault -import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator.Companion.toModelType +import com.cjbooms.fabrikt.generators.model.ModelGenerator.Companion.toModelType import com.cjbooms.fabrikt.model.ClientType import com.cjbooms.fabrikt.model.HeaderParam import com.cjbooms.fabrikt.model.IncomingParameter diff --git a/src/main/kotlin/com/cjbooms/fabrikt/generators/controller/ControllerGeneratorUtils.kt b/src/main/kotlin/com/cjbooms/fabrikt/generators/controller/ControllerGeneratorUtils.kt index f85af821..452de7cb 100644 --- a/src/main/kotlin/com/cjbooms/fabrikt/generators/controller/ControllerGeneratorUtils.kt +++ b/src/main/kotlin/com/cjbooms/fabrikt/generators/controller/ControllerGeneratorUtils.kt @@ -1,6 +1,6 @@ package com.cjbooms.fabrikt.generators.controller -import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator.Companion.toModelType +import com.cjbooms.fabrikt.generators.model.ModelGenerator.Companion.toModelType import com.cjbooms.fabrikt.model.ControllerType import com.cjbooms.fabrikt.model.KotlinTypeInfo import com.cjbooms.fabrikt.util.NormalisedString.camelCase diff --git a/src/main/kotlin/com/cjbooms/fabrikt/generators/model/JacksonModelGenerator.kt b/src/main/kotlin/com/cjbooms/fabrikt/generators/model/ModelGenerator.kt similarity index 99% rename from src/main/kotlin/com/cjbooms/fabrikt/generators/model/JacksonModelGenerator.kt rename to src/main/kotlin/com/cjbooms/fabrikt/generators/model/ModelGenerator.kt index 077b7f4a..ad019794 100644 --- a/src/main/kotlin/com/cjbooms/fabrikt/generators/model/JacksonModelGenerator.kt +++ b/src/main/kotlin/com/cjbooms/fabrikt/generators/model/ModelGenerator.kt @@ -68,7 +68,7 @@ import java.io.Serializable import java.net.MalformedURLException import java.net.URL -class JacksonModelGenerator( // TODO: Rename to ModelGenerator +class ModelGenerator( private val packages: Packages, private val sourceApi: SourceApi, ) { diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/KotlinSerializationModelGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/KotlinSerializationModelGeneratorTest.kt index 208cfbfa..48f2a357 100644 --- a/src/test/kotlin/com/cjbooms/fabrikt/generators/KotlinSerializationModelGeneratorTest.kt +++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/KotlinSerializationModelGeneratorTest.kt @@ -4,7 +4,7 @@ import com.cjbooms.fabrikt.cli.CodeGenerationType import com.cjbooms.fabrikt.cli.ModelCodeGenOptionType import com.cjbooms.fabrikt.cli.SerializationLibrary import com.cjbooms.fabrikt.configurations.Packages -import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator +import com.cjbooms.fabrikt.generators.model.ModelGenerator import com.cjbooms.fabrikt.model.KotlinSourceSet import com.cjbooms.fabrikt.model.SourceApi import com.cjbooms.fabrikt.util.ModelNameRegistry @@ -54,7 +54,7 @@ class KotlinSerializationModelGeneratorTest { val sourceApi = SourceApi(apiLocation.readText(), baseDir = Paths.get(apiLocation.toURI())) val expectedModels = readFolder(Path.of("src/test/resources/examples/$testCaseName/models/kotlinx/")) - val models = JacksonModelGenerator( + val models = ModelGenerator( Packages(basePackage), sourceApi, ).generate() @@ -85,7 +85,7 @@ class KotlinSerializationModelGeneratorTest { val sourceApi = SourceApi(apiLocation.readText(), baseDir = Paths.get(apiLocation.toURI())) val e = assertThrows { - JacksonModelGenerator(Packages(basePackage), sourceApi,).generate() + ModelGenerator(Packages(basePackage), sourceApi,).generate() } assertThat(e.message).isEqualTo("Additional properties not supported by selected serialization library") } @@ -97,7 +97,7 @@ class KotlinSerializationModelGeneratorTest { val sourceApi = SourceApi(apiLocation.readText(), baseDir = Paths.get(apiLocation.toURI())) val e = assertThrows { - val models = JacksonModelGenerator(Packages(basePackage), sourceApi,).generate() + val models = ModelGenerator(Packages(basePackage), sourceApi,).generate() val sourceSet = setOf(KotlinSourceSet(models.files, Paths.get(""))) println(sourceSet) } diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt index dc9b5fd5..fb95339e 100644 --- a/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt +++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt @@ -6,7 +6,7 @@ import com.cjbooms.fabrikt.cli.CodeGenerationType import com.cjbooms.fabrikt.cli.ModelCodeGenOptionType import com.cjbooms.fabrikt.cli.ValidationLibrary import com.cjbooms.fabrikt.configurations.Packages -import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator +import com.cjbooms.fabrikt.generators.model.ModelGenerator import com.cjbooms.fabrikt.model.KotlinSourceSet import com.cjbooms.fabrikt.model.Models import com.cjbooms.fabrikt.model.SourceApi @@ -102,7 +102,7 @@ class ModelGeneratorTest { val sourceApi = SourceApi(apiLocation.readText(), baseDir = Paths.get(apiLocation.toURI())) val expectedModels = readFolder(Path.of("src/test/resources/examples/$testCaseName/models/")) - val models = JacksonModelGenerator( + val models = ModelGenerator( Packages(basePackage), sourceApi, ).generate() @@ -137,7 +137,7 @@ class ModelGeneratorTest { val sourceApi = SourceApi(apiLocation.readText(), baseDir = Paths.get(apiLocation.toURI())) val expectedModels = readFolder(Path.of("src/test/resources/examples/modelSuffix/models/")) - val models = JacksonModelGenerator( + val models = ModelGenerator( Packages(basePackage), sourceApi, ).generate() @@ -158,7 +158,7 @@ class ModelGeneratorTest { genTypes = setOf(CodeGenerationType.HTTP_MODELS), validationLibrary = ValidationLibrary.JAKARTA_VALIDATION ) - val models = JacksonModelGenerator( + val models = ModelGenerator( Packages(basePackage), SourceApi(spec), ).generate() @@ -179,7 +179,7 @@ class ModelGeneratorTest { genTypes = setOf(CodeGenerationType.HTTP_MODELS), validationLibrary = ValidationLibrary.NO_VALIDATION ) - val models = JacksonModelGenerator( + val models = ModelGenerator( Packages(basePackage), SourceApi(spec), ).generate() @@ -198,7 +198,7 @@ class ModelGeneratorTest { MutableSettings.updateSettings( modelOptions = setOf(ModelCodeGenOptionType.JAVA_SERIALIZATION), ) - val models = JacksonModelGenerator( + val models = ModelGenerator( Packages(basePackage), SourceApi(spec), ) @@ -241,7 +241,7 @@ class ModelGeneratorTest { private fun assertExceptionWithMessage(path: String, expectedMessage: String) { val spec = readTextResource(path) val exception = assertThrows { - JacksonModelGenerator(Packages("blah"), SourceApi(spec)) + ModelGenerator(Packages("blah"), SourceApi(spec)) .generate() .toSingleFile() } @@ -257,7 +257,7 @@ class ModelGeneratorTest { modelOptions = setOf(ModelCodeGenOptionType.QUARKUS_REFLECTION), ) - val models = JacksonModelGenerator( + val models = ModelGenerator( Packages(basePackage), SourceApi(spec), ) @@ -276,7 +276,7 @@ class ModelGeneratorTest { modelOptions = setOf(ModelCodeGenOptionType.MICRONAUT_INTROSPECTION), ) - val models = JacksonModelGenerator( + val models = ModelGenerator( Packages(basePackage), SourceApi(spec), ) @@ -295,7 +295,7 @@ class ModelGeneratorTest { modelOptions = setOf(ModelCodeGenOptionType.MICRONAUT_REFLECTION), ) - val models = JacksonModelGenerator( + val models = ModelGenerator( Packages(basePackage), SourceApi(spec), ) @@ -314,7 +314,7 @@ class ModelGeneratorTest { modelOptions = setOf(ModelCodeGenOptionType.INCLUDE_COMPANION_OBJECT), ) - val models = JacksonModelGenerator( + val models = ModelGenerator( Packages(basePackage), SourceApi(spec), ) diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/OkHttpClientGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/OkHttpClientGeneratorTest.kt index 56a5ccd5..db8a3552 100644 --- a/src/test/kotlin/com/cjbooms/fabrikt/generators/OkHttpClientGeneratorTest.kt +++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/OkHttpClientGeneratorTest.kt @@ -10,7 +10,7 @@ import com.cjbooms.fabrikt.configurations.Packages import com.cjbooms.fabrikt.generators.client.OkHttpEnhancedClientGenerator import com.cjbooms.fabrikt.generators.client.OkHttpSimpleClientGenerator import com.cjbooms.fabrikt.generators.model.JacksonMetadata -import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator +import com.cjbooms.fabrikt.generators.model.ModelGenerator import com.cjbooms.fabrikt.model.ClientType import com.cjbooms.fabrikt.model.Models import com.cjbooms.fabrikt.model.SimpleFile @@ -62,7 +62,7 @@ class OkHttpClientGeneratorTest { val expectedModel = readTextResource("/examples/$testCaseName/models/ClientModels.kt") val expectedClient = readTextResource("/examples/$testCaseName/client/ApiClient.kt") - val models = JacksonModelGenerator( + val models = ModelGenerator( packages, sourceApi ).generate().toSingleFile() @@ -145,7 +145,7 @@ class OkHttpClientGeneratorTest { externalRefResolutionMode = ExternalReferencesResolutionMode.AGGRESSIVE, ) - val models = JacksonModelGenerator( + val models = ModelGenerator( packages, sourceApi, ).generate().toSingleFile() diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/OpenFeignClientGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/OpenFeignClientGeneratorTest.kt index 9fc63021..eeb9a276 100644 --- a/src/test/kotlin/com/cjbooms/fabrikt/generators/OpenFeignClientGeneratorTest.kt +++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/OpenFeignClientGeneratorTest.kt @@ -6,7 +6,7 @@ import com.cjbooms.fabrikt.cli.CodeGenerationType import com.cjbooms.fabrikt.cli.ModelCodeGenOptionType import com.cjbooms.fabrikt.configurations.Packages import com.cjbooms.fabrikt.generators.client.OpenFeignInterfaceGenerator -import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator +import com.cjbooms.fabrikt.generators.model.ModelGenerator import com.cjbooms.fabrikt.model.ClientType import com.cjbooms.fabrikt.model.Models import com.cjbooms.fabrikt.model.SourceApi @@ -78,7 +78,7 @@ class OpenFeignClientGeneratorTest { val expectedModel = readTextResource("/examples/$testCaseName/models/ClientModels.kt") val expectedClient = readTextResource("/examples/$testCaseName/client/$clientFileName") - val models = JacksonModelGenerator( + val models = ModelGenerator( packages, sourceApi, ).generate().toSingleFile() diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/ResourceGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/ResourceGeneratorTest.kt index 9d744233..c7d87537 100644 --- a/src/test/kotlin/com/cjbooms/fabrikt/generators/ResourceGeneratorTest.kt +++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/ResourceGeneratorTest.kt @@ -2,7 +2,7 @@ package com.cjbooms.fabrikt.generators import com.cjbooms.fabrikt.cli.CodeGenerationType import com.cjbooms.fabrikt.configurations.Packages -import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator +import com.cjbooms.fabrikt.generators.model.ModelGenerator import com.cjbooms.fabrikt.generators.model.QuarkusReflectionModelGenerator import com.cjbooms.fabrikt.model.ResourceFile import com.cjbooms.fabrikt.model.SourceApi @@ -43,7 +43,7 @@ class ResourceGeneratorTest { genTypes = setOf(CodeGenerationType.QUARKUS_REFLECTION_CONFIG), ) - val models = JacksonModelGenerator(Packages(basePackage), sourceApi).generate() + val models = ModelGenerator(Packages(basePackage), sourceApi).generate() val resources = QuarkusReflectionModelGenerator(models).generate()?.toSingleFile()