From 8a11cbc8756f39752c74accb8cab2f43f90da192 Mon Sep 17 00:00:00 2001 From: shaowenchen Date: Thu, 11 Jun 2020 18:21:34 +0800 Subject: [PATCH] fix apiresult Signed-off-by: shaowenchen --- pkg/kapis/devops/v1alpha3/register.go | 6 +++--- pkg/models/devops/devops.go | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/kapis/devops/v1alpha3/register.go b/pkg/kapis/devops/v1alpha3/register.go index 8bc4cea94..15b16c58e 100644 --- a/pkg/kapis/devops/v1alpha3/register.go +++ b/pkg/kapis/devops/v1alpha3/register.go @@ -60,7 +60,7 @@ func AddToContainer(container *restful.Container, devopsClient devopsClient.Inte DataFormat("limit=%d,page=%d"). DefaultValue("limit=10,page=1")). Doc("list the credentials of the specified devops for the current user"). - Returns(http.StatusOK, api.StatusOK, api.ListResult{}). + Returns(http.StatusOK, api.StatusOK, api.ListResult{Items: []interface{}{}}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectTag})) ws.Route(ws.POST("/devops/{devops}/credentials"). @@ -105,7 +105,7 @@ func AddToContainer(container *restful.Container, devopsClient devopsClient.Inte DataFormat("limit=%d,page=%d"). DefaultValue("limit=10,page=1")). Doc("list the pipelines of the specified devops for the current user"). - Returns(http.StatusOK, api.StatusOK, api.ListResult{}). + Returns(http.StatusOK, api.StatusOK, api.ListResult{Items: []interface{}{}}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectTag})) ws.Route(ws.POST("/devops/{devops}/pipelines"). @@ -147,7 +147,7 @@ func AddToContainer(container *restful.Container, devopsClient devopsClient.Inte Required(false). DataFormat("limit=%d,page=%d"). DefaultValue("limit=10,page=1")).Doc("List the devopsproject of the specified workspace for the current user"). - Returns(http.StatusOK, api.StatusOK, api.ListResult{}). + Returns(http.StatusOK, api.StatusOK, api.ListResult{Items: []interface{}{}}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectTag})) ws.Route(ws.POST("/workspaces/{workspace}/devops"). diff --git a/pkg/models/devops/devops.go b/pkg/models/devops/devops.go index 06b49a204..0fd6c6cfe 100644 --- a/pkg/models/devops/devops.go +++ b/pkg/models/devops/devops.go @@ -175,6 +175,9 @@ func (d devopsOperator) ListDevOpsProject(workspace string, limit, offset int) ( limit = len(result) - offset } items = result[offset : offset+limit] + if items == nil { + items = []interface{}{} + } return api.ListResult{TotalItems: len(result), Items: items}, nil } @@ -218,7 +221,7 @@ func (d devopsOperator) ListPipelineObj(projectName string, limit, offset int) ( } data, err := d.ksInformers.Devops().V1alpha3().Pipelines().Lister().Pipelines(projectObj.Status.AdminNamespace).List(labels.Everything()) if err != nil { - return api.ListResult{}, nil + return api.ListResult{}, err } items := make([]interface{}, 0) var result []interface{} @@ -230,6 +233,9 @@ func (d devopsOperator) ListPipelineObj(projectName string, limit, offset int) ( limit = len(result) - offset } items = result[offset : offset+limit] + if items == nil { + items = []interface{}{} + } return api.ListResult{TotalItems: len(result), Items: items}, nil } @@ -298,6 +304,9 @@ func (d devopsOperator) ListCredentialObj(projectName string, limit, offset int) limit = len(result) - offset } items = result[offset : offset+limit] + if items == nil { + items = []interface{}{} + } return api.ListResult{TotalItems: len(result), Items: items}, nil }