From 916367dccb7b0903d1e6356373380932ed93c387 Mon Sep 17 00:00:00 2001 From: Hannah Cooper Date: Thu, 4 Jun 2026 15:14:07 +1200 Subject: [PATCH] fix(api-docs): time.Duration bounds fix + linting fixes [C9S-223] (#2762) --- Makefile | 2 +- api/.swaggo | 1 + api/crypto/nonce.go | 3 ++- api/gitops/workflows/mapping.go | 14 ++++++++------ api/http/handler/stacks/stack_stop.go | 4 ++-- 5 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 api/.swaggo diff --git a/Makefile b/Makefile index adb4a36a29..e72b77abf4 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ dev-extension: build-server build-client ## Run the extension in development mod .PHONY: docs-build docs-validate docs-clean docs-validate-clean docs-build: init-dist ## Build docs go mod download - cd api && $(SWAG) init -o "../dist/docs" -ot "yaml" -g ./http/handler/handler.go --parseDependency --parseInternal --parseDepth 2 -p pascalcase --markdownFiles ./ + cd api && $(SWAG) init -o "../dist/docs" -ot "yaml" -g ./http/handler/handler.go --parseDependency --parseInternal --parseDepth 2 -p pascalcase --markdownFiles ./ --overridesFile .swaggo docs-validate: docs-build ## Validate docs pnpm swagger2openapi --warnOnly dist/docs/swagger.yaml -o dist/docs/openapi.yaml diff --git a/api/.swaggo b/api/.swaggo new file mode 100644 index 0000000000..3f6089489d --- /dev/null +++ b/api/.swaggo @@ -0,0 +1 @@ +replace k8s.io/apimachinery/pkg/apis/meta/v1.Duration string diff --git a/api/crypto/nonce.go b/api/crypto/nonce.go index af1cc898bd..4753374a6e 100644 --- a/api/crypto/nonce.go +++ b/api/crypto/nonce.go @@ -4,6 +4,7 @@ import ( "crypto/rand" "errors" "io" + "slices" ) type Nonce struct { @@ -45,7 +46,7 @@ func (n *Nonce) Value() []byte { func (n *Nonce) Increment() error { // Start incrementing from the least significant byte - for i := len(n.val) - 1; i >= 0; i-- { + for i := range slices.Backward(n.val) { // Increment the current byte n.val[i]++ diff --git a/api/gitops/workflows/mapping.go b/api/gitops/workflows/mapping.go index fec1c70ec8..c652dc4acf 100644 --- a/api/gitops/workflows/mapping.go +++ b/api/gitops/workflows/mapping.go @@ -1,6 +1,8 @@ package workflows import ( + "slices" + portainer "github.com/portainer/portainer/api" gittypes "github.com/portainer/portainer/api/git/types" "github.com/portainer/portainer/api/set" @@ -61,9 +63,9 @@ func MapEdgeStackToWorkflow(es portainer.EdgeStack, gitConfig *gittypes.RepoConf } func StackLastSyncDate(s portainer.Stack) int64 { - for i := len(s.DeploymentStatus) - 1; i >= 0; i-- { - if s.DeploymentStatus[i].Status == portainer.StackStatusActive { - return s.DeploymentStatus[i].Time + for _, ds := range slices.Backward(s.DeploymentStatus) { + if ds.Status == portainer.StackStatusActive { + return ds.Time } } return 0 @@ -84,9 +86,9 @@ func edgeStackLastSyncDate(statuses []portainer.EdgeStackStatusForEnv) int64 { } func endpointLastSyncDate(epStatus portainer.EdgeStackStatusForEnv) int64 { - for i := len(epStatus.Status) - 1; i >= 0; i-- { - if isEdgeStackHealthyStatus(epStatus.Status[i].Type) { - return epStatus.Status[i].Time + for _, s := range slices.Backward(epStatus.Status) { + if isEdgeStackHealthyStatus(s.Type) { + return s.Time } } return 0 diff --git a/api/http/handler/stacks/stack_stop.go b/api/http/handler/stacks/stack_stop.go index 6f15e8d9c0..447642db81 100644 --- a/api/http/handler/stacks/stack_stop.go +++ b/api/http/handler/stacks/stack_stop.go @@ -18,8 +18,8 @@ import ( ) // @id StackStop -// @summary Stops a stopped Stack -// @description Stops a stopped Stack. +// @summary Stop a running Stack +// @description Stop a running Stack. // @description **Access policy**: authenticated // @tags stacks // @security ApiKeyAuth