mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-01 14:56:30 +00:00
update swagger for explore code
This commit is contained in:
parent
1bf78712d4
commit
ed8d76be3b
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
package structs // import "code.gitea.io/gitea/modules/structs"
|
package structs // import "code.gitea.io/gitea/modules/structs"
|
||||||
|
|
||||||
// ExploreCodeSearchItem A single search match
|
// ExploreCodeSearchItem A code search match
|
||||||
// swagger:model
|
// swagger:model
|
||||||
type ExploreCodeSearchItem struct {
|
type ExploreCodeSearchItem struct {
|
||||||
RepoName string `json:"repoName"`
|
RepoName string `json:"repoName"`
|
||||||
@ -12,7 +12,7 @@ type ExploreCodeSearchItem struct {
|
|||||||
LineText string `json:"lineText"`
|
LineText string `json:"lineText"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExploreCodeResult all returned search results
|
// ExploreCodeResult all returned code search results
|
||||||
// swagger:model
|
// swagger:model
|
||||||
type ExploreCodeResult struct {
|
type ExploreCodeResult struct {
|
||||||
Total int `json:"total"`
|
Total int `json:"total"`
|
||||||
|
@ -17,18 +17,43 @@ import (
|
|||||||
|
|
||||||
// Code explore code
|
// Code explore code
|
||||||
func Code(ctx *context.APIContext) {
|
func Code(ctx *context.APIContext) {
|
||||||
|
// swagger:operation GET /explore/code explore codeSearch
|
||||||
|
// ---
|
||||||
|
// summary: Search for code
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// parameters:
|
||||||
|
// - name: q
|
||||||
|
// in: query
|
||||||
|
// description: keyword
|
||||||
|
// type: string
|
||||||
|
// - name: page
|
||||||
|
// in: query
|
||||||
|
// description: page number of results to return (1-based)
|
||||||
|
// type: integer
|
||||||
|
// - name: fuzzy
|
||||||
|
// in: query
|
||||||
|
// description: whether to search fuzzy or strict
|
||||||
|
// type: boolean
|
||||||
|
// responses:
|
||||||
|
// "200":
|
||||||
|
// description: "SearchResults of a successful search"
|
||||||
|
// schema:
|
||||||
|
// "$ref": "#/definitions/ExploreCodeResult"
|
||||||
if !setting.Indexer.RepoIndexerEnabled {
|
if !setting.Indexer.RepoIndexerEnabled {
|
||||||
ctx.NotFound("Indexer not enabled")
|
ctx.NotFound("Indexer not enabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
language := ctx.FormTrim("l")
|
|
||||||
keyword := ctx.FormTrim("q")
|
keyword := ctx.FormTrim("q")
|
||||||
|
|
||||||
isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(true)
|
isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(true)
|
||||||
|
|
||||||
if keyword == "" {
|
if keyword == "" {
|
||||||
ctx.JSON(http.StatusInternalServerError, api.SearchError{OK: false, Error: "No keyword provided"})
|
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
||||||
|
OK: false,
|
||||||
|
Error: "No keyword provided",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +75,10 @@ func Code(ctx *context.APIContext) {
|
|||||||
if ctx.Doer == nil || !isAdmin {
|
if ctx.Doer == nil || !isAdmin {
|
||||||
repoIDs, err = repo_model.FindUserCodeAccessibleRepoIDs(ctx, ctx.Doer)
|
repoIDs, err = repo_model.FindUserCodeAccessibleRepoIDs(ctx, ctx.Doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("FindUserCodeAccessibleRepoIDs", err)
|
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
||||||
|
OK: false,
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,7 +95,6 @@ func Code(ctx *context.APIContext) {
|
|||||||
Keyword: keyword,
|
Keyword: keyword,
|
||||||
IsKeywordFuzzy: isFuzzy,
|
IsKeywordFuzzy: isFuzzy,
|
||||||
IsHtmlSafe: false,
|
IsHtmlSafe: false,
|
||||||
Language: language,
|
|
||||||
Paginator: &db.ListOptions{
|
Paginator: &db.ListOptions{
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: setting.API.DefaultPagingNum,
|
PageSize: setting.API.DefaultPagingNum,
|
||||||
@ -75,7 +102,10 @@ func Code(ctx *context.APIContext) {
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if code_indexer.IsAvailable(ctx) {
|
if code_indexer.IsAvailable(ctx) {
|
||||||
ctx.ServerError("SearchResults", err)
|
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
||||||
|
OK: false,
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +126,10 @@ func Code(ctx *context.APIContext) {
|
|||||||
|
|
||||||
repoMaps, err = repo_model.GetRepositoriesMapByIDs(ctx, loadRepoIDs)
|
repoMaps, err = repo_model.GetRepositoriesMapByIDs(ctx, loadRepoIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetRepositoriesMapByIDs", err)
|
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
||||||
|
OK: false,
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
routers/api/v1/swagger/explore.go
Normal file
15
routers/api/v1/swagger/explore.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package swagger
|
||||||
|
|
||||||
|
import (
|
||||||
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ExploreCode
|
||||||
|
// swagger:response ExploreCode
|
||||||
|
type swaggerResponseExploreCode struct {
|
||||||
|
// out:body
|
||||||
|
Body api.ExploreCodeResult `json:"body"`
|
||||||
|
}
|
@ -15,7 +15,7 @@ func ToExploreCodeSearchResults(total int, results []*code_indexer.Result, repoM
|
|||||||
if repo := repoMaps[res.RepoID]; repo != nil {
|
if repo := repoMaps[res.RepoID]; repo != nil {
|
||||||
for _, r := range res.Lines {
|
for _, r := range res.Lines {
|
||||||
out.Results = append(out.Results, api.ExploreCodeSearchItem{
|
out.Results = append(out.Results, api.ExploreCodeSearchItem{
|
||||||
RepoName: repo.Name,
|
RepoName: repo.FullName(),
|
||||||
FilePath: res.Filename,
|
FilePath: res.Filename,
|
||||||
LineNumber: r.Num,
|
LineNumber: r.Num,
|
||||||
LineText: r.RawContent,
|
LineText: r.RawContent,
|
||||||
|
94
templates/swagger/v1_json.tmpl
generated
94
templates/swagger/v1_json.tmpl
generated
@ -1009,6 +1009,46 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/explore/code": {
|
||||||
|
"get": {
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"explore"
|
||||||
|
],
|
||||||
|
"summary": "Search for code",
|
||||||
|
"operationId": "codeSearch",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "keyword",
|
||||||
|
"name": "q",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "page number of results to return (1-based)",
|
||||||
|
"name": "page",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "whether to search fuzzy or strict",
|
||||||
|
"name": "fuzzy",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "SearchResults of a successful search",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ExploreCodeResult"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/gitignore/templates": {
|
"/gitignore/templates": {
|
||||||
"get": {
|
"get": {
|
||||||
"produces": [
|
"produces": [
|
||||||
@ -21331,6 +21371,49 @@
|
|||||||
},
|
},
|
||||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||||
},
|
},
|
||||||
|
"ExploreCodeResult": {
|
||||||
|
"description": "ExploreCodeResult all returned code search results",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"results": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/ExploreCodeSearchItem"
|
||||||
|
},
|
||||||
|
"x-go-name": "Results"
|
||||||
|
},
|
||||||
|
"total": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"x-go-name": "Total"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||||
|
},
|
||||||
|
"ExploreCodeSearchItem": {
|
||||||
|
"description": "ExploreCodeSearchItem A code search match",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"lineNumber": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"x-go-name": "LineNumber"
|
||||||
|
},
|
||||||
|
"lineText": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "LineText"
|
||||||
|
},
|
||||||
|
"path": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "FilePath"
|
||||||
|
},
|
||||||
|
"repoName": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "RepoName"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||||
|
},
|
||||||
"ExternalTracker": {
|
"ExternalTracker": {
|
||||||
"description": "ExternalTracker represents settings for external tracker",
|
"description": "ExternalTracker represents settings for external tracker",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
@ -25397,6 +25480,17 @@
|
|||||||
"$ref": "#/definitions/APIError"
|
"$ref": "#/definitions/APIError"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"ExploreCode": {
|
||||||
|
"description": "ExploreCode",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/ExploreCodeResult"
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"body": {
|
||||||
|
"description": "out:body"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"FileDeleteResponse": {
|
"FileDeleteResponse": {
|
||||||
"description": "FileDeleteResponse",
|
"description": "FileDeleteResponse",
|
||||||
"schema": {
|
"schema": {
|
||||||
|
Loading…
Reference in New Issue
Block a user