Skip to content

Commit 91c0d7e

Browse files
committed
Create swagger-ui page
1 parent b041554 commit 91c0d7e

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

src/main/kotlin/io/realworld/app/config/AppConfig.kt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class AppConfig : KoinComponent {
3636
enableWebjars()
3737
enableCorsForAllOrigins()
3838
contextPath = getProperty("context")
39-
registerPlugin(getConfiguredOpenApiPlugin())
39+
addStaticFiles("/swagger")
40+
addSinglePageRoot("","/swagger/swagger-ui.html")
4041
server {
4142
Server(getProperty("server_port") as Int)
4243
}
@@ -61,22 +62,5 @@ class AppConfig : KoinComponent {
6162
.configure(SerializationFeature.WRITE_DATES_WITH_ZONE_ID, true)
6263
)
6364
}
64-
65-
fun getConfiguredOpenApiPlugin() = OpenApiPlugin(
66-
OpenApiOptions(
67-
Info().apply {
68-
title("Conduit")
69-
version("1.0")
70-
description(
71-
"|-\n" +
72-
" Collection for testing the Conduit API\n" +
73-
" https://github.com/Rudge/kotlin-javalin-realworld-example-app")
74-
}
75-
).apply {
76-
path("/swagger-docs") // endpoint for OpenAPI json
77-
swagger(SwaggerOptions("/swagger-ui")) // endpoint for swagger-ui
78-
roles(roles(Roles.ANYONE, Roles.AUTHENTICATED))
79-
}
80-
)
8165
}
8266

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!-- HTML for static distribution bundle build -->
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Swagger UI</title>
7+
<link rel="stylesheet" type="text/css" href="/api/webjars/swagger-ui/3.24.3/swagger-ui.css" >
8+
<link rel="icon" type="image/png" href="/api/webjars/swagger-ui/3.24.3/favicon-32x32.png" sizes="32x32" />
9+
<link rel="icon" type="image/png" href="/api/webjars/swagger-ui/3.24.3/favicon-16x16.png" sizes="16x16" />
10+
<style>
11+
html {
12+
box-sizing: border-box;
13+
overflow: -moz-scrollbars-vertical;
14+
overflow-y: scroll;
15+
}
16+
*, *:before, *:after {
17+
box-sizing: inherit;
18+
}
19+
body {
20+
margin:0;
21+
background: #fafafa;
22+
}
23+
</style>
24+
</head>
25+
<body>
26+
<div id="swagger-ui"></div>
27+
<script src="/api/webjars/swagger-ui/3.24.3/swagger-ui-bundle.js"> </script>
28+
<script src="/api/webjars/swagger-ui/3.24.3/swagger-ui-standalone-preset.js"> </script>
29+
<script>
30+
window.onload = function() {
31+
window.ui = SwaggerUIBundle({
32+
url: "/api/api.yaml",
33+
dom_id: "#swagger-ui",
34+
deepLinking: true,
35+
presets: [
36+
SwaggerUIBundle.presets.apis,
37+
SwaggerUIStandalonePreset
38+
],
39+
plugins: [
40+
SwaggerUIBundle.plugins.DownloadUrl
41+
],
42+
layout: "StandaloneLayout"
43+
})
44+
}
45+
</script>
46+
</body>
47+
</html>

0 commit comments

Comments
 (0)