Skip to content

Commit 619b9b5

Browse files
sapklunny
authored andcommitted
Move swagger-ui under /api/v1 (#2746)
* Move swagger interface under /api/v1 * Update swagger-ui * Add /api/swagger and prepare for multiple api version * Update test links * Fix footer link
1 parent bc8d726 commit 619b9b5

17 files changed

+166
-192
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ generate-stylesheets:
304304
.PHONY: swagger-ui
305305
swagger-ui:
306306
rm -Rf public/vendor/assets/swagger-ui
307-
git clone --depth=10 -b v3.0.7 --single-branch https://github.com/swagger-api/swagger-ui.git $(TMPDIR)/swagger-ui
307+
git clone --depth=10 -b v3.3.2 --single-branch https://github.com/swagger-api/swagger-ui.git $(TMPDIR)/swagger-ui
308308
mv $(TMPDIR)/swagger-ui/dist public/vendor/assets/swagger-ui
309309
rm -Rf $(TMPDIR)/swagger-ui
310-
$(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../swagger.v1.json;g" public/assets/swagger-ui/index.html
310+
$(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../../swagger.v1.json;g" public/vendor/assets/swagger-ui/index.html
311311

312312
.PHONY: update-translations
313313
update-translations:

integrations/links_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ func TestLinksNoLogin(t *testing.T) {
2626
"/user/sign_up",
2727
"/user/login",
2828
"/user/forgot_password",
29-
"/swagger",
29+
"/api/swagger",
30+
"/api/v1/swagger",
3031
// TODO: follow this page and test every link
3132
"/vendor/librejs.html",
3233
}
@@ -47,7 +48,8 @@ func testLinksAsUser(userName string, t *testing.T) {
4748
"/explore/organizations?q=test&tab=",
4849
"/",
4950
"/user/forgot_password",
50-
"/swagger",
51+
"/api/swagger",
52+
"/api/v1/swagger",
5153
"/issues",
5254
"/issues?type=your_repositories&repo=0&sort=&state=open",
5355
"/issues?type=assigned&repo=0&sort=&state=open",

public/vendor/assets/swagger-ui/index.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
<style>
1212
html
1313
{
14-
box-sizing: border-box;
15-
overflow: -moz-scrollbars-vertical;
16-
overflow-y: scroll;
14+
box-sizing: border-box;
15+
overflow: -moz-scrollbars-vertical;
16+
overflow-y: scroll;
1717
}
1818
*,
1919
*:before,
2020
*:after
2121
{
22-
box-sizing: inherit;
22+
box-sizing: inherit;
2323
}
2424

2525
body {
@@ -71,10 +71,12 @@
7171
<script src="./swagger-ui-standalone-preset.js"> </script>
7272
<script>
7373
window.onload = function() {
74+
7475
// Build a system
7576
const ui = SwaggerUIBundle({
76-
url: "../../swagger.v1.json",
77+
url: "../../../swagger.v1.json",
7778
dom_id: '#swagger-ui',
79+
deepLinking: true,
7880
presets: [
7981
SwaggerUIBundle.presets.apis,
8082
SwaggerUIStandalonePreset

public/vendor/assets/swagger-ui/oauth2-redirect.html

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88
function run () {
99
var oauth2 = window.opener.swaggerUIRedirectOauth2;
1010
var sentState = oauth2.state;
11-
var isValid, qp;
11+
var redirectUrl = oauth2.redirectUrl;
12+
var isValid, qp, arr;
1213

13-
qp = (window.location.hash || location.search).substring(1);
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+
}
1419

15-
qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
20+
arr = qp.split("&")
21+
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
22+
qp = qp ? JSON.parse('{' + arr.join() + '}',
1623
function (key, value) {
1724
return key === "" ? value : decodeURIComponent(value)
1825
}
@@ -33,51 +40,18 @@
3340
if (qp.code) {
3441
delete oauth2.state;
3542
oauth2.auth.code = qp.code;
36-
createForm(oauth2.auth, qp).submit();
43+
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
3744
} else {
3845
oauth2.errCb({
3946
authId: oauth2.auth.name,
4047
source: "auth",
4148
level: "error",
42-
message: "Authorization failed: no accessCode came from the server"
49+
message: "Authorization failed: no accessCode received from the server"
4350
});
44-
window.close();
4551
}
4652
} else {
47-
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid});
48-
window.close();
53+
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
4954
}
55+
window.close();
5056
}
51-
52-
function createForm(auth, qp) {
53-
var form = document.createElement("form");
54-
var schema = auth.schema;
55-
var action = schema.get("tokenUrl");
56-
var name, input;
57-
58-
var fields = {
59-
code: qp.code,
60-
"redirect_uri": location.protocol + "//" + location.host + location.pathname,
61-
"grant_type": "authorization_code",
62-
"client_secret": auth.clientSecret,
63-
"client_id": auth.clientId
64-
}
65-
66-
for ( name in fields ) {
67-
input = document.createElement("input");
68-
input.name = name;
69-
input.value = fields[name];
70-
input.type = "hidden";
71-
form.appendChild(input);
72-
}
73-
74-
75-
form.method = "POST";
76-
form.action = action;
77-
78-
document.body.appendChild(form);
79-
80-
return form;
81-
}
82-
8357
</script>

public/vendor/assets/swagger-ui/swagger-ui-bundle.js

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

public/vendor/assets/swagger-ui/swagger-ui-bundle.js.map

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

public/vendor/assets/swagger-ui/swagger-ui-standalone-preset.js

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

public/vendor/assets/swagger-ui/swagger-ui-standalone-preset.js.map

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

public/vendor/assets/swagger-ui/swagger-ui.css

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

public/vendor/assets/swagger-ui/swagger-ui.js

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

0 commit comments

Comments
 (0)