Skip to content

Commit

Permalink
KTOR-7876 Fix Sink.writeText corrupts long streams for Jetty server
Browse files Browse the repository at this point in the history
  • Loading branch information
marychatte committed Dec 3, 2024
1 parent bca1cc2 commit 717819e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public fun Route.swaggerUI(
config.customStyle?.let {
link(href = it, rel = "stylesheet")
}
link(
href = config.faviconLocation,
rel = "icon",
type = "image/x-icon"
)
}
body {
div { id = "swagger-ui" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public class SwaggerConfig {
* Swagger package location
*/
public var packageLocation: String = "https://unpkg.com/swagger-ui-dist"

/**
* Swagger favicon location
*/
public var faviconLocation: String = "https://unpkg.com/swagger-ui-dist@$version/favicon-32x32.png"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.server.testing.*
import kotlin.test.*
import kotlin.test.Test
import kotlin.test.assertEquals

class SwaggerTest {
@Test
Expand All @@ -25,6 +26,7 @@ class SwaggerTest {
<head>
<title>Swagger UI</title>
<link href="https://unpkg.com/[email protected]/swagger-ui.css" rel="stylesheet">
<link href="https://unpkg.com/[email protected]/favicon-32x32.png" rel="icon" type="image/x-icon">
</head>
<body>
<div id="swagger-ui"></div>
Expand Down Expand Up @@ -65,6 +67,7 @@ class SwaggerTest {
<head>
<title>Swagger UI</title>
<link href="https://unpkg.com/[email protected]/swagger-ui.css" rel="stylesheet">
<link href="https://unpkg.com/[email protected]/favicon-32x32.png" rel="icon" type="image/x-icon">
</head>
<body>
<div id="swagger-ui"></div>
Expand Down Expand Up @@ -101,4 +104,48 @@ class SwaggerTest {
assertEquals("text/yaml; charset=UTF-8", response.contentType().toString())
assertEquals("hello:\n world".filter { it.isLetterOrDigit() }, body.filter { it.isLetterOrDigit() })
}

@Test
fun testCustomFavicon() = testApplication {
routing {
swaggerUI("swagger") {
faviconLocation = "https://www.google.com/favicon.ico"
}
}

val response = client.get("/swagger") {
parameter("docExpansion", "list")
}.bodyAsText()
assertEquals(
"""
<!DOCTYPE html>
<html>
<head>
<title>Swagger UI</title>
<link href="https://unpkg.com/[email protected]/swagger-ui.css" rel="stylesheet">
<link href="https://www.google.com/favicon.ico" rel="icon" type="image/x-icon">
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/[email protected]/swagger-ui-bundle.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]/swagger-ui-standalone-preset.js" crossorigin="anonymous"></script>
<script>window.onload = function() {
window.ui = SwaggerUIBundle({
url: '/swagger/documentation.yaml',
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
layout: 'StandaloneLayout',
docExpansion: 'list'
});
}</script>
</body>
</html>
""".trimIndent(),
response
)
}
}

0 comments on commit 717819e

Please sign in to comment.