Skip to content

Commit 75ba6cb

Browse files
author
Emanuel Moecklin
committed
some test code cleanup / get rid of some warnings
1 parent fb268b9 commit 75ba6cb

File tree

12 files changed

+52
-68
lines changed

12 files changed

+52
-68
lines changed

build.gradle

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,12 @@ dependencies {
3939
testImplementation "ch.qos.logback:logback-classic:$logback_version"
4040
testImplementation "io.ktor:ktor-auth:$ktor_version"
4141
testImplementation "io.ktor:ktor-auth-jwt:$ktor_version"
42-
43-
4442
}
4543

4644
compileKotlin {
47-
kotlinOptions.jvmTarget = "1.6"
45+
kotlinOptions.jvmTarget = "1.8"
4846
kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlin.ExperimentalStdlibApi"]
4947
}
5048
compileTestKotlin {
51-
kotlinOptions.jvmTarget = "1.6"
52-
}
53-
54-
wrapper {
55-
gradleVersion = '6.0.1'
49+
kotlinOptions.jvmTarget = "1.8"
5650
}

src/main/kotlin/com/papsign/ktor/openapigen/annotations/type/common/ConstraintViolation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package com.papsign.ktor.openapigen.annotations.type.common
33
import java.lang.Exception
44

55
abstract class ConstraintViolation(defaultMessage: String, message: String = "", cause: Throwable? = null)
6-
: Exception(if (message.isEmpty()) defaultMessage else message, cause)
6+
: Exception(message.ifEmpty { defaultMessage }, cause)

src/main/kotlin/com/papsign/ktor/openapigen/annotations/type/string/length/LengthConstraintProcessor.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import com.papsign.ktor.openapigen.validation.ValidatorBuilder
1111
import kotlin.reflect.KType
1212
import kotlin.reflect.full.withNullability
1313

14-
abstract class LengthConstraintProcessor<A: Annotation>(): SchemaProcessor<A>, ValidatorBuilder<A> {
14+
abstract class LengthConstraintProcessor<A: Annotation>: SchemaProcessor<A>, ValidatorBuilder<A> {
1515

1616
private val log = classLogger()
1717

@@ -59,14 +59,14 @@ abstract class LengthConstraintProcessor<A: Annotation>(): SchemaProcessor<A>, V
5959
data class LengthConstraint(val min: Int? = null, val max: Int? = null, val errorMessage: String)
6060

6161
class LengthConstraintViolation(val actual: Number?, val constraint: LengthConstraint): ConstraintViolation("Constraint violation: the length of the string should be ${
62-
{
63-
val min = "${constraint.min}"
64-
val max = "${constraint.max}"
65-
when {
66-
constraint.min != null && constraint.max != null -> "between $min and $max"
67-
constraint.min != null -> "at least $min"
68-
constraint.max != null -> "at most $max"
69-
else -> "anything"
62+
run {
63+
val min = "${constraint.min}"
64+
val max = "${constraint.max}"
65+
when {
66+
constraint.min != null && constraint.max != null -> "between $min and $max"
67+
constraint.min != null -> "at least $min"
68+
constraint.max != null -> "at most $max"
69+
else -> "anything"
70+
}
7071
}
71-
}()
7272
}, but it is $actual", constraint.errorMessage)

src/main/kotlin/com/papsign/ktor/openapigen/content/type/multipart/MultipartFormDataContentProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import io.ktor.http.content.PartData
1717
import io.ktor.http.content.forEachPart
1818
import io.ktor.http.content.streamProvider
1919
import io.ktor.request.receiveMultipart
20-
import io.ktor.util.asStream
20+
import io.ktor.util.*
2121
import io.ktor.util.pipeline.PipelineContext
2222
import java.io.InputStream
2323
import java.time.Instant
@@ -68,6 +68,7 @@ object MultipartFormDataContentProvider : BodyParser, OpenAPIGenModuleExtension
6868
private val typeContentTypes = HashMap<KType, Map<String, MediaTypeEncodingModel>>()
6969

7070

71+
@OptIn(KtorExperimentalAPI::class)
7172
override suspend fun <T : Any> parseBody(type: KType, request: PipelineContext<Unit, ApplicationCall>): T {
7273
val objectMap = HashMap<String, Any>()
7374
request.context.receiveMultipart().forEachPart {

src/main/kotlin/com/papsign/ktor/openapigen/validation/ValidationHandler.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import kotlin.reflect.*
66
import kotlin.reflect.full.*
77
import kotlin.reflect.jvm.*
88

9-
109
/**
1110
* don't mind the evil leak, it's that or a two-step builder structure to be able to handle recursive types
1211
*/
@@ -315,11 +314,7 @@ class ValidationHandler private constructor(
315314
*/
316315
fun build(type: AnnotatedKType): ValidationHandler {
317316
val str = type.toString()
318-
return map[str] ?: {
319-
ValidationHandler(type) {
320-
map[str] = it
321-
}
322-
}()
317+
return map[str] ?: ValidationHandler(type) { map[str] = it }
323318
}
324319

325320
fun <T:Any> build(tClass: KClass<T>, annotations: List<Annotation> = listOf()): ValidationHandler {

src/main/kotlin/com/papsign/ktor/openapigen/validation/ValidatorAnnotation.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.papsign.ktor.openapigen.validation
22

3-
import com.papsign.ktor.openapigen.validation.ValidatorBuilder
43
import kotlin.reflect.KClass
54

65
@Target(AnnotationTarget.ANNOTATION_CLASS)

src/test/kotlin/Basic.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ object Basic {
9393
info("String Post Endpoint", "This is a String Post Endpoint"),
9494
exampleRequest = setOf(StringUsable("Ho")),
9595
exampleResponse = StringUsable("Ho")
96-
) { params, body ->
96+
) { _, body ->
9797
respond(body.first())
9898
}
9999
}
100100

101101
route("generic") {
102-
post<Unit, GenericTest<A?>, GenericTest<A?>> { params, body ->
102+
post<Unit, GenericTest<A?>, GenericTest<A?>> { _, body ->
103103
respond(body)
104104
}
105105
}

src/test/kotlin/Minimal.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object Minimal {
9292
info("String Post Endpoint", "This is a String Post Endpoint"),
9393
exampleRequest = StringUsable("Ho"),
9494
exampleResponse = StringUsable("Ho")
95-
) { params, body ->
95+
) { _, body ->
9696
respond(body)
9797
}
9898
}

src/test/kotlin/OneOf.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fun NormalOpenAPIRoute.SealedRoute() {
2424
info("Sealed class Endpoint", "This is a Sealed class Endpoint"),
2525
exampleRequest = Base.A("Hi"),
2626
exampleResponse = Base.A("Hi")
27-
) { params, base ->
27+
) { _, base ->
2828
respond(base)
2929
}
3030
}

src/test/kotlin/TestServer.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ object TestServer {
106106
"5a21be2"
107107
),
108108
exampleResponse = StringResponse("All of the fields were valid")
109-
) { params, body ->
109+
) { _, _ ->
110110
respond(StringResponse("All of the fields were valid"))
111111
}
112112

@@ -122,7 +122,7 @@ object TestServer {
122122
0.023f
123123
),
124124
exampleResponse = StringResponse("All of the fields were valid")
125-
) { params, body ->
125+
) { _, _ ->
126126
respond(StringResponse("All of the fields were valid"))
127127
}
128128

@@ -314,8 +314,6 @@ object TestServer {
314314
}
315315
}
316316

317-
val scopes = Scopes.values().asList()
318-
319317
// serve OpenAPI and redirect from root
320318
routing {
321319
get("/openapi.json") {
@@ -392,9 +390,6 @@ object TestServer {
392390
profile("Basic Profile scope"), email("Email scope")
393391
}
394392

395-
data class APIPrincipal(val a: String, val b: String)
396-
397-
398393
@Request("A LocalDate Request")
399394
data class LocalDateQuery(@QueryParam("LocalDate") val date: LocalDate)
400395
data class LocalDateOptionalQuery(@QueryParam("LocalDate") val date: LocalDate?)

0 commit comments

Comments
 (0)