Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go-version: [ 1.17 ]
go-version: [ 1.23 ]
name: ${{ matrix.os }} @ Go ${{ matrix.go-version }}
runs-on: ${{ matrix.os }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ run:
linters:
disable-all: true
enable:
- goerr113
- err113

issues:
exclude-rules:
- path: tests/api/
text: "do not define dynamic errors, use wrapped static errors instead"
linters:
- goerr113
- err113
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ endif

.PHONY: lint
lint:
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
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

.PHONY: install
install: framework ## builds and installs the binaries of the APIKit in $GOPATH/bin
Expand Down
12 changes: 4 additions & 8 deletions generator/client_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ func (gen *goClientGenerator) generateOperation(operation *Operation, nameOfClie
)

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

Expand All @@ -393,16 +393,12 @@ func (gen *goClientGenerator) generateOperation(operation *Operation, nameOfClie
)
}

var currentIndex int
var addedDeferStatement bool
walkResponses(operation, func(statusCode int, response spec.Response) {
walkResponses(operation, func(index int, statusCode int, response spec.Response) {
gen.generateResponse(operation, statusCode, response, stmts)
// generate defer http.Response.Close statement after last file response handler
if lastFileResponseIndex > -1 && currentIndex == lastFileResponseIndex && addedDeferStatement == false {
addedDeferStatement = true
if index == lastFileResponseIndex {
stmts.Defer().Id("httpResponse").Dot("Body").Dot("Close").Call()
}
currentIndex++
})

stmts.If(jen.Id("client").Dot("hooks").Dot("OnUnknownResponseCode").Op("!=").Nil()).Block(
Expand Down
8 changes: 4 additions & 4 deletions generator/generatorutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func getDefinitionName(schema spec.Schema) string {
return ""
}

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

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

for _, v := range statusCodesOrder {
f(v.statusCode, responses[v.statusCode])
for i, v := range statusCodesOrder {
f(i, v.statusCode, responses[v.statusCode])
}
}

Expand All @@ -56,7 +56,7 @@ func hasFileEndpointValidProduce(operation *Operation) (bool, int) {
var match bool
var counter int

walkResponses(operation, func(statusCode int, response spec.Response) {
walkResponses(operation, func(_, statusCode int, response spec.Response) {
if response.Schema != nil && response.Schema.Type.Contains("file") {
match = true
if operation.HasProduces(ContentTypesForFiles...) {
Expand Down
2 changes: 0 additions & 2 deletions generator/mock_client_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package generator
import (
"github.com/spf13/viper"
"github.com/vektra/mockery/v2/cmd"
"github.com/vektra/mockery/v2/pkg/config"
"strings"
)

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

return mockery.Run()
}
2 changes: 1 addition & 1 deletion generator/types_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (gen *goTypesGenerator) generateResponses(operation *Operation, file *file.
jen.Id("write").Params(jen.Id("response").Qual("net/http", "ResponseWriter")).Error(),
).Line()

walkResponses(operation, func(statusCode int, response spec.Response) {
walkResponses(operation, func(_, statusCode int, response spec.Response) {

responseName := strings.Title(fmt.Sprintf("%s%dResponse", operation.ID, statusCode))
responseType, err := gen.makeResponse(responseName, response.Schema, response.Headers)
Expand Down
105 changes: 77 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,38 +1,87 @@
module github.com/ExperienceOne/apikit

go 1.13
go 1.23

require (
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect
github.com/corpix/uarand v0.1.1 // indirect
github.com/dave/jennifer v1.4.0
github.com/dave/jennifer v1.7.1
github.com/fatih/astrewrite v0.0.0-20191207154002-9094e544fcef
github.com/go-openapi/analysis v0.19.7
github.com/go-openapi/errors v0.19.3
github.com/go-openapi/loads v0.19.4
github.com/go-openapi/runtime v0.19.11 // indirect
github.com/go-openapi/spec v0.19.6
github.com/go-openapi/strfmt v0.19.4
github.com/go-openapi/swag v0.19.7 // indirect
github.com/go-openapi/validate v0.19.6
github.com/go-openapi/analysis v0.23.0
github.com/go-openapi/errors v0.22.0
github.com/go-openapi/loads v0.22.0
github.com/go-openapi/spec v0.21.0
github.com/go-openapi/strfmt v0.23.0
github.com/go-openapi/validate v0.24.0
github.com/go-ozzo/ozzo-routing v2.1.4+incompatible
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator v9.31.0+incompatible
github.com/gofrs/uuid v3.2.0+incompatible
github.com/golang/gddo v0.0.0-20191216155521-fbfc0f5e7810 // indirect
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
github.com/leodido/go-urn v1.2.0 // indirect
github.com/mailru/easyjson v0.7.1 // indirect
github.com/gofrs/uuid v4.4.0+incompatible
github.com/icrowley/fake v0.0.0-20240710202011-f797eb4a99c0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.1
github.com/sirupsen/logrus v1.8.1
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.6.1
github.com/urfave/cli v1.22.2
github.com/vektra/mockery/v2 v2.9.0
go.mongodb.org/mongo-driver v1.5.1 // indirect
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6
golang.org/x/sys v0.1.0 // indirect
golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e
github.com/prometheus/client_golang v1.20.5
github.com/sirupsen/logrus v1.9.3
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
github.com/urfave/cli v1.22.16
github.com/vektra/mockery/v2 v2.50.0
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e
golang.org/x/tools v0.28.0
)

require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chigopher/pathlib v0.19.1 // indirect
github.com/corpix/uarand v0.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/golang/gddo v0.0.0-20191216155521-fbfc0f5e7810 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/magiconair/properties v1.8.9 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.61.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.mongodb.org/mongo-driver v1.17.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.36.0 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading