Skip to content

Commit ed8d76b

Browse files
committed
update swagger for explore code
1 parent 1bf7871 commit ed8d76b

File tree

5 files changed

+152
-10
lines changed

5 files changed

+152
-10
lines changed

modules/structs/explore.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
package structs // import "code.gitea.io/gitea/modules/structs"
55

6-
// ExploreCodeSearchItem A single search match
6+
// ExploreCodeSearchItem A code search match
77
// swagger:model
88
type ExploreCodeSearchItem struct {
99
RepoName string `json:"repoName"`
@@ -12,7 +12,7 @@ type ExploreCodeSearchItem struct {
1212
LineText string `json:"lineText"`
1313
}
1414

15-
// ExploreCodeResult all returned search results
15+
// ExploreCodeResult all returned code search results
1616
// swagger:model
1717
type ExploreCodeResult struct {
1818
Total int `json:"total"`

routers/api/v1/explore/code.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,43 @@ import (
1717

1818
// Code explore code
1919
func Code(ctx *context.APIContext) {
20+
// swagger:operation GET /explore/code explore codeSearch
21+
// ---
22+
// summary: Search for code
23+
// produces:
24+
// - application/json
25+
// parameters:
26+
// - name: q
27+
// in: query
28+
// description: keyword
29+
// type: string
30+
// - name: page
31+
// in: query
32+
// description: page number of results to return (1-based)
33+
// type: integer
34+
// - name: fuzzy
35+
// in: query
36+
// description: whether to search fuzzy or strict
37+
// type: boolean
38+
// responses:
39+
// "200":
40+
// description: "SearchResults of a successful search"
41+
// schema:
42+
// "$ref": "#/definitions/ExploreCodeResult"
2043
if !setting.Indexer.RepoIndexerEnabled {
2144
ctx.NotFound("Indexer not enabled")
2245
return
2346
}
2447

25-
language := ctx.FormTrim("l")
2648
keyword := ctx.FormTrim("q")
2749

2850
isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(true)
2951

3052
if keyword == "" {
31-
ctx.JSON(http.StatusInternalServerError, api.SearchError{OK: false, Error: "No keyword provided"})
53+
ctx.JSON(http.StatusInternalServerError, api.SearchError{
54+
OK: false,
55+
Error: "No keyword provided",
56+
})
3257
return
3358
}
3459

@@ -50,7 +75,10 @@ func Code(ctx *context.APIContext) {
5075
if ctx.Doer == nil || !isAdmin {
5176
repoIDs, err = repo_model.FindUserCodeAccessibleRepoIDs(ctx, ctx.Doer)
5277
if err != nil {
53-
ctx.ServerError("FindUserCodeAccessibleRepoIDs", err)
78+
ctx.JSON(http.StatusInternalServerError, api.SearchError{
79+
OK: false,
80+
Error: err.Error(),
81+
})
5482
return
5583
}
5684
}
@@ -67,15 +95,17 @@ func Code(ctx *context.APIContext) {
6795
Keyword: keyword,
6896
IsKeywordFuzzy: isFuzzy,
6997
IsHtmlSafe: false,
70-
Language: language,
7198
Paginator: &db.ListOptions{
7299
Page: page,
73100
PageSize: setting.API.DefaultPagingNum,
74101
},
75102
})
76103
if err != nil {
77104
if code_indexer.IsAvailable(ctx) {
78-
ctx.ServerError("SearchResults", err)
105+
ctx.JSON(http.StatusInternalServerError, api.SearchError{
106+
OK: false,
107+
Error: err.Error(),
108+
})
79109
return
80110
}
81111
}
@@ -96,7 +126,10 @@ func Code(ctx *context.APIContext) {
96126

97127
repoMaps, err = repo_model.GetRepositoriesMapByIDs(ctx, loadRepoIDs)
98128
if err != nil {
99-
ctx.ServerError("GetRepositoriesMapByIDs", err)
129+
ctx.JSON(http.StatusInternalServerError, api.SearchError{
130+
OK: false,
131+
Error: err.Error(),
132+
})
100133
return
101134
}
102135

routers/api/v1/swagger/explore.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package swagger
5+
6+
import (
7+
api "code.gitea.io/gitea/modules/structs"
8+
)
9+
10+
// ExploreCode
11+
// swagger:response ExploreCode
12+
type swaggerResponseExploreCode struct {
13+
// out:body
14+
Body api.ExploreCodeResult `json:"body"`
15+
}

services/convert/explore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func ToExploreCodeSearchResults(total int, results []*code_indexer.Result, repoM
1515
if repo := repoMaps[res.RepoID]; repo != nil {
1616
for _, r := range res.Lines {
1717
out.Results = append(out.Results, api.ExploreCodeSearchItem{
18-
RepoName: repo.Name,
18+
RepoName: repo.FullName(),
1919
FilePath: res.Filename,
2020
LineNumber: r.Num,
2121
LineText: r.RawContent,

templates/swagger/v1_json.tmpl

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

0 commit comments

Comments
 (0)