Skip to content
1 change: 1 addition & 0 deletions examples/generate/serverurls/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 14 additions & 17 deletions examples/petstore-expanded/petstore-client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions internal/test/any_of/param/param.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/labstack/echo/v4 v4.15.1
github.com/oapi-codegen/nullable v1.1.0
github.com/oapi-codegen/oapi-codegen/v2 v2.0.0-00010101000000-000000000000
github.com/oapi-codegen/runtime v1.2.0
github.com/oapi-codegen/runtime v1.3.1
github.com/oapi-codegen/testutil v1.1.0
github.com/stretchr/testify v1.11.1
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions internal/test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
github.com/oapi-codegen/nullable v1.1.0 h1:eAh8JVc5430VtYVnq00Hrbpag9PFRGWLjxR1/3KntMs=
github.com/oapi-codegen/nullable v1.1.0/go.mod h1:KUZ3vUzkmEKY90ksAmit2+5juDIhIZhfDl+0PwOQlFY=
github.com/oapi-codegen/runtime v1.2.0 h1:RvKc1CVS1QeKSNzO97FBQbSMZyQ8s6rZd+LpmzwHMP4=
github.com/oapi-codegen/runtime v1.2.0/go.mod h1:Y7ZhmmlE8ikZOmuHRRndiIm7nf3xcVv+YMweKgG1DT0=
github.com/oapi-codegen/runtime v1.3.1 h1:RgDY6J4OGQLbRXhG/Xpt3vSVqYpHQS7hN4m85+5xB9g=
github.com/oapi-codegen/runtime v1.3.1/go.mod h1:kOdeacKy7t40Rclb1je37ZLFboFxh+YLy0zaPCMibPY=
github.com/oapi-codegen/testutil v1.1.0 h1:EufqpNg43acR3qzr3ObhXmWg3Sl2kwtRnUN5GYY4d5g=
github.com/oapi-codegen/testutil v1.1.0/go.mod h1:ttCaYbHvJtHuiyeBF0tPIX+4uhEPTeizXKx28okijLw=
github.com/oasdiff/yaml v0.0.0-20260313112342-a3ea61cb4d4c h1:7ACFcSaQsrWtrH4WHHfUqE1C+f8r2uv8KGaW0jTNjus=
Expand Down
19 changes: 12 additions & 7 deletions internal/test/issues/issue-2031/prefer/issue2031.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions internal/test/issues/issue-2183/communication_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package issue2183

import (
"reflect"
"strings"
"testing"

"github.com/oapi-codegen/runtime"
)

func TestQueryCommunication(t *testing.T) {

type ParamDefinition struct {
style string
explode bool
paramName string
value any
}

testCases := []struct {
Name string
// Params defines the query parameters to serialize and deserialize.
Params []ParamDefinition
// SpecQuery is the expected raw query string per the OpenAPI spec.
SpecQuery string
}{
{
Name: "explode=false",
Params: []ParamDefinition{{
style: "form",
explode: false,
paramName: "color",
value: []string{"blue", "black", "brown"},
}},
// https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#style-examples
SpecQuery: "color=blue,black,brown",
},
{
Name: "explode=false;commas",
Params: []ParamDefinition{{
style: "form",
explode: false,
paramName: "search_term",
value: []string{"a", "b", "c,d"},
}},
SpecQuery: "search_term=a,b,c%2Cd",
},
{
Name: "explode=true",
Params: []ParamDefinition{{
style: "form",
explode: true,
paramName: "color",
value: []string{"blue", "black", "brown"},
}},
SpecQuery: "color=blue&color=black&color=brown",
},
{
Name: "multiple params",
Params: []ParamDefinition{
{
style: "form",
explode: false,
paramName: "color",
value: []string{"blue", "black"},
},
{
style: "form",
explode: false,
paramName: "size",
value: []string{"s", "m", "l"},
},
},
SpecQuery: "color=blue,black&size=s,m,l",
},
}

for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {

// rawQueryFragments collects pre-encoded query fragments from
// styled parameters, matching the generated client pattern.
var rawQueryFragments []string

for _, param := range tc.Params {

// following code equivalent to generated client (after fix)
queryFrag, err := runtime.StyleParamWithOptions(param.style, param.explode, param.paramName, param.value, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery})
if err != nil {
t.Fatal(err)
}
rawQueryFragments = append(rawQueryFragments, queryFrag)
}

rawQuery := strings.Join(rawQueryFragments, "&")
t.Logf("client query: %s", rawQuery)
if tc.SpecQuery != "" && rawQuery != tc.SpecQuery {
t.Errorf("spec query: expected %q, got %q", tc.SpecQuery, rawQuery)
}

// following code equivalent to generated server
for _, param := range tc.Params {

dest := reflect.New(reflect.TypeOf(param.value))
err := runtime.BindRawQueryParameter(param.style, param.explode, true, param.paramName, rawQuery, dest.Interface())
if err != nil {
t.Error(err)
} else if !reflect.DeepEqual(dest.Elem().Interface(), param.value) {
t.Errorf("expecting %v, got %v", param.value, dest.Elem().Interface())
}

}

})
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading