Skip to content

Commit

Permalink
bump up swagger (#21396)
Browse files Browse the repository at this point in the history
* bump up swagger

Signed-off-by: wang yan <wangyan@vmware.com>

* fix gc driver type

Signed-off-by: wang yan <wangyan@vmware.com>

---------

Signed-off-by: wang yan <wangyan@vmware.com>
  • Loading branch information
wy65701436 authored Jan 10, 2025
1 parent 15d17a3 commit b0545c0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ lint_apis:
$(SPECTRAL) lint ./api/v2.0/swagger.yaml

SWAGGER_IMAGENAME=$(IMAGENAMESPACE)/swagger
SWAGGER_VERSION=v0.25.0
SWAGGER_VERSION=v0.31.0
SWAGGER=$(RUNCONTAINER) ${SWAGGER_IMAGENAME}:${SWAGGER_VERSION}
SWAGGER_GENERATE_SERVER=${SWAGGER} generate server --template-dir=$(TOOLSPATH)/swagger/templates --exclude-main --additional-initialism=CVE --additional-initialism=GC --additional-initialism=OIDC
SWAGGER_IMAGE_BUILD_CMD=${DOCKERBUILD} -f ${TOOLSPATH}/swagger/Dockerfile --build-arg GOLANG=${GOBUILDIMAGE} --build-arg SWAGGER_VERSION=${SWAGGER_VERSION} -t ${SWAGGER_IMAGENAME}:$(SWAGGER_VERSION) .
Expand Down
4 changes: 2 additions & 2 deletions src/controller/quota/driver/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (d *driver) HardLimits(ctx context.Context) types.ResourceList {
}
}

func (d *driver) Load(ctx context.Context, key string) (dr.RefObject, error) {
func (d *driver) Load(ctx context.Context, key string) (dr.QuotaRefObject, error) {
thunk := d.loader.Load(ctx, dataloader.StringKey(key))

result, err := thunk()
Expand All @@ -75,7 +75,7 @@ func (d *driver) Load(ctx context.Context, key string) (dr.RefObject, error) {
return nil, fmt.Errorf("bad result for project: %s", key)
}

return dr.RefObject{
return dr.QuotaRefObject{
"id": project.ProjectID,
"name": project.Name,
"owner_name": project.OwnerName,
Expand Down
6 changes: 3 additions & 3 deletions src/pkg/quota/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ var (
drivers = map[string]Driver{}
)

// RefObject type for quota ref object
type RefObject map[string]interface{}
// QuotaRefObject type for quota ref object
type QuotaRefObject map[string]interface{}

// Driver the driver for quota
type Driver interface {
Expand All @@ -36,7 +36,7 @@ type Driver interface {
// HardLimits returns default resource list
HardLimits(ctx context.Context) types.ResourceList
// Load returns quota ref object by key
Load(ctx context.Context, key string) (RefObject, error)
Load(ctx context.Context, key string) (QuotaRefObject, error)
// Validate validate the hard limits
Validate(hardLimits types.ResourceList) error
// CalculateUsage calculate quota usage by reference id
Expand Down
16 changes: 8 additions & 8 deletions src/pkg/quota/models/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (

// Quota quota model for manager
type Quota struct {
ID int64 `orm:"pk;auto;column(id)" json:"id"`
Ref driver.RefObject `orm:"-" json:"ref"`
Reference string `orm:"column(reference)" json:"-"`
ReferenceID string `orm:"column(reference_id)" json:"-"`
Hard string `orm:"column(hard);type(jsonb)" json:"-"`
Used string `orm:"column(used);type(jsonb)" json:"-"`
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
ID int64 `orm:"pk;auto;column(id)" json:"id"`
Ref driver.QuotaRefObject `orm:"-" json:"ref"`
Reference string `orm:"column(reference)" json:"-"`
ReferenceID string `orm:"column(reference_id)" json:"-"`
Hard string `orm:"column(hard);type(jsonb)" json:"-"`
Used string `orm:"column(used);type(jsonb)" json:"-"`
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`

HardVersion int64 `orm:"column(hard_version)" json:"-"`
UsedVersion int64 `orm:"column(used_version)" json:"-"`
Expand Down
24 changes: 23 additions & 1 deletion src/server/v2.0/handler/model/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/goharbor/harbor/src/lib/log"
"github.com/goharbor/harbor/src/pkg/quota"
"github.com/goharbor/harbor/src/pkg/quota/driver"
"github.com/goharbor/harbor/src/pkg/quota/types"
"github.com/goharbor/harbor/src/server/v2.0/models"
)
Expand Down Expand Up @@ -54,7 +55,7 @@ func (q *Quota) ToSwagger(ctx context.Context) *models.Quota {

return &models.Quota{
ID: q.ID,
Ref: q.Ref,
Ref: NewQuotaRefObject(q.Ref).ToSwagger(),
Hard: NewResourceList(hard).ToSwagger(),
Used: NewResourceList(used).ToSwagger(),
CreationTime: strfmt.DateTime(q.CreationTime),
Expand All @@ -66,3 +67,24 @@ func (q *Quota) ToSwagger(ctx context.Context) *models.Quota {
func NewQuota(quota *quota.Quota) *Quota {
return &Quota{Quota: quota}
}

// QuotaRefObject model
type QuotaRefObject struct {
driver.QuotaRefObject
}

// ToSwagger converts the QuotaRefObject to the swagger model
func (rl *QuotaRefObject) ToSwagger() models.QuotaRefObject {
result := make(map[string]interface{}, len(rl.QuotaRefObject))

for name, value := range rl.QuotaRefObject {
result[string(name)] = value
}

return result
}

// NewQuotaRefObject new QuotaRefObject instance
func NewQuotaRefObject(qr driver.QuotaRefObject) *QuotaRefObject {
return &QuotaRefObject{QuotaRefObject: qr}
}
10 changes: 5 additions & 5 deletions src/testing/pkg/quota/driver/driver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tools/swagger/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG GOLANG
FROM ${GOLANG}

ARG SWAGGER_VERSION
RUN curl -fsSL -o /usr/bin/swagger https://github.com/go-swagger/go-swagger/releases/download/$SWAGGER_VERSION/swagger_linux_amd64 && chmod +x /usr/bin/swagger
RUN go install github.com/go-swagger/go-swagger/cmd/swagger@$SWAGGER_VERSION

ENTRYPOINT ["/usr/bin/swagger"]
ENTRYPOINT ["swagger"]
CMD ["--help"]

0 comments on commit b0545c0

Please sign in to comment.