From 6f9b857b6a7e41fc1373012891609e21df27ccae Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Fri, 1 Mar 2024 23:02:46 +0100 Subject: [PATCH] Update deps, fix lint (#98) --- .github/workflows/golangci-lint.yml | 6 +++--- .github/workflows/gorelease.yml | 2 +- .github/workflows/test-unit.yml | 4 ++-- Makefile | 2 +- go.mod | 4 ++-- go.sum | 8 ++++---- internal/json_schema.go | 5 +++-- openapi3/reflect.go | 5 ++++- openapi3/reflect_deprecated_test.go | 2 +- openapi3/reflect_test.go | 2 +- openapi3/walk_schema_test.go | 6 +++--- openapi31/reflect.go | 4 +++- openapi31/reflect_test.go | 3 ++- openapi31/walk_schema_test.go | 6 +++--- 14 files changed, 33 insertions(+), 26 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5e985cc..6239219 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -21,13 +21,13 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: 1.21.x + go-version: 1.22.x - uses: actions/checkout@v2 - name: golangci-lint - uses: golangci/golangci-lint-action@v3.7.0 + uses: golangci/golangci-lint-action@v4.0.0 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.55.2 + version: v1.56.2 # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/.github/workflows/gorelease.yml b/.github/workflows/gorelease.yml index 97ebe87..6356a9d 100644 --- a/.github/workflows/gorelease.yml +++ b/.github/workflows/gorelease.yml @@ -9,7 +9,7 @@ concurrency: cancel-in-progress: true env: - GO_VERSION: 1.21.x + GO_VERSION: 1.22.x jobs: gorelease: runs-on: ubuntu-latest diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 7ce70d7..4472858 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -15,13 +15,13 @@ concurrency: env: GO111MODULE: "on" RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing. - COV_GO_VERSION: 1.21.x # Version of Go to collect coverage + COV_GO_VERSION: 1.22.x # Version of Go to collect coverage TARGET_DELTA_COV: 90 # Target coverage of changed lines, in percents jobs: test: strategy: matrix: - go-version: [ 1.16.x, 1.20.x, 1.21.x ] + go-version: [ 1.16.x, 1.21.x, 1.22.x ] runs-on: ubuntu-latest steps: - name: Install Go stable diff --git a/Makefile b/Makefile index 0b346b6..71dd110 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -#GOLANGCI_LINT_VERSION := "v1.55.2" # Optional configuration to pinpoint golangci-lint version. +#GOLANGCI_LINT_VERSION := "v1.56.2" # Optional configuration to pinpoint golangci-lint version. # The head of Makefile determines location of dev-go to include standard targets. GO ?= go diff --git a/go.mod b/go.mod index 6984d29..4a5b680 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/swaggest/openapi-go go 1.18 require ( - github.com/bool64/dev v0.2.32 + github.com/bool64/dev v0.2.34 github.com/stretchr/testify v1.8.2 github.com/swaggest/assertjson v1.9.0 - github.com/swaggest/jsonschema-go v0.3.64 + github.com/swaggest/jsonschema-go v0.3.66 github.com/swaggest/refl v1.3.0 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 76ca615..1004248 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/bool64/dev v0.2.32 h1:DRZtloaoH1Igky3zphaUHV9+SLIV2H3lsf78JsJHFg0= -github.com/bool64/dev v0.2.32/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= +github.com/bool64/dev v0.2.34 h1:P9n315P8LdpxusnYQ0X7MP1CZXwBK5ae5RZrd+GdSZE= +github.com/bool64/dev v0.2.34/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E= github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -33,8 +33,8 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= -github.com/swaggest/jsonschema-go v0.3.64 h1:HyB41fkA4XP0BZkqWfGap5i2JtRHQGXG/21dGDPbyLM= -github.com/swaggest/jsonschema-go v0.3.64/go.mod h1:DYuKqdpms/edvywsX6p1zHXCZkdwB28wRaBdFCe3Duw= +github.com/swaggest/jsonschema-go v0.3.66 h1:4c5d7NRRqPLTswsbaypKqcMe3Z+CYHE3/lGsPIByp8o= +github.com/swaggest/jsonschema-go v0.3.66/go.mod h1:7N43/CwdaWgPUDfYV70K7Qm79tRqe/al7gLSt9YeGIE= github.com/swaggest/refl v1.3.0 h1:PEUWIku+ZznYfsoyheF97ypSduvMApYyGkYF3nabS0I= github.com/swaggest/refl v1.3.0/go.mod h1:3Ujvbmh1pfSbDYjC6JGG7nMgPvpG0ehQL4iNonnLNbg= github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= diff --git a/internal/json_schema.go b/internal/json_schema.go index e93e140..a7166c9 100644 --- a/internal/json_schema.go +++ b/internal/json_schema.go @@ -27,7 +27,7 @@ const ( var defNameSanitizer = regexp.MustCompile(`[^a-zA-Z0-9.\-_]+`) func sanitizeDefName(rc *jsonschema.ReflectContext) { - jsonschema.InterceptDefName(func(t reflect.Type, defaultDefName string) string { + jsonschema.InterceptDefName(func(_ reflect.Type, defaultDefName string) string { return defNameSanitizer.ReplaceAllString(defaultDefName, "") })(rc) } @@ -80,10 +80,10 @@ func ReflectRequestBody( // Checking for default options that allow tag-less JSON. isProcessWithoutTags := false + _, err = r.Reflect("", func(rc *jsonschema.ReflectContext) { isProcessWithoutTags = rc.ProcessWithoutTags }) - if err != nil { return nil, false, fmt.Errorf("BUG: %w", err) } @@ -160,6 +160,7 @@ func ReflectRequestBody( params.Schema.AddType(jsonschema.String) params.Schema.RemoveType(jsonschema.Null) params.Schema.WithFormat("binary") + if is31 { params.Schema.WithExtraPropertiesItem("contentMediaType", "application/octet-stream") } diff --git a/openapi3/reflect.go b/openapi3/reflect.go index 783c7c0..8f01a90 100644 --- a/openapi3/reflect.go +++ b/openapi3/reflect.go @@ -449,6 +449,7 @@ func (r *Reflector) parseParametersIn( swg2CollectionFormat := "" refl.ReadStringTag(field.Tag, "collectionFormat", &swg2CollectionFormat) + switch swg2CollectionFormat { case "csv": p.WithStyle(string(QueryParameterStyleForm)).WithExplode(false) @@ -476,6 +477,7 @@ func (r *Reflector) parseParametersIn( openapiSchema := SchemaOrRef{} openapiSchema.FromJSONSchema(propertySchema.ToSchemaOrBool()) + p.Schema = nil p.WithContentItem("application/json", MediaType{Schema: &openapiSchema}) } else { @@ -503,6 +505,7 @@ func (r *Reflector) parseParametersIn( } alreadyExists := false + for _, ep := range o.Parameters { if ep.Parameter != nil && ep.Parameter.In == p.In && ep.Parameter.Name == p.Name { alreadyExists = true @@ -535,7 +538,7 @@ func (r *Reflector) parseParametersIn( var defNameSanitizer = regexp.MustCompile(`[^a-zA-Z0-9.\-_]+`) func sanitizeDefName(rc *jsonschema.ReflectContext) { - jsonschema.InterceptDefName(func(t reflect.Type, defaultDefName string) string { + jsonschema.InterceptDefName(func(_ reflect.Type, defaultDefName string) string { return defNameSanitizer.ReplaceAllString(defaultDefName, "") })(rc) } diff --git a/openapi3/reflect_deprecated_test.go b/openapi3/reflect_deprecated_test.go index 31ba9b4..032abf6 100644 --- a/openapi3/reflect_deprecated_test.go +++ b/openapi3/reflect_deprecated_test.go @@ -602,7 +602,7 @@ func TestOperationCtx(t *testing.T) { func(rc *jsonschema.ReflectContext) { currentRC = rc }, - jsonschema.InterceptSchema(func(params jsonschema.InterceptSchemaParams) (stop bool, err error) { + jsonschema.InterceptSchema(func(_ jsonschema.InterceptSchemaParams) (stop bool, err error) { if occ, ok := openapi3.OperationCtx(currentRC); ok { if occ.ProcessingResponse { visited["resp:"+occ.ProcessingIn] = true diff --git a/openapi3/reflect_test.go b/openapi3/reflect_test.go index 5d96109..0e6c37e 100644 --- a/openapi3/reflect_test.go +++ b/openapi3/reflect_test.go @@ -731,7 +731,7 @@ func TestReflector_AddOperation_OperationCtx(t *testing.T) { func(rc *jsonschema.ReflectContext) { currentRC = rc }, - jsonschema.InterceptSchema(func(params jsonschema.InterceptSchemaParams) (stop bool, err error) { + jsonschema.InterceptSchema(func(_ jsonschema.InterceptSchemaParams) (stop bool, err error) { if occ, ok := openapi.OperationCtx(currentRC); ok { if occ.IsProcessingResponse() { visited["resp:"+string(occ.ProcessingIn())] = true diff --git a/openapi3/walk_schema_test.go b/openapi3/walk_schema_test.go index 6eb83cb..12b08d2 100644 --- a/openapi3/walk_schema_test.go +++ b/openapi3/walk_schema_test.go @@ -59,7 +59,7 @@ func TestReflector_WalkRequestJSONSchemas(t *testing.T) { return nil }, - func(oc openapi.OperationContext) { + func(_ openapi.OperationContext) { doneCalled++ }, )) @@ -149,7 +149,7 @@ func TestReflector_WalkRequestJSONSchemas_jsonBody(t *testing.T) { return nil }, - func(oc openapi.OperationContext) { + func(_ openapi.OperationContext) { doneCalled++ }, )) @@ -234,7 +234,7 @@ func TestReflector_WalkResponseJSONSchemas(t *testing.T) { return nil }, - func(oc openapi.OperationContext) { + func(_ openapi.OperationContext) { doneCalled++ }, )) diff --git a/openapi31/reflect.go b/openapi31/reflect.go index 90fb130..923dc2e 100644 --- a/openapi31/reflect.go +++ b/openapi31/reflect.go @@ -394,6 +394,7 @@ func (r *Reflector) parseParametersIn( swg2CollectionFormat := "" refl.ReadStringTag(field.Tag, "collectionFormat", &swg2CollectionFormat) + switch swg2CollectionFormat { case "csv": p.WithStyle(ParameterStyleForm).WithExplode(false) @@ -451,6 +452,7 @@ func (r *Reflector) parseParametersIn( } alreadyExists := false + for _, ep := range o.Parameters { if ep.Parameter != nil && ep.Parameter.In == p.In && ep.Parameter.Name == p.Name { alreadyExists = true @@ -484,7 +486,7 @@ func (r *Reflector) parseParametersIn( var defNameSanitizer = regexp.MustCompile(`[^a-zA-Z0-9.\-_]+`) func sanitizeDefName(rc *jsonschema.ReflectContext) { - jsonschema.InterceptDefName(func(t reflect.Type, defaultDefName string) string { + jsonschema.InterceptDefName(func(_ reflect.Type, defaultDefName string) string { return defNameSanitizer.ReplaceAllString(defaultDefName, "") })(rc) } diff --git a/openapi31/reflect_test.go b/openapi31/reflect_test.go index 2e5b364..b5352ee 100644 --- a/openapi31/reflect_test.go +++ b/openapi31/reflect_test.go @@ -755,7 +755,7 @@ func TestReflector_AddOperation_OperationCtx(t *testing.T) { func(rc *jsonschema.ReflectContext) { currentRC = rc }, - jsonschema.InterceptSchema(func(params jsonschema.InterceptSchemaParams) (stop bool, err error) { + jsonschema.InterceptSchema(func(_ jsonschema.InterceptSchemaParams) (stop bool, err error) { if occ, ok := openapi.OperationCtx(currentRC); ok { if occ.IsProcessingResponse() { visited["resp:"+string(occ.ProcessingIn())] = true @@ -1156,6 +1156,7 @@ func Test_Repro2(t *testing.T) { op.AddReqStructure(dummyIn, openapi.WithContentType("application/json")) op.AddRespStructure(dummyOut, openapi.WithHTTPStatus(200)) + if err = oarefl.AddOperation(op); err != nil { t.Fatal(err) } diff --git a/openapi31/walk_schema_test.go b/openapi31/walk_schema_test.go index 908c06f..0224f66 100644 --- a/openapi31/walk_schema_test.go +++ b/openapi31/walk_schema_test.go @@ -59,7 +59,7 @@ func TestReflector_WalkRequestJSONSchemas(t *testing.T) { return nil }, - func(oc openapi.OperationContext) { + func(_ openapi.OperationContext) { doneCalled++ }, )) @@ -149,7 +149,7 @@ func TestReflector_WalkRequestJSONSchemas_jsonBody(t *testing.T) { return nil }, - func(oc openapi.OperationContext) { + func(_ openapi.OperationContext) { doneCalled++ }, )) @@ -231,7 +231,7 @@ func TestReflector_WalkResponseJSONSchemas(t *testing.T) { return nil }, - func(oc openapi.OperationContext) { + func(_ openapi.OperationContext) { doneCalled++ }, ))