Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Commit 5691784

Browse files
authored
Update Go dependancies and fix a bug when walking file responses (#31)
* Fix counting error when walking file responses (#2) * fix linting issues * fix counting error when iterating responses * Update go dependancies and migrate to go v1.23 (#1)
1 parent 879ec3e commit 5691784

10 files changed

Lines changed: 262 additions & 659 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
strategy:
3131
matrix:
3232
os: [ ubuntu-latest, macos-latest, windows-latest ]
33-
go-version: [ 1.17 ]
33+
go-version: [ 1.23 ]
3434
name: ${{ matrix.os }} @ Go ${{ matrix.go-version }}
3535
runs-on: ${{ matrix.os }}
3636
steps:

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ run:
44
linters:
55
disable-all: true
66
enable:
7-
- goerr113
7+
- err113
88

99
issues:
1010
exclude-rules:
1111
- path: tests/api/
1212
text: "do not define dynamic errors, use wrapped static errors instead"
1313
linters:
14-
- goerr113
14+
- err113

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ endif
8181

8282
.PHONY: lint
8383
lint:
84-
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.40.0 golangci-lint run -v --max-issues-per-linter=0 --max-same-issues=0
84+
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.62.2 golangci-lint run -v --max-issues-per-linter=0 --max-same-issues=0
8585

8686
.PHONY: install
8787
install: framework ## builds and installs the binaries of the APIKit in $GOPATH/bin

generator/client_generator.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ func (gen *goClientGenerator) generateOperation(operation *Operation, nameOfClie
373373
)
374374

375375
lastFileResponseIndex := -1
376-
walkResponses(operation, func(statusCode int, response spec.Response) {
376+
walkResponses(operation, func(index int, statusCode int, response spec.Response) {
377377
if response.Schema != nil && response.Schema.Type.Contains("file") && operation.HasProduces(ContentTypesForFiles...) {
378-
lastFileResponseIndex++
378+
lastFileResponseIndex = index
379379
}
380380
})
381381

@@ -393,16 +393,12 @@ func (gen *goClientGenerator) generateOperation(operation *Operation, nameOfClie
393393
)
394394
}
395395

396-
var currentIndex int
397-
var addedDeferStatement bool
398-
walkResponses(operation, func(statusCode int, response spec.Response) {
396+
walkResponses(operation, func(index int, statusCode int, response spec.Response) {
399397
gen.generateResponse(operation, statusCode, response, stmts)
400398
// generate defer http.Response.Close statement after last file response handler
401-
if lastFileResponseIndex > -1 && currentIndex == lastFileResponseIndex && addedDeferStatement == false {
402-
addedDeferStatement = true
399+
if index == lastFileResponseIndex {
403400
stmts.Defer().Id("httpResponse").Dot("Body").Dot("Close").Call()
404401
}
405-
currentIndex++
406402
})
407403

408404
stmts.If(jen.Id("client").Dot("hooks").Dot("OnUnknownResponseCode").Op("!=").Nil()).Block(

generator/generatorutil.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func getDefinitionName(schema spec.Schema) string {
1919
return ""
2020
}
2121

22-
func walkResponses(operation *Operation, f func(statusCode int, response spec.Response)) {
22+
func walkResponses(operation *Operation, f func(index int, statusCode int, response spec.Response)) {
2323
responses := operation.Responses.StatusCodeResponses
2424

2525
type Priority struct {
@@ -46,8 +46,8 @@ func walkResponses(operation *Operation, f func(statusCode int, response spec.Re
4646
return statusCodesOrder[i].value < statusCodesOrder[j].value
4747
})
4848

49-
for _, v := range statusCodesOrder {
50-
f(v.statusCode, responses[v.statusCode])
49+
for i, v := range statusCodesOrder {
50+
f(i, v.statusCode, responses[v.statusCode])
5151
}
5252
}
5353

@@ -56,7 +56,7 @@ func hasFileEndpointValidProduce(operation *Operation) (bool, int) {
5656
var match bool
5757
var counter int
5858

59-
walkResponses(operation, func(statusCode int, response spec.Response) {
59+
walkResponses(operation, func(_, statusCode int, response spec.Response) {
6060
if response.Schema != nil && response.Schema.Type.Contains("file") {
6161
match = true
6262
if operation.HasProduces(ContentTypesForFiles...) {

generator/mock_client_generator.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package generator
33
import (
44
"github.com/spf13/viper"
55
"github.com/vektra/mockery/v2/cmd"
6-
"github.com/vektra/mockery/v2/pkg/config"
76
"strings"
87
)
98

@@ -21,7 +20,6 @@ func (gen *mockGoClientGenerator) Generate(clientName, path string) error {
2120
mockery.Config.InPackage = true
2221
mockery.Config.Name = strings.Title(clientName)
2322
mockery.Config.Dir = path
24-
config.SemVer = "v2.9.0"
2523

2624
return mockery.Run()
2725
}

generator/types_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func (gen *goTypesGenerator) generateResponses(operation *Operation, file *file.
343343
jen.Id("write").Params(jen.Id("response").Qual("net/http", "ResponseWriter")).Error(),
344344
).Line()
345345

346-
walkResponses(operation, func(statusCode int, response spec.Response) {
346+
walkResponses(operation, func(_, statusCode int, response spec.Response) {
347347

348348
responseName := strings.Title(fmt.Sprintf("%s%dResponse", operation.ID, statusCode))
349349
responseType, err := gen.makeResponse(responseName, response.Schema, response.Headers)

go.mod

Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,87 @@
11
module github.com/ExperienceOne/apikit
22

3-
go 1.13
3+
go 1.23
44

55
require (
6-
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect
7-
github.com/corpix/uarand v0.1.1 // indirect
8-
github.com/dave/jennifer v1.4.0
6+
github.com/dave/jennifer v1.7.1
97
github.com/fatih/astrewrite v0.0.0-20191207154002-9094e544fcef
10-
github.com/go-openapi/analysis v0.19.7
11-
github.com/go-openapi/errors v0.19.3
12-
github.com/go-openapi/loads v0.19.4
13-
github.com/go-openapi/runtime v0.19.11 // indirect
14-
github.com/go-openapi/spec v0.19.6
15-
github.com/go-openapi/strfmt v0.19.4
16-
github.com/go-openapi/swag v0.19.7 // indirect
17-
github.com/go-openapi/validate v0.19.6
8+
github.com/go-openapi/analysis v0.23.0
9+
github.com/go-openapi/errors v0.22.0
10+
github.com/go-openapi/loads v0.22.0
11+
github.com/go-openapi/spec v0.21.0
12+
github.com/go-openapi/strfmt v0.23.0
13+
github.com/go-openapi/validate v0.24.0
1814
github.com/go-ozzo/ozzo-routing v2.1.4+incompatible
19-
github.com/go-playground/universal-translator v0.17.0 // indirect
2015
github.com/go-playground/validator v9.31.0+incompatible
21-
github.com/gofrs/uuid v3.2.0+incompatible
22-
github.com/golang/gddo v0.0.0-20191216155521-fbfc0f5e7810 // indirect
23-
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
24-
github.com/leodido/go-urn v1.2.0 // indirect
25-
github.com/mailru/easyjson v0.7.1 // indirect
16+
github.com/gofrs/uuid v4.4.0+incompatible
17+
github.com/icrowley/fake v0.0.0-20240710202011-f797eb4a99c0
2618
github.com/pkg/errors v0.9.1
27-
github.com/prometheus/client_golang v1.11.1
28-
github.com/sirupsen/logrus v1.8.1
29-
github.com/spf13/viper v1.7.0
30-
github.com/stretchr/testify v1.6.1
31-
github.com/urfave/cli v1.22.2
32-
github.com/vektra/mockery/v2 v2.9.0
33-
go.mongodb.org/mongo-driver v1.5.1 // indirect
34-
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6
35-
golang.org/x/sys v0.1.0 // indirect
36-
golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e
19+
github.com/prometheus/client_golang v1.20.5
20+
github.com/sirupsen/logrus v1.9.3
21+
github.com/spf13/viper v1.19.0
22+
github.com/stretchr/testify v1.10.0
23+
github.com/urfave/cli v1.22.16
24+
github.com/vektra/mockery/v2 v2.50.0
25+
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e
26+
golang.org/x/tools v0.28.0
27+
)
28+
29+
require (
30+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
31+
github.com/beorn7/perks v1.0.1 // indirect
32+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
33+
github.com/chigopher/pathlib v0.19.1 // indirect
34+
github.com/corpix/uarand v0.2.0 // indirect
35+
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
36+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
37+
github.com/fsnotify/fsnotify v1.8.0 // indirect
38+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
39+
github.com/go-openapi/jsonreference v0.21.0 // indirect
40+
github.com/go-openapi/swag v0.23.0 // indirect
41+
github.com/go-playground/locales v0.14.1 // indirect
42+
github.com/go-playground/universal-translator v0.18.1 // indirect
43+
github.com/golang/gddo v0.0.0-20191216155521-fbfc0f5e7810 // indirect
44+
github.com/google/uuid v1.6.0 // indirect
45+
github.com/hashicorp/hcl v1.0.0 // indirect
46+
github.com/huandu/xstrings v1.5.0 // indirect
47+
github.com/iancoleman/strcase v0.3.0 // indirect
48+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
49+
github.com/jinzhu/copier v0.4.0 // indirect
50+
github.com/josharian/intern v1.0.0 // indirect
51+
github.com/leodido/go-urn v1.4.0 // indirect
52+
github.com/magiconair/properties v1.8.9 // indirect
53+
github.com/mailru/easyjson v0.9.0 // indirect
54+
github.com/mattn/go-colorable v0.1.13 // indirect
55+
github.com/mattn/go-isatty v0.0.20 // indirect
56+
github.com/mitchellh/go-homedir v1.1.0 // indirect
57+
github.com/mitchellh/mapstructure v1.5.0 // indirect
58+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
59+
github.com/oklog/ulid v1.3.1 // indirect
60+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
61+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
62+
github.com/prometheus/client_model v0.6.1 // indirect
63+
github.com/prometheus/common v0.61.0 // indirect
64+
github.com/prometheus/procfs v0.15.1 // indirect
65+
github.com/rs/zerolog v1.33.0 // indirect
66+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
67+
github.com/sagikazarmark/locafero v0.6.0 // indirect
68+
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
69+
github.com/sourcegraph/conc v0.3.0 // indirect
70+
github.com/spf13/afero v1.11.0 // indirect
71+
github.com/spf13/cast v1.7.0 // indirect
72+
github.com/spf13/cobra v1.8.1 // indirect
73+
github.com/spf13/pflag v1.0.5 // indirect
74+
github.com/stretchr/objx v0.5.2 // indirect
75+
github.com/subosito/gotenv v1.6.0 // indirect
76+
go.mongodb.org/mongo-driver v1.17.1 // indirect
77+
go.uber.org/multierr v1.11.0 // indirect
78+
golang.org/x/mod v0.22.0 // indirect
79+
golang.org/x/sync v0.10.0 // indirect
80+
golang.org/x/sys v0.28.0 // indirect
81+
golang.org/x/term v0.27.0 // indirect
82+
golang.org/x/text v0.21.0 // indirect
83+
google.golang.org/protobuf v1.36.0 // indirect
3784
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
85+
gopkg.in/ini.v1 v1.67.0 // indirect
86+
gopkg.in/yaml.v3 v3.0.1 // indirect
3887
)

0 commit comments

Comments
 (0)