0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-04 22:57:34 -04:00

fix swagger

This commit is contained in:
wxiaoguang 2025-07-02 19:26:45 +08:00
parent 7a13e5a58a
commit fd19585760
3 changed files with 26 additions and 5 deletions

View File

@ -812,9 +812,10 @@ func GetContentsExt(ctx *context.APIContext) {
// required: true
// - name: filepath
// in: path
// description: path of the dir, file, symlink or submodule in the repo
// description: path of the dir, file, symlink or submodule in the repo. Swagger requires path parameter to be "required",
// you can leave it empty or pass a single dot (".") to get the root directory.
// type: string
// required: false
// required: true
// - name: ref
// in: query
// description: the name of the commit/branch/tag, default to the repositorys default branch.
@ -833,6 +834,11 @@ func GetContentsExt(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
treePath := ctx.PathParam("*")
if treePath == "." || treePath == "/" {
treePath = ""
ctx.SetPathParam("*", treePath)
}
opts := files_service.GetContentsOrListOptions{TreePath: ctx.PathParam("*")}
for includeOpt := range strings.SplitSeq(ctx.FormString("includes"), ",") {
if includeOpt == "" {

View File

@ -7547,9 +7547,10 @@
},
{
"type": "string",
"description": "path of the dir, file, symlink or submodule in the repo",
"description": "path of the dir, file, symlink or submodule in the repo. Swagger requires path parameter to be \"required\", you can leave it empty or pass a single dot (\".\") to get the root directory.",
"name": "filepath",
"in": "path"
"in": "path",
"required": true
},
{
"type": "string",

View File

@ -206,11 +206,25 @@ func testAPIGetContentsExt(t *testing.T) {
session := loginUser(t, "user2")
token2 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
t.Run("DirContents", func(t *testing.T) {
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/contents-ext/docs?ref=sub-home-md-img-check")
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/contents-ext?ref=sub-home-md-img-check")
resp := MakeRequest(t, req, http.StatusOK)
var contentsResponse api.ContentsExtResponse
DecodeJSON(t, resp, &contentsResponse)
assert.Nil(t, contentsResponse.FileContents)
assert.NotNil(t, contentsResponse.DirContents)
req = NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/contents-ext/.?ref=sub-home-md-img-check")
resp = MakeRequest(t, req, http.StatusOK)
contentsResponse = api.ContentsExtResponse{}
DecodeJSON(t, resp, &contentsResponse)
assert.Nil(t, contentsResponse.FileContents)
assert.NotNil(t, contentsResponse.DirContents)
req = NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/contents-ext/docs?ref=sub-home-md-img-check")
resp = MakeRequest(t, req, http.StatusOK)
contentsResponse = api.ContentsExtResponse{}
DecodeJSON(t, resp, &contentsResponse)
assert.Nil(t, contentsResponse.FileContents)
assert.Equal(t, "README.md", contentsResponse.DirContents[0].Name)
assert.Nil(t, contentsResponse.DirContents[0].Encoding)
assert.Nil(t, contentsResponse.DirContents[0].Content)