Skip to content
Merged
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 gen/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func fixEqualResponses(ctx *genctx, op *ir.Operation) error {
}

var candidates []candidate
for i := 0; i < len(statusCodes); i++ {
for i := range statusCodes {
lcode := statusCodes[i]
for j := i; j < len(statusCodes); j++ {
rcode := statusCodes[j]
Expand Down
6 changes: 2 additions & 4 deletions gen/gen_contents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gen

import (
"fmt"
"maps"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -40,16 +41,13 @@ func Test_filterMostSpecific(t *testing.T) {
{list("application/*", "text/html"), list("application/*", "text/html"), false},
}
for i, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
a := require.New(t)
core, logs := observer.New(zapcore.DebugLevel)

// Make a copy of the testdata to avoid modifying it.
contents := map[string]*openapi.MediaType{}
for k, v := range tt.contents {
contents[k] = v
}
maps.Copy(contents, tt.contents)

err := filterMostSpecific(contents, zap.New(core))
if tt.wantErr {
Expand Down
4 changes: 2 additions & 2 deletions gen/gen_equality_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ func TestWriteArrayComparison(t *testing.T) {
}

// Verify proper indentation
lines := strings.Split(output, "\n")
for _, line := range lines {
lines := strings.SplitSeq(output, "\n")
for line := range lines {
if line != "" {
require.True(t, strings.HasPrefix(line, tt.indent),
"line should start with indent %q: %s", tt.indent, line)
Expand Down
8 changes: 2 additions & 6 deletions gen/ir/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ir

import (
"fmt"
"slices"
"strings"

"github.com/ogen-go/ogen/internal/naming"
Expand Down Expand Up @@ -305,12 +306,7 @@ func (t *Type) Format() bool {
}

func (t *Type) Is(vs ...Kind) bool {
for _, v := range vs {
if t.Kind == v {
return true
}
}
return false
return slices.Contains(vs, t.Kind)
}

// Go returns valid Go type for this Type.
Expand Down
2 changes: 1 addition & 1 deletion gen/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (n namer) valueMappingNameGen(
}

nextStrategy:
for strategy := pascalName; strategy < _lastStrategy; strategy++ {
for strategy := range _lastStrategy {
if !allowSpecial && strategy == pascalSpecialName {
continue nextStrategy
}
Expand Down
1 change: 0 additions & 1 deletion gen/names_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func Test_cleanRef(t *testing.T) {
{"user.json", "user"},
}
for i, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("Test%d", i), func(t *testing.T) {
u, err := url.Parse(tt.ref)
require.NoError(t, err)
Expand Down
1 change: 0 additions & 1 deletion gen/schema_gen_sum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func Test_mergeEnums(t *testing.T) {
{[]any{1, 2, 3}, []any{4, 5, 6}, nil, true},
}
for i, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
a := require.New(t)

Expand Down
1 change: 0 additions & 1 deletion gen/schema_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ func TestGenerate(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("Test %s", tt.name), func(t *testing.T) {
a := require.New(t)

Expand Down
20 changes: 5 additions & 15 deletions gen/tstorage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gen

import (
"maps"
"sort"
"strings"

Expand Down Expand Up @@ -218,21 +219,10 @@ func (s *tstorage) merge(other *tstorage) error {
s.types[t.Name] = t
}

for name, t := range other.types {
s.types[name] = t
}

for name, t := range other.responses {
s.responses[name] = t
}

for name, t := range other.wtypes {
s.wtypes[name] = t
}

for name, t := range other.parameters {
s.parameters[name] = t
}
maps.Copy(s.types, other.types)
maps.Copy(s.responses, other.responses)
maps.Copy(s.wtypes, other.wtypes)
maps.Copy(s.parameters, other.parameters)

return nil
}
1 change: 0 additions & 1 deletion gen_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func BenchmarkGenerator(b *testing.B) {
"manga.json", // Tiny (<1kLOC)
}
for _, file := range files {
file := file
name := strings.TrimSuffix(file, ".json")
b.Run(name, func(b *testing.B) {
a := require.New(b)
Expand Down
3 changes: 1 addition & 2 deletions http/form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestParseForm(t *testing.T) {
{"%", url.Values{}, true},
}
for i, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
a := require.New(t)
got, err := ParseForm(&http.Request{
Expand Down Expand Up @@ -90,7 +89,7 @@ func BenchmarkParseForm(b *testing.B) {
// ~12KB of form data.
body := func() string {
var sb strings.Builder
for i := 0; i < 1024; i++ {
for i := range 1024 {
if i > 0 {
sb.WriteString("&")
}
Expand Down
1 change: 0 additions & 1 deletion http/match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func TestMatchContentType(t *testing.T) {
{"text/*", "application/json", false},
}
for i, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
require.Equal(t, tt.want, MatchContentType(tt.pattern, tt.value))
})
Expand Down
4 changes: 0 additions & 4 deletions internal/integration/any_of_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func TestValidateSum(t *testing.T) {
false,
},
} {
tc := tc
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
m := api.JaegerAnyOf{}
require.NoError(t, m.Decode(jx.DecodeStr(tc.Input)))
Expand All @@ -55,7 +54,6 @@ func TestAnyOf(t *testing.T) {
{`null`, "", true},
} {
// Make range value copy to prevent data races.
tc := tc
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
checker := require.NoError
if tc.Error {
Expand All @@ -78,7 +76,6 @@ func TestAnyOf(t *testing.T) {
{`null`, "", true},
} {
// Make range value copy to prevent data races.
tc := tc
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
checker := require.NoError
if tc.Error {
Expand Down Expand Up @@ -112,7 +109,6 @@ func TestAnyOf(t *testing.T) {
{`null`, zero, true},
} {
// Make range value copy to prevent data races.
tc := tc
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
checker := require.NoError
if tc.Error {
Expand Down
1 change: 0 additions & 1 deletion internal/integration/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func TestDefault(t *testing.T) {
},
} {
// Make range value copy to prevent data races.
tc := tc
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
r := api.DefaultTest{}
if err := r.Decode(jx.DecodeStr(tc.Input)); tc.Error {
Expand Down
3 changes: 0 additions & 3 deletions internal/integration/discriminator_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func TestDiscriminatorMapping(t *testing.T) {
{`{"petType": "unknown", "name": "Test"}`, "", true},
{`{"name": "Test"}`, "", true}, // missing discriminator
} {
tc := tc
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
checker := require.NoError
if tc.Error {
Expand Down Expand Up @@ -131,7 +130,6 @@ func TestDiscriminatorMapping(t *testing.T) {
{`{"vehicleType": "Motorcycle", "make": "Honda", "model": "CBR"}`, api.MotorcycleVehicle, false},
{`{"vehicleType": "Truck", "make": "Ford"}`, "", true}, // Unknown type
} {
tc := tc
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
checker := require.NoError
if tc.Error {
Expand Down Expand Up @@ -164,7 +162,6 @@ func TestDiscriminatorMapping(t *testing.T) {
// Error cases
{`{"notificationType": "unknown", "message": "test"}`, "", true},
} {
tc := tc
t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) {
checker := require.NoError
if tc.Error {
Expand Down
1 change: 0 additions & 1 deletion internal/integration/form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ func TestURIEncodingE2E(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
a := assert.New(t)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
Expand Down
1 change: 0 additions & 1 deletion internal/integration/json_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func TestExampleJSON(t *testing.T) {
},
} {
// Make range value copy to prevent data races.
tc := tc
t.Run(tc.Name, func(t *testing.T) {
encode := json.Encode(tc.Value)
t.Logf("%s", encode)
Expand Down
Loading
Loading