Skip to content

Commit 3a5ddcd

Browse files
authored
refactor: apply modernize fixes (#1195)
1 parent 742704d commit 3a5ddcd

21 files changed

Lines changed: 40 additions & 77 deletions

‎.github/workflows/go.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656
- run: go vet ./...
5757
- run: git --no-pager diff --exit-code
5858

59+
- run: go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -test -diff -fix -omitzero=false ./...
60+
5961
- run: go fmt ./...
6062
- run: git --no-pager diff --exit-code
6163

‎openapi2conv/openapi2_conv.go‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ func ToV3WithLoader(doc2 *openapi2.T, loader *openapi3.Loader, location *url.URL
9494
}
9595
}
9696

97-
for key, schema := range ToV3Schemas(doc2.Definitions) {
98-
doc3.Components.Schemas[key] = schema
99-
}
97+
maps.Copy(doc3.Components.Schemas, ToV3Schemas(doc2.Definitions))
10098

10199
if m := doc2.SecurityDefinitions; len(m) != 0 {
102100
doc3SecuritySchemes := make(map[string]*openapi3.SecuritySchemeRef)
@@ -178,9 +176,7 @@ func ToV3Operation(components *openapi3.Components, pathItem *openapi2.PathItem,
178176
case v3RequestBody != nil:
179177
reqBodies = append(reqBodies, v3RequestBody)
180178
case v3SchemaMap != nil:
181-
for key, v3Schema := range v3SchemaMap {
182-
formDataSchemas[key] = v3Schema
183-
}
179+
maps.Copy(formDataSchemas, v3SchemaMap)
184180
default:
185181
doc3.Parameters = append(doc3.Parameters, v3Parameter)
186182
}

‎openapi3/example_validation_test.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ func TestExamplesSchemaValidation(t *testing.T) {
216216
t.Parallel()
217217

218218
for _, testOption := range testOptions {
219-
testOption := testOption
220219
t.Run(testOption.name, func(t *testing.T) {
221220
t.Parallel()
222221
for _, tc := range testCases {
@@ -430,7 +429,6 @@ func TestExampleObjectValidation(t *testing.T) {
430429
t.Parallel()
431430

432431
for _, testOption := range testOptions {
433-
testOption := testOption
434432
t.Run(testOption.name, func(t *testing.T) {
435433
t.Parallel()
436434
for _, tc := range testCases {

‎openapi3/helpers.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func ReferencesComponentInRootDocument(doc *T, ref ComponentRef) (string, bool)
212212

213213
var components map[string]ComponentRef
214214

215-
componentRefType := reflect.TypeOf(new(ComponentRef)).Elem()
215+
componentRefType := reflect.TypeFor[ComponentRef]()
216216
if t := reflect.TypeOf(collection); t.Kind() == reflect.Map &&
217217
t.Key().Kind() == reflect.String &&
218218
t.Elem().AssignableTo(componentRefType) {

‎openapi3/issue657_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ components:
6767
}
6868

6969
for _, test := range tests {
70-
test := test
7170
t.Run(test.name, func(t *testing.T) {
7271
t.Parallel()
7372

‎openapi3/issue689_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ func TestIssue689(t *testing.T) {
9797
}
9898

9999
for _, test := range tests {
100-
test := test
101100
t.Run(test.name, func(t *testing.T) {
102101
t.Parallel()
103102
err := test.schema.VisitJSON(test.value, test.opts...)

‎openapi3/issue767_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func TestIssue767(t *testing.T) {
8080
}
8181

8282
for _, test := range tests {
83-
test := test
8483
t.Run(test.name, func(t *testing.T) {
8584
t.Parallel()
8685
err := test.schema.VisitJSON(test.value, test.opts...)

‎openapi3/load_cicular_ref_with_external_file_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build go1.16
2-
// +build go1.16
32

43
package openapi3_test
54

‎openapi3/load_with_go_embed_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build go1.16
2-
// +build go1.16
32

43
package openapi3_test
54

‎openapi3/loader.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func (loader *Loader) resolveComponent(doc *T, ref string, path *url.URL, resolv
500500
reflect.ValueOf(resolved).Elem().Set(reflect.ValueOf(cursor).Elem())
501501
return componentDoc, componentPath, nil
502502

503-
case reflect.TypeOf(cursor) == reflect.TypeOf(map[string]any{}):
503+
case reflect.TypeOf(cursor) == reflect.TypeFor[map[string]any]():
504504
codec := func(got, expect any) error {
505505
enc, err := json.Marshal(got)
506506
if err != nil {
@@ -578,7 +578,7 @@ func drillIntoField(cursor any, fieldName string) (any, error) {
578578
for i := range val.NumField() {
579579
hasFields = true
580580
if yamlTag := val.Type().Field(i).Tag.Get("yaml"); yamlTag != "-" {
581-
if tagName := strings.Split(yamlTag, ",")[0]; tagName != "" {
581+
if tagName, _, _ := strings.Cut(yamlTag, ","); tagName != "" {
582582
if fieldName == tagName {
583583
return val.Field(i).Interface(), nil
584584
}

0 commit comments

Comments
 (0)