-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KTOR-7893 Add favicon to Swagger UI (#4528)
- Loading branch information
1 parent
ec1071d
commit f6e4926
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
ktor-server/ktor-server-plugins/ktor-server-swagger/api/ktor-server-swagger.api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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> | ||
|
@@ -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> | ||
|
@@ -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 | ||
) | ||
} | ||
} |