1
1
package io.kotest.extensions.ktor.openapi
2
2
3
3
import io.kotest.core.spec.style.FunSpec
4
+ import io.kotest.matchers.shouldBe
4
5
import io.ktor.client.request.delete
5
6
import io.ktor.client.request.get
6
7
import io.ktor.client.request.patch
7
8
import io.ktor.client.request.post
9
+ import io.ktor.client.statement.bodyAsText
8
10
import io.ktor.http.HttpStatusCode
11
+ import io.ktor.serialization.jackson.jackson
9
12
import io.ktor.server.application.call
10
13
import io.ktor.server.auth.Authentication
11
14
import io.ktor.server.auth.authenticate
12
15
import io.ktor.server.auth.basic
16
+ import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
13
17
import io.ktor.server.response.respond
14
18
import io.ktor.server.routing.delete
15
19
import io.ktor.server.routing.get
@@ -29,6 +33,9 @@ class OpenApiTest : FunSpec() {
29
33
test(" should generate routes for all method types" ) {
30
34
testApplication {
31
35
install(KotestOpenApi )
36
+ install(ContentNegotiation ) {
37
+ jackson()
38
+ }
32
39
install(Authentication ) {
33
40
basic(" auth2" ) {
34
41
this .realm = " myrealm"
@@ -41,7 +48,7 @@ class OpenApiTest : FunSpec() {
41
48
route(" /internal" ) {
42
49
get(" /foo1" ) {
43
50
description(" Returns the user identified by the foo param" )
44
- call.respond(HttpStatusCode . OK , User (" sammy" , " chicago" ))
51
+ call.respond(User (" sammy" , " chicago" ))
45
52
}
46
53
patch(" /patchme" ) {
47
54
deprecated(true )
@@ -56,7 +63,7 @@ class OpenApiTest : FunSpec() {
56
63
}
57
64
post(" /bar2" ) { call.respond(HttpStatusCode .OK , " some response body" ) }
58
65
}
59
- client.get(" /internal/foo1" )
66
+ client.get(" /internal/foo1" ).bodyAsText() shouldBe """ {"name":"sammy","location":"chicago"} """
60
67
client.patch(" /internal/patchme" )
61
68
client.post(" /bar2" ).status
62
69
client.get(" /users/154363" )
0 commit comments