Skip to content

Commit

Permalink
Update deps, fix lint (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Mar 1, 2024
1 parent 2112af7 commit 6f9b857
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down Expand Up @@ -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=
Expand Down
5 changes: 3 additions & 2 deletions internal/json_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
}
Expand Down
5 changes: 4 additions & 1 deletion openapi3/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion openapi3/reflect_deprecated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion openapi3/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions openapi3/walk_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestReflector_WalkRequestJSONSchemas(t *testing.T) {

return nil
},
func(oc openapi.OperationContext) {
func(_ openapi.OperationContext) {
doneCalled++
},
))
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestReflector_WalkRequestJSONSchemas_jsonBody(t *testing.T) {

return nil
},
func(oc openapi.OperationContext) {
func(_ openapi.OperationContext) {
doneCalled++
},
))
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestReflector_WalkResponseJSONSchemas(t *testing.T) {

return nil
},
func(oc openapi.OperationContext) {
func(_ openapi.OperationContext) {
doneCalled++
},
))
Expand Down
4 changes: 3 additions & 1 deletion openapi31/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ func (r *Reflector) parseParametersIn(

swg2CollectionFormat := ""
refl.ReadStringTag(field.Tag, "collectionFormat", &swg2CollectionFormat)

switch swg2CollectionFormat {
case "csv":
p.WithStyle(ParameterStyleForm).WithExplode(false)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion openapi31/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions openapi31/walk_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestReflector_WalkRequestJSONSchemas(t *testing.T) {

return nil
},
func(oc openapi.OperationContext) {
func(_ openapi.OperationContext) {
doneCalled++
},
))
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestReflector_WalkRequestJSONSchemas_jsonBody(t *testing.T) {

return nil
},
func(oc openapi.OperationContext) {
func(_ openapi.OperationContext) {
doneCalled++
},
))
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestReflector_WalkResponseJSONSchemas(t *testing.T) {

return nil
},
func(oc openapi.OperationContext) {
func(_ openapi.OperationContext) {
doneCalled++
},
))
Expand Down

0 comments on commit 6f9b857

Please sign in to comment.