fix: remove x-go-type in swagger.yaml (#15923)

Closes #15912

Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
He Weiwei 2021-11-04 23:39:36 +08:00 committed by GitHub
parent 71ee8b57c2
commit b2268dbf8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 137 additions and 84 deletions

View File

@ -6773,10 +6773,6 @@ definitions:
additionalProperties:
type: integer
format: int64
x-go-type:
type: ResourceList
import:
package: "github.com/goharbor/harbor/src/pkg/quota/types"
ReplicationExecution:
type: object
description: The replication execution
@ -7927,10 +7923,18 @@ definitions:
format: date-time
InternalConfigurationsResponse:
type: object
x-go-type:
type: InternalCfg
import:
package: "github.com/goharbor/harbor/src/lib/config"
additionalProperties:
$ref: '#/definitions/InternalConfigurationValue'
InternalConfigurationValue:
type: object
properties:
value:
type: object
description: The value of current config item
editable:
type: boolean
x-omitempty: false
description: The configure item can be updated or not
ConfigurationsResponse:
type: object
properties:

View File

@ -22,7 +22,6 @@ import (
"github.com/goharbor/harbor/src/common"
comModels "github.com/goharbor/harbor/src/common/models"
"github.com/goharbor/harbor/src/lib/config/metadata"
"github.com/goharbor/harbor/src/lib/config/models"
"github.com/goharbor/harbor/src/lib/encrypt"
"github.com/goharbor/harbor/src/lib/log"
"github.com/goharbor/harbor/src/lib/orm"
@ -43,9 +42,6 @@ var (
managers = make(map[string]Manager)
)
// InternalCfg internal configure response model
type InternalCfg map[string]*models.Value
// Manager defines the operation for config
type Manager interface {
Load(ctx context.Context) error

View File

@ -17,6 +17,7 @@ package handler
import (
"context"
"encoding/json"
"github.com/go-openapi/runtime/middleware"
"github.com/goharbor/harbor/src/common/rbac"
"github.com/goharbor/harbor/src/common/security"
@ -111,7 +112,13 @@ func (c *configAPI) GetInternalconfig(ctx context.Context, params configure.GetI
if err != nil {
return c.SendError(ctx, err)
}
return configure.NewGetInternalconfigOK().WithPayload(resultCfg)
payload := make(models.InternalConfigurationsResponse, len(resultCfg))
for key, cfg := range resultCfg {
payload[key] = models.InternalConfigurationValue{Value: cfg.Val, Editable: cfg.Editable}
}
return configure.NewGetInternalconfigOK().WithPayload(payload)
}
func toResponseModel(cfg map[string]*cfgModels.Value) (*models.ConfigurationsResponse, error) {

View File

@ -54,8 +54,8 @@ func (q *Quota) ToSwagger(ctx context.Context) *models.Quota {
return &models.Quota{
ID: q.ID,
Ref: q.Ref,
Hard: hard,
Used: used,
Hard: NewResourceList(hard).ToSwagger(),
Used: NewResourceList(used).ToSwagger(),
CreationTime: strfmt.DateTime(q.CreationTime),
UpdateTime: strfmt.DateTime(q.UpdateTime),
}

View File

@ -0,0 +1,41 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package model
import (
"github.com/goharbor/harbor/src/pkg/quota/types"
"github.com/goharbor/harbor/src/server/v2.0/models"
)
// ResourceList model
type ResourceList struct {
types.ResourceList
}
// ToSwagger converts the resource list to the swagger model
func (rl *ResourceList) ToSwagger() models.ResourceList {
result := make(map[string]int64, len(rl.ResourceList))
for name, value := range rl.ResourceList {
result[string(name)] = value
}
return result
}
// NewResourceList new resource list instance
func NewResourceList(rl types.ResourceList) *ResourceList {
return &ResourceList{ResourceList: rl}
}

View File

@ -748,10 +748,10 @@ func getProjectQuotaSummary(ctx context.Context, p *project.Project, summary *mo
summary.Quota = &models.ProjectSummaryQuota{}
if hard, err := q.GetHard(); err == nil {
summary.Quota.Hard = hard
summary.Quota.Hard = model.NewResourceList(hard).ToSwagger()
}
if used, err := q.GetUsed(); err == nil {
summary.Quota.Used = used
summary.Quota.Used = model.NewResourceList(used).ToSwagger()
}
}

View File

@ -23,6 +23,7 @@ import (
"github.com/goharbor/harbor/src/lib"
"github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/pkg/quota/types"
"github.com/goharbor/harbor/src/server/v2.0/handler/model"
"github.com/goharbor/harbor/src/server/v2.0/models"
operation "github.com/goharbor/harbor/src/server/v2.0/restapi/operations/quota"
@ -102,11 +103,16 @@ func (qa *quotaAPI) UpdateQuota(ctx context.Context, params operation.UpdateQuot
return qa.SendError(ctx, err)
}
if err := quota.Validate(ctx, q.Reference, params.Hard.Hard); err != nil {
hard := make(types.ResourceList, len(params.Hard.Hard))
for name, value := range params.Hard.Hard {
hard[types.ResourceName(name)] = value
}
if err := quota.Validate(ctx, q.Reference, hard); err != nil {
return qa.SendError(ctx, errors.BadRequestError(nil).WithMessage(err.Error()))
}
q.SetHard(params.Hard.Hard)
q.SetHard(hard)
if err := qa.quotaCtl.Update(ctx, q); err != nil {
return qa.SendError(ctx, err)

View File

@ -25,7 +25,6 @@ import (
"github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/pkg/quota"
"github.com/goharbor/harbor/src/pkg/quota/types"
"github.com/goharbor/harbor/src/server/v2.0/models"
"github.com/goharbor/harbor/src/server/v2.0/restapi"
quotatesting "github.com/goharbor/harbor/src/testing/controller/quota"
@ -75,7 +74,7 @@ func (suite *QuotaTestSuite) TestAuthorization() {
}
quota := models.QuotaUpdateReq{
Hard: types.ResourceList{"storage": 1000},
Hard: models.ResourceList{"storage": 1000},
}
reqs := []struct {
@ -214,7 +213,7 @@ func (suite *QuotaTestSuite) TestUpdateQuota() {
{
// update quota with empty hard
quota := models.QuotaUpdateReq{
Hard: types.ResourceList{},
Hard: models.ResourceList{},
}
res, err := suite.PutJSON("/quotas/1", quota)
@ -227,7 +226,7 @@ func (suite *QuotaTestSuite) TestUpdateQuota() {
mock.OnAnything(suite.quotaCtl, "Get").Return(nil, errors.NotFoundError(nil)).Once()
quota := models.QuotaUpdateReq{
Hard: types.ResourceList{"storage": 1000},
Hard: models.ResourceList{"storage": 1000},
}
res, err := suite.PutJSON("/quotas/1", quota)
@ -241,7 +240,7 @@ func (suite *QuotaTestSuite) TestUpdateQuota() {
mock.OnAnything(suite.quotaCtl, "Update").Return(nil).Once()
quota := models.QuotaUpdateReq{
Hard: types.ResourceList{"storage": 1000},
Hard: models.ResourceList{"storage": 1000},
}
res, err := suite.PutJSON("/quotas/1", quota)
@ -255,7 +254,7 @@ func (suite *QuotaTestSuite) TestUpdateQuota() {
mock.OnAnything(suite.quotaCtl, "Update").Return(fmt.Errorf("failed to update the quota")).Once()
quota := models.QuotaUpdateReq{
Hard: types.ResourceList{"storage": 1000},
Hard: models.ResourceList{"storage": 1000},
}
res, err := suite.PutJSON("/quotas/1", quota)
@ -269,7 +268,7 @@ func (suite *QuotaTestSuite) TestUpdateQuota() {
mock.OnAnything(suite.quotaCtl, "Update").Return(nil).Once()
quota := models.QuotaUpdateReq{
Hard: types.ResourceList{"size": 1000},
Hard: models.ResourceList{"size": 1000},
}
res, err := suite.PutJSON("/quotas/1", quota)