Skip to content

Commit a5c871f

Browse files
committed
Added support for Swagger-UI and fixes to Swagger JSON (openapi.yaml)
1 parent 29703a9 commit a5c871f

18 files changed

Lines changed: 396 additions & 134 deletions

.idea/modules.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/scala_compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ libraryDependencies += guice
1111
libraryDependencies += "com.google.code.gson" % "gson" % "2.8.5"
1212
libraryDependencies += "com.datastax.cassandra" % "cassandra-driver-core" % "3.3.0"
1313
libraryDependencies += "com.datastax.cassandra" % "cassandra-driver-extras" % "3.3.0"
14+
libraryDependencies += "io.swagger" % "swagger-play2_2.12" % "1.6.0"
1415

conf/application.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ db {
1010
}
1111

1212
play.http.secret.key="whatever"
13+
play.modules.enabled += "play.modules.swagger.SwaggerModule"
14+
play.filters.headers.contentSecurityPolicy = null
15+
16+

conf/routes

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ POST /model controllers.ModelController.create()
1414
GET /element controllers.ElementController.all()
1515
GET /element/:id controllers.ElementController.byId(id)
1616
GET /element/model/:mid controllers.ElementController.byModel(mid)
17-
GET /element/:id/model/:mid controllers.ElementController.byIdAndModel(id,mid)
17+
#GET /element/:id/model/:mid controllers.ElementController.byIdAndModel(id,mid)
1818
POST /element controllers.ElementController.create()
1919

2020
# Relationship endpoints
@@ -30,3 +30,6 @@ POST /relationship controllers.RelationshipController.creat
3030

3131
# Map static resources from the /public folder to the /assets URL path
3232
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
33+
34+
GET /docs/ controllers.Assets.at(path="/public/swagger",file="index.html")
35+
GET /docs/*file controllers.Assets.at(path="/public/swagger",file)

public/swagger/favicon-16x16.png

738 Bytes
Loading

public/swagger/favicon-32x32.png

1.6 KB
Loading

public/swagger/index.html

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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="./swagger-ui.css" >
8+
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
9+
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
10+
<style>
11+
html
12+
{
13+
box-sizing: border-box;
14+
overflow: -moz-scrollbars-vertical;
15+
overflow-y: scroll;
16+
}
17+
18+
*,
19+
*:before,
20+
*:after
21+
{
22+
box-sizing: inherit;
23+
}
24+
25+
body
26+
{
27+
margin:0;
28+
background: #fafafa;
29+
}
30+
</style>
31+
</head>
32+
33+
<body>
34+
<div id="swagger-ui"></div>
35+
36+
<script src="./swagger-ui-bundle.js"> </script>
37+
<script src="./swagger-ui-standalone-preset.js"> </script>
38+
<script>
39+
window.onload = function() {
40+
// Begin Swagger UI call region
41+
const ui = SwaggerUIBundle({
42+
url: "/assets/swagger/openapi.yaml",
43+
dom_id: '#swagger-ui',
44+
deepLinking: true,
45+
presets: [
46+
SwaggerUIBundle.presets.apis,
47+
SwaggerUIStandalonePreset
48+
],
49+
plugins: [
50+
SwaggerUIBundle.plugins.DownloadUrl
51+
],
52+
layout: "StandaloneLayout"
53+
})
54+
// End Swagger UI call region
55+
56+
window.ui = ui
57+
}
58+
</script>
59+
</body>
60+
</html>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<body onload="run()">
4+
</body>
5+
</html>
6+
<script>
7+
'use strict';
8+
function run () {
9+
var oauth2 = window.opener.swaggerUIRedirectOauth2;
10+
var sentState = oauth2.state;
11+
var redirectUrl = oauth2.redirectUrl;
12+
var isValid, qp, arr;
13+
14+
if (/code|token|error/.test(window.location.hash)) {
15+
qp = window.location.hash.substring(1);
16+
} else {
17+
qp = location.search.substring(1);
18+
}
19+
20+
arr = qp.split("&")
21+
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
22+
qp = qp ? JSON.parse('{' + arr.join() + '}',
23+
function (key, value) {
24+
return key === "" ? value : decodeURIComponent(value)
25+
}
26+
) : {}
27+
28+
isValid = qp.state === sentState
29+
30+
if ((
31+
oauth2.auth.schema.get("flow") === "accessCode"||
32+
oauth2.auth.schema.get("flow") === "authorizationCode"
33+
) && !oauth2.auth.code) {
34+
if (!isValid) {
35+
oauth2.errCb({
36+
authId: oauth2.auth.name,
37+
source: "auth",
38+
level: "warning",
39+
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
40+
});
41+
}
42+
43+
if (qp.code) {
44+
delete oauth2.state;
45+
oauth2.auth.code = qp.code;
46+
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
47+
} else {
48+
let oauthErrorMsg
49+
if (qp.error) {
50+
oauthErrorMsg = "["+qp.error+"]: " +
51+
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
52+
(qp.error_uri ? "More info: "+qp.error_uri : "");
53+
}
54+
55+
oauth2.errCb({
56+
authId: oauth2.auth.name,
57+
source: "auth",
58+
level: "error",
59+
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
60+
});
61+
}
62+
} else {
63+
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
64+
}
65+
window.close();
66+
}
67+
</script>

0 commit comments

Comments
 (0)