Skip to content

Commit fc2f2c7

Browse files
authored
API: Move AllowedReactions endpoint into GetGenneralUI endpoint + creat new swagger section settings (#11854)
* move Setting function into its own package * swagger add&use new section "settings" * move api AllowedReactions into general UI-Settings endpoint * prepare TEST * lint
1 parent b948ecb commit fc2f2c7

File tree

7 files changed

+73
-33
lines changed

7 files changed

+73
-33
lines changed

integrations/api_issue_reaction_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ import (
2020
func TestAPIAllowedReactions(t *testing.T) {
2121
defer prepareTestEnv(t)()
2222

23-
type allowed []string
23+
a := new(api.GeneralUISettings)
2424

25-
a := new(allowed)
26-
27-
req := NewRequest(t, "GET", "/api/v1/settings/allowed_reactions")
25+
req := NewRequest(t, "GET", "/api/v1/settings/ui")
2826
resp := MakeRequest(t, req, http.StatusOK)
2927

3028
DecodeJSON(t, resp, &a)
31-
assert.Len(t, *a, len(setting.UI.Reactions))
32-
assert.ElementsMatch(t, setting.UI.Reactions, *a)
29+
assert.Len(t, a.AllowedReactions, len(setting.UI.Reactions))
30+
assert.ElementsMatch(t, setting.UI.Reactions, a.AllowedReactions)
3331
}
3432

3533
func TestAPIIssuesReactions(t *testing.T) {

modules/structs/settings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ type GeneralRepoSettings struct {
99
MirrorsDisabled bool `json:"mirrors_disabled"`
1010
HTTPGitDisabled bool `json:"http_git_disabled"`
1111
}
12+
13+
// GeneralUISettings contains global ui settings exposed by API
14+
type GeneralUISettings struct {
15+
AllowedReactions []string `json:"allowed_reactions"`
16+
}

routers/api/v1/api.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import (
7373
"code.gitea.io/gitea/routers/api/v1/notify"
7474
"code.gitea.io/gitea/routers/api/v1/org"
7575
"code.gitea.io/gitea/routers/api/v1/repo"
76+
"code.gitea.io/gitea/routers/api/v1/settings"
7677
_ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation
7778
"code.gitea.io/gitea/routers/api/v1/user"
7879

@@ -513,8 +514,8 @@ func RegisterRoutes(m *macaron.Macaron) {
513514
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
514515
m.Post("/markdown/raw", misc.MarkdownRaw)
515516
m.Group("/settings", func() {
516-
m.Get("/allowed_reactions", misc.SettingGetsAllowedReactions)
517-
m.Get("/repository", misc.GetGeneralRepoSettings)
517+
m.Get("/ui", settings.GetGeneralUISettings)
518+
m.Get("/repository", settings.GetGeneralRepoSettings)
518519
})
519520

520521
// Notifications

routers/api/v1/misc/settings.go renamed to routers/api/v1/settings/settings.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

5-
package misc
5+
package settings
66

77
import (
88
"net/http"
@@ -12,22 +12,24 @@ import (
1212
api "code.gitea.io/gitea/modules/structs"
1313
)
1414

15-
// SettingGetsAllowedReactions return allowed reactions
16-
func SettingGetsAllowedReactions(ctx *context.APIContext) {
17-
// swagger:operation GET /settings/allowed_reactions miscellaneous getAllowedReactions
15+
// GetGeneralUISettings returns instance's global settings for ui
16+
func GetGeneralUISettings(ctx *context.APIContext) {
17+
// swagger:operation GET /settings/ui settings getGeneralUISettings
1818
// ---
19-
// summary: Returns string array of allowed reactions
19+
// summary: Get instance's global settings for ui
2020
// produces:
2121
// - application/json
2222
// responses:
2323
// "200":
24-
// "$ref": "#/responses/StringSlice"
25-
ctx.JSON(http.StatusOK, setting.UI.Reactions)
24+
// "$ref": "#/responses/GeneralUISettings"
25+
ctx.JSON(http.StatusOK, api.GeneralUISettings{
26+
AllowedReactions: setting.UI.Reactions,
27+
})
2628
}
2729

2830
// GetGeneralRepoSettings returns instance's global settings for repositories
2931
func GetGeneralRepoSettings(ctx *context.APIContext) {
30-
// swagger:operation GET /settings/repository miscellaneous getGeneralRepositorySettings
32+
// swagger:operation GET /settings/repository settings getGeneralRepositorySettings
3133
// ---
3234
// summary: Get instance's global settings for repositories
3335
// produces:

routers/api/v1/swagger/misc.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,3 @@ type swaggerResponseStringSlice struct {
2121
// in:body
2222
Body []string `json:"body"`
2323
}
24-
25-
// GeneralRepoSettings
26-
// swagger:response GeneralRepoSettings
27-
type swaggerResponseGeneralRepoSettings struct {
28-
// in:body
29-
Body api.GeneralRepoSettings `json:"body"`
30-
}

routers/api/v1/swagger/settings.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package swagger
6+
7+
import api "code.gitea.io/gitea/modules/structs"
8+
9+
// GeneralRepoSettings
10+
// swagger:response GeneralRepoSettings
11+
type swaggerResponseGeneralRepoSettings struct {
12+
// in:body
13+
Body api.GeneralRepoSettings `json:"body"`
14+
}
15+
16+
// GeneralUISettings
17+
// swagger:response GeneralUISettings
18+
type swaggerResponseGeneralUISettings struct {
19+
// in:body
20+
Body api.GeneralUISettings `json:"body"`
21+
}

templates/swagger/v1_json.tmpl

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8470,36 +8470,36 @@
84708470
}
84718471
}
84728472
},
8473-
"/settings/allowed_reactions": {
8473+
"/settings/repository": {
84748474
"get": {
84758475
"produces": [
84768476
"application/json"
84778477
],
84788478
"tags": [
8479-
"miscellaneous"
8479+
"settings"
84808480
],
8481-
"summary": "Returns string array of allowed reactions",
8482-
"operationId": "getAllowedReactions",
8481+
"summary": "Get instance's global settings for repositories",
8482+
"operationId": "getGeneralRepositorySettings",
84838483
"responses": {
84848484
"200": {
8485-
"$ref": "#/responses/StringSlice"
8485+
"$ref": "#/responses/GeneralRepoSettings"
84868486
}
84878487
}
84888488
}
84898489
},
8490-
"/settings/repository": {
8490+
"/settings/ui": {
84918491
"get": {
84928492
"produces": [
84938493
"application/json"
84948494
],
84958495
"tags": [
8496-
"miscellaneous"
8496+
"settings"
84978497
],
8498-
"summary": "Get instance's global settings for repositories",
8499-
"operationId": "getGeneralRepositorySettings",
8498+
"summary": "Get instance's global settings for ui",
8499+
"operationId": "getGeneralUISettings",
85008500
"responses": {
85018501
"200": {
8502-
"$ref": "#/responses/GeneralRepoSettings"
8502+
"$ref": "#/responses/GeneralUISettings"
85038503
}
85048504
}
85058505
}
@@ -12753,6 +12753,20 @@
1275312753
},
1275412754
"x-go-package": "code.gitea.io/gitea/modules/structs"
1275512755
},
12756+
"GeneralUISettings": {
12757+
"description": "GeneralUISettings contains global ui settings exposed by API",
12758+
"type": "object",
12759+
"properties": {
12760+
"allowed_reactions": {
12761+
"type": "array",
12762+
"items": {
12763+
"type": "string"
12764+
},
12765+
"x-go-name": "AllowedReactions"
12766+
}
12767+
},
12768+
"x-go-package": "code.gitea.io/gitea/modules/structs"
12769+
},
1275612770
"GitBlobResponse": {
1275712771
"description": "GitBlobResponse represents a git blob",
1275812772
"type": "object",
@@ -14928,6 +14942,12 @@
1492814942
"$ref": "#/definitions/GeneralRepoSettings"
1492914943
}
1493014944
},
14945+
"GeneralUISettings": {
14946+
"description": "GeneralUISettings",
14947+
"schema": {
14948+
"$ref": "#/definitions/GeneralUISettings"
14949+
}
14950+
},
1493114951
"GitBlobResponse": {
1493214952
"description": "GitBlobResponse",
1493314953
"schema": {

0 commit comments

Comments
 (0)