Skip to content

Commit fd19585

Browse files
committed
fix swagger
1 parent 7a13e5a commit fd19585

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

routers/api/v1/repo/file.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,10 @@ func GetContentsExt(ctx *context.APIContext) {
812812
// required: true
813813
// - name: filepath
814814
// in: path
815-
// description: path of the dir, file, symlink or submodule in the repo
815+
// description: path of the dir, file, symlink or submodule in the repo. Swagger requires path parameter to be "required",
816+
// you can leave it empty or pass a single dot (".") to get the root directory.
816817
// type: string
817-
// required: false
818+
// required: true
818819
// - name: ref
819820
// in: query
820821
// description: the name of the commit/branch/tag, default to the repository’s default branch.
@@ -833,6 +834,11 @@ func GetContentsExt(ctx *context.APIContext) {
833834
// "404":
834835
// "$ref": "#/responses/notFound"
835836

837+
treePath := ctx.PathParam("*")
838+
if treePath == "." || treePath == "/" {
839+
treePath = ""
840+
ctx.SetPathParam("*", treePath)
841+
}
836842
opts := files_service.GetContentsOrListOptions{TreePath: ctx.PathParam("*")}
837843
for includeOpt := range strings.SplitSeq(ctx.FormString("includes"), ",") {
838844
if includeOpt == "" {

templates/swagger/v1_json.tmpl

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/api_repo_get_contents_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,25 @@ func testAPIGetContentsExt(t *testing.T) {
206206
session := loginUser(t, "user2")
207207
token2 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
208208
t.Run("DirContents", func(t *testing.T) {
209-
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/contents-ext/docs?ref=sub-home-md-img-check")
209+
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/contents-ext?ref=sub-home-md-img-check")
210210
resp := MakeRequest(t, req, http.StatusOK)
211211
var contentsResponse api.ContentsExtResponse
212212
DecodeJSON(t, resp, &contentsResponse)
213213
assert.Nil(t, contentsResponse.FileContents)
214+
assert.NotNil(t, contentsResponse.DirContents)
215+
216+
req = NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/contents-ext/.?ref=sub-home-md-img-check")
217+
resp = MakeRequest(t, req, http.StatusOK)
218+
contentsResponse = api.ContentsExtResponse{}
219+
DecodeJSON(t, resp, &contentsResponse)
220+
assert.Nil(t, contentsResponse.FileContents)
221+
assert.NotNil(t, contentsResponse.DirContents)
222+
223+
req = NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/contents-ext/docs?ref=sub-home-md-img-check")
224+
resp = MakeRequest(t, req, http.StatusOK)
225+
contentsResponse = api.ContentsExtResponse{}
226+
DecodeJSON(t, resp, &contentsResponse)
227+
assert.Nil(t, contentsResponse.FileContents)
214228
assert.Equal(t, "README.md", contentsResponse.DirContents[0].Name)
215229
assert.Nil(t, contentsResponse.DirContents[0].Encoding)
216230
assert.Nil(t, contentsResponse.DirContents[0].Content)

0 commit comments

Comments
 (0)