Skip to content

(chore): Added Spotless support for Kotlin files #714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root = true

[*.{kt,kts}]
ktlint_standard_package-name = disabled
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ allprojects {
trimTrailingWhitespace()
endWithNewline()
}

kotlin {
ktfmt()
ktlint("1.1.1")

licenseHeader("// SPDX-License-Identifier: Apache-2.0", "package|import|public")

}
}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.addons.kotlinx_serialization_model_converter.converter

import io.swagger.v3.core.converter.AnnotatedType
Expand All @@ -20,9 +21,10 @@ import kotlin.reflect.jvm.javaType
import kotlin.reflect.jvm.jvmErasure

class KotlinxSerializationModelConverter(private val useFqn: Boolean = false) : ModelConverter {

override fun resolve(
annotatedType: AnnotatedType, context: ModelConverterContext, chain: Iterator<ModelConverter>
annotatedType: AnnotatedType,
context: ModelConverterContext,
chain: Iterator<ModelConverter>,
): Schema<*>? {
if (annotatedType.type is Class<*>) {
val jClass = annotatedType.type as Class<*>
Expand Down Expand Up @@ -58,10 +60,13 @@ class KotlinxSerializationModelConverter(private val useFqn: Boolean = false) :
return property.name
}

private fun getPropertySchema(property: KProperty1<*, *>, context: ModelConverterContext): Schema<*> {
private fun getPropertySchema(
property: KProperty1<*, *>,
context: ModelConverterContext,
): Schema<*> {
val propertySchema: Schema<*>

val name = getPropertyName(property)
val name = getPropertyName(property)

val propertyType = property.returnType.jvmErasure

Expand Down Expand Up @@ -92,7 +97,10 @@ class KotlinxSerializationModelConverter(private val useFqn: Boolean = false) :
return propertySchema
}

private fun resolveRefSchema(type: Type, context: ModelConverterContext): Schema<*> {
private fun resolveRefSchema(
type: Type,
context: ModelConverterContext,
): Schema<*> {
val typeSchema = context.resolve(AnnotatedType(type))
if (typeSchema.type == "object") {
val typeClass = type as Class<*>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.addons.kotlinx_serialization_model_converter.converter

import kotlinx.serialization.KSerializer
Expand All @@ -22,7 +23,10 @@ object LocalDateSerializer : KSerializer<LocalDate> {
return LocalDate.parse(decoder.decodeString(), dateTimeFormatter)
}

override fun serialize(encoder: Encoder, value: LocalDate) {
override fun serialize(
encoder: Encoder,
value: LocalDate,
) {
encoder.encodeString(value.format(dateTimeFormatter))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.addons.kotlinx_serialization_model_converter.converter

import kotlinx.serialization.SerialName
Expand Down Expand Up @@ -51,7 +52,7 @@ data class SampleEvent(
enum class Color {
RED,
GREEN,
BLUE
BLUE,
}

@Serializable
Expand Down Expand Up @@ -89,4 +90,4 @@ data class ClassWithNestedProperty(
val name: String,
val color: Color,
)
}
}
1 change: 1 addition & 0 deletions springwolf-examples/springwolf-kafka-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ afterEvaluate {
dependsOn jar
dependsOn processTestResources
dependsOn spotlessJava
dependsOn spotlessKotlin
doNotTrackState("See https://github.com/springdoc/springdoc-openapi-gradle-plugin/issues/102")
}
}
Expand Down