diff --git a/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/Swagger.kt b/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/Swagger.kt index 5da6578617d..8b23331e726 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/Swagger.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/Swagger.kt @@ -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 diff --git a/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/SwaggerConfig.kt b/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/SwaggerConfig.kt index a69ced719d3..afcfe91f1dd 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/SwaggerConfig.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/src/io/ktor/server/plugins/swagger/SwaggerConfig.kt @@ -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 } diff --git a/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/test/io/ktor/server/plugins/swagger/SwaggerTest.kt b/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/test/io/ktor/server/plugins/swagger/SwaggerTest.kt index 473e20d9ff6..0512228ede5 100644 --- a/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/test/io/ktor/server/plugins/swagger/SwaggerTest.kt +++ b/ktor-server/ktor-server-plugins/ktor-server-swagger/jvm/test/io/ktor/server/plugins/swagger/SwaggerTest.kt @@ -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' + }); + } + + + + """.trimIndent(), + response + ) + } + + @Test + fun testSwaggerAllowDeepLinking() = testApplication { + routing { + swaggerUI("swagger") { + deepLinking = true + } + } + + val response = client.get("/swagger").bodyAsText() + assertEquals( + """ + + + + Swagger UI + + + +
+ + +