Skip to content

Commit

Permalink
Add deepLinking configuration variable to Swagger plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikMeyer committed Dec 17, 2024
1 parent dbcbff9 commit 7f0f904
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ window.onload = function() {
window.ui = SwaggerUIBundle({
url: '$fullPath/$apiUrl',
dom_id: '#swagger-ui',
deepLinking: ${config.deepLinking},
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public class SwaggerConfig {
* Swagger package location
*/
public var packageLocation: String = "https://unpkg.com/swagger-ui-dist"

/**
* Whether to allow deep linking in Swagger UI, as described here: https://swagger.io/docs/open-source-tools/swagger-ui/usage/deep-linking/
*
* Defaults to `false`.
*/
public var deepLinking: Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,48 @@ class SwaggerTest {
window.ui = SwaggerUIBundle({
url: '/swagger/documentation.yaml',
dom_id: '#swagger-ui',
deepLinking: false,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
layout: 'StandaloneLayout'
});
}</script>
</body>
</html>
""".trimIndent(),
response
)
}

@Test
fun testSwaggerAllowDeepLinking() = testApplication {
routing {
swaggerUI("swagger") {
deepLinking = true
}
}

val response = client.get("/swagger").bodyAsText()
assertEquals(
"""
<!DOCTYPE html>
<html>
<head>
<title>Swagger UI</title>
<link href="https://unpkg.com/[email protected]/swagger-ui.css" rel="stylesheet">
</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',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
Expand Down Expand Up @@ -74,6 +116,7 @@ class SwaggerTest {
window.ui = SwaggerUIBundle({
url: '/swagger/documentation.yaml',
dom_id: '#swagger-ui',
deepLinking: false,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
Expand Down

0 comments on commit 7f0f904

Please sign in to comment.