fix: support pagination for GetBranches

The docs mention that this is a Paged API, yet there is no support for
limit and start query params.
This commit is contained in:
mlosicki 2022-01-24 00:30:09 +01:00
parent dff2223ade
commit 4880bdf0b7
2 changed files with 56 additions and 0 deletions

View File

@ -3260,7 +3260,19 @@ func (a *DefaultApiService) GetBranches(project, repository string, localVarOpti
if err := typeCheckParameter(localVarOptionals["orderBy"], "string", "orderBy"); err != nil { if err := typeCheckParameter(localVarOptionals["orderBy"], "string", "orderBy"); err != nil {
return nil, err return nil, err
} }
if err := typeCheckParameter(localVarOptionals["limit"], "int", "limit"); err != nil {
return nil, err
}
if err := typeCheckParameter(localVarOptionals["start"], "int", "start"); err != nil {
return nil, err
}
if localVarTempParam, localVarOk := localVarOptionals["limit"].(int); localVarOk {
localVarQueryParams.Add("limit", parameterToString(localVarTempParam, ""))
}
if localVarTempParam, localVarOk := localVarOptionals["start"].(int); localVarOk {
localVarQueryParams.Add("start", parameterToString(localVarTempParam, ""))
}
if localVarTempParam, localVarOk := localVarOptionals["base"].(string); localVarOk { if localVarTempParam, localVarOk := localVarOptionals["base"].(string); localVarOk {
localVarQueryParams.Add("base", parameterToString(localVarTempParam, "")) localVarQueryParams.Add("base", parameterToString(localVarTempParam, ""))
} }

View File

@ -5,6 +5,9 @@
package bitbucketv1 package bitbucketv1
import ( import (
"io"
"net/http"
"net/http/httptest"
"os" "os"
"reflect" "reflect"
"testing" "testing"
@ -2331,6 +2334,47 @@ func TestDefaultApiService_GetBranches(t *testing.T) {
} }
} }
func TestDefaultApiService_GetBranchesPagination(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.RequestURI {
case "/api/1.0/projects/PROJECT/repos/REPO/branches?limit=100&start=0":
io.WriteString(w, `{
"size": 1,
"limit": 100,
"isLastPage": true,
"values": [
{
"id": "refs/heads/main",
"displayId": "main",
"type": "BRANCH",
"latestCommit": "8d51122def5632836d1cb1026e879069e10a1e13",
"latestChangeset": "8d51122def5632836d1cb1026e879069e10a1e13",
"isDefault": true
}
],
"start": 0
}`)
default:
t.Errorf("DefaultApiService.GetBranches() error = unhandled request %s", r.RequestURI)
}
}))
defer ts.Close()
client := NewAPIClient(
context.TODO(),
NewConfiguration(ts.URL),
)
_, err := client.DefaultApi.GetBranches("PROJECT", "REPO", map[string]interface{}{
"limit": 100,
"start": 0,
})
if err != nil {
t.Errorf("DefaultApiService.GetBranches() error = %v", err)
return
}
}
func TestDefaultApiService_GetChanges(t *testing.T) { func TestDefaultApiService_GetChanges(t *testing.T) {
type fields struct { type fields struct {
client *APIClient client *APIClient