Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit 689d029

Browse files
committed
Fixed schema references
1 parent ee9b1d8 commit 689d029

File tree

2 files changed

+10
-3
lines changed
  • kotest-extensions-ktor-openapi-plugin/src

2 files changed

+10
-3
lines changed

kotest-extensions-ktor-openapi-plugin/src/main/kotlin/io/kotest/extensions/ktor/openapi/OpenApiBuilder.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class OpenApiBuilder(private val config: OpenApiConfig) {
8383
val mediaType = MediaType()
8484
tracesByContentType.firstNotNullOfOrNull { it.schema }?.let {
8585
mediaType.schema = Schema<Any>()
86-
mediaType.schema.`$ref` = it.java.name
86+
mediaType.schema.`$ref` = "#/components/schemas/" + it.java.name
8787
}
8888

8989
// for each content type that is the same, they are added as multiple examples

kotest-extensions-ktor-openapi-plugin/src/test/kotlin/io/kotest/extensions/ktor/openapi/OpenApiTest.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package io.kotest.extensions.ktor.openapi
22

33
import io.kotest.core.spec.style.FunSpec
4+
import io.kotest.matchers.shouldBe
45
import io.ktor.client.request.delete
56
import io.ktor.client.request.get
67
import io.ktor.client.request.patch
78
import io.ktor.client.request.post
9+
import io.ktor.client.statement.bodyAsText
810
import io.ktor.http.HttpStatusCode
11+
import io.ktor.serialization.jackson.jackson
912
import io.ktor.server.application.call
1013
import io.ktor.server.auth.Authentication
1114
import io.ktor.server.auth.authenticate
1215
import io.ktor.server.auth.basic
16+
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
1317
import io.ktor.server.response.respond
1418
import io.ktor.server.routing.delete
1519
import io.ktor.server.routing.get
@@ -29,6 +33,9 @@ class OpenApiTest : FunSpec() {
2933
test("should generate routes for all method types") {
3034
testApplication {
3135
install(KotestOpenApi)
36+
install(ContentNegotiation) {
37+
jackson()
38+
}
3239
install(Authentication) {
3340
basic("auth2") {
3441
this.realm = "myrealm"
@@ -41,7 +48,7 @@ class OpenApiTest : FunSpec() {
4148
route("/internal") {
4249
get("/foo1") {
4350
description("Returns the user identified by the foo param")
44-
call.respond(HttpStatusCode.OK, User("sammy", "chicago"))
51+
call.respond(User("sammy", "chicago"))
4552
}
4653
patch("/patchme") {
4754
deprecated(true)
@@ -56,7 +63,7 @@ class OpenApiTest : FunSpec() {
5663
}
5764
post("/bar2") { call.respond(HttpStatusCode.OK, "some response body") }
5865
}
59-
client.get("/internal/foo1")
66+
client.get("/internal/foo1").bodyAsText() shouldBe """{"name":"sammy","location":"chicago"}"""
6067
client.patch("/internal/patchme")
6168
client.post("/bar2").status
6269
client.get("/users/154363")

0 commit comments

Comments
 (0)