Skip to content

Commit 7b895fe

Browse files
committed
Fully working base
Generate swagger.json into public/ Add swagger-ui auto-installation Add footer link to local swagger-ui Add /swagger url for using app url. Fix Swagger-UI version via git tag Use a easier to understand sed syntax Vendor temporary PR for sdk
1 parent a1a7581 commit 7b895fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2313
-62
lines changed

Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ generate:
5252
@hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
5353
go get -u github.com/jteeuwen/go-bindata/...; \
5454
fi
55+
@hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
56+
go get -u github.com/go-swagger/go-swagger/cmd/swagger; \
57+
fi
5558
go generate $(PACKAGES)
5659

5760
.PHONY: errcheck
@@ -177,5 +180,13 @@ stylesheets: public/css/index.css
177180
public/css/index.css: $(STYLESHEETS)
178181
lessc $< $@
179182

183+
.PHONY: swagger-ui
184+
swagger-ui:
185+
rm -Rf public/assets/swagger-ui
186+
git clone --depth=10 -b v3.0.7 --single-branch https://github.com/swagger-api/swagger-ui.git /tmp/swagger-ui
187+
mv /tmp/swagger-ui/dist public/assets/swagger-ui
188+
rm -Rf /tmp/swagger-ui
189+
sed -i "s;http://petstore.swagger.io/v2/swagger.json;../../swagger.v1.json;g" public/assets/swagger-ui/index.html
190+
180191
.PHONY: assets
181192
assets: javascripts stylesheets

models/repo_list.go

+20-9
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,27 @@ func (repos MirrorRepositoryList) LoadAttributes() error {
8484
}
8585

8686
// SearchRepoOptions holds the search options
87+
// swagger:parameters repoSearch
8788
type SearchRepoOptions struct {
88-
Keyword string
89-
OwnerID int64
90-
Searcher *User //ID of the person who's seeking
91-
OrderBy string
92-
Private bool // Include private repositories in results
93-
Starred bool
94-
Page int
95-
IsProfile bool
96-
PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
89+
// Keyword to search
90+
//
91+
// in: query
92+
Keyword string `json:"q"`
93+
// Owner in we search search
94+
//
95+
// in: query
96+
OwnerID int64 `json:"uid"`
97+
Searcher *User `json:"-"` //ID of the person who's seeking
98+
OrderBy string `json:"-"`
99+
Private bool `json:"-"` // Include private repositories in results
100+
Starred bool `json:"-"`
101+
Page int `json:"-"`
102+
IsProfile bool `json:"-"`
103+
// Limit of result
104+
//
105+
// maximum: setting.ExplorePagingNum
106+
// in: query
107+
PageSize int `json:"limit"` // Can be smaller than or equal to setting.ExplorePagingNum
97108
}
98109

99110
// SearchRepositoryByName takes keyword and part of repository name to search,

modules/context/api.go

+31-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,34 @@ type APIContext struct {
2323
Org *APIOrganization
2424
}
2525

26+
// APIError is error format response
27+
// swagger:response error
28+
type APIError struct {
29+
Message string `json:"message"`
30+
URL string `json:"url"`
31+
}
32+
33+
// APIValidationError is error format response related to input validation
34+
// swagger:response validationError
35+
type APIValidationError struct {
36+
Message string `json:"message"`
37+
URL string `json:"url"`
38+
}
39+
40+
//APIEmpty is a empty response
41+
// swagger:response empty
42+
type APIEmpty struct{}
43+
44+
//APIForbiddenError is a forbidden error response
45+
// swagger:response forbidden
46+
type APIForbiddenError struct {
47+
APIError
48+
}
49+
50+
//APINotFound is a not found empty response
51+
// swagger:response notFound
52+
type APINotFound struct{}
53+
2654
// Error responses error message to client with given message.
2755
// If status is 500, also it prints error to log.
2856
func (ctx *APIContext) Error(status int, title string, obj interface{}) {
@@ -37,9 +65,9 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
3765
log.Error(4, "%s: %s", title, message)
3866
}
3967

40-
ctx.JSON(status, map[string]string{
41-
"message": message,
42-
"url": base.DocURL,
68+
ctx.JSON(status, APIError{
69+
Message: message,
70+
URL: base.DocURL,
4371
})
4472
}
4573

445 Bytes
Loading
1.11 KB
Loading

public/assets/swagger-ui/index.html

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
8+
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
9+
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
10+
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
11+
<style>
12+
html
13+
{
14+
box-sizing: border-box;
15+
overflow: -moz-scrollbars-vertical;
16+
overflow-y: scroll;
17+
}
18+
*,
19+
*:before,
20+
*:after
21+
{
22+
box-sizing: inherit;
23+
}
24+
25+
body {
26+
margin:0;
27+
background: #fafafa;
28+
}
29+
</style>
30+
</head>
31+
32+
<body>
33+
34+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
35+
<defs>
36+
<symbol viewBox="0 0 20 20" id="unlocked">
37+
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
38+
</symbol>
39+
40+
<symbol viewBox="0 0 20 20" id="locked">
41+
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
42+
</symbol>
43+
44+
<symbol viewBox="0 0 20 20" id="close">
45+
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
46+
</symbol>
47+
48+
<symbol viewBox="0 0 20 20" id="large-arrow">
49+
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
50+
</symbol>
51+
52+
<symbol viewBox="0 0 20 20" id="large-arrow-down">
53+
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
54+
</symbol>
55+
56+
57+
<symbol viewBox="0 0 24 24" id="jump-to">
58+
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
59+
</symbol>
60+
61+
<symbol viewBox="0 0 24 24" id="expand">
62+
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
63+
</symbol>
64+
65+
</defs>
66+
</svg>
67+
68+
<div id="swagger-ui"></div>
69+
70+
<script src="./swagger-ui-bundle.js"> </script>
71+
<script src="./swagger-ui-standalone-preset.js"> </script>
72+
<script>
73+
window.onload = function() {
74+
// Build a system
75+
const ui = SwaggerUIBundle({
76+
url: "../../swagger.v1.json",
77+
dom_id: '#swagger-ui',
78+
presets: [
79+
SwaggerUIBundle.presets.apis,
80+
SwaggerUIStandalonePreset
81+
],
82+
plugins: [
83+
SwaggerUIBundle.plugins.DownloadUrl
84+
],
85+
layout: "StandaloneLayout"
86+
})
87+
88+
window.ui = ui
89+
}
90+
</script>
91+
</body>
92+
93+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 isValid, qp;
12+
13+
qp = (window.location.hash || location.search).substring(1);
14+
15+
qp = qp ? JSON.parse('{"' + qp.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
16+
function (key, value) {
17+
return key === "" ? value : decodeURIComponent(value)
18+
}
19+
) : {}
20+
21+
isValid = qp.state === sentState
22+
23+
if (oauth2.auth.schema.get("flow") === "accessCode" && !oauth2.auth.code) {
24+
if (!isValid) {
25+
oauth2.errCb({
26+
authId: oauth2.auth.name,
27+
source: "auth",
28+
level: "warning",
29+
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
30+
});
31+
}
32+
33+
if (qp.code) {
34+
delete oauth2.state;
35+
oauth2.auth.code = qp.code;
36+
createForm(oauth2.auth, qp).submit();
37+
} else {
38+
oauth2.errCb({
39+
authId: oauth2.auth.name,
40+
source: "auth",
41+
level: "error",
42+
message: "Authorization failed: no accessCode came from the server"
43+
});
44+
window.close();
45+
}
46+
} else {
47+
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid});
48+
window.close();
49+
}
50+
}
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+
83+
</script>

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

+105
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)