forked from loafle/openapi-generator-original
[GO] Fix value formatting in url with slices (#15581)
* fix reflect value for Slice * Add test
This commit is contained in:
parent
cfc14565ae
commit
117e5118b1
@ -189,7 +189,7 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class
|
|||||||
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
||||||
s := reflect.ValueOf(t)
|
s := reflect.ValueOf(t)
|
||||||
for i := 0; i < s.Len(); i++ {
|
for i := 0; i < s.Len(); i++ {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", s.Index(i), "{{collectionFormat}}")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", s.Index(i).Interface(), "{{collectionFormat}}")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", t, "{{collectionFormat}}")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", t, "{{collectionFormat}}")
|
||||||
@ -207,7 +207,7 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class
|
|||||||
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
||||||
s := reflect.ValueOf(t)
|
s := reflect.ValueOf(t)
|
||||||
for i := 0; i < s.Len(); i++ {
|
for i := 0; i < s.Len(); i++ {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", s.Index(i), "{{collectionFormat}}")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", s.Index(i).Interface(), "{{collectionFormat}}")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", t, "{{collectionFormat}}")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "{{baseName}}", t, "{{collectionFormat}}")
|
||||||
|
@ -1944,7 +1944,7 @@ func (a *FakeAPIService) TestQueryParameterCollectionFormatExecute(r ApiTestQuer
|
|||||||
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
||||||
s := reflect.ValueOf(t)
|
s := reflect.ValueOf(t)
|
||||||
for i := 0; i < s.Len(); i++ {
|
for i := 0; i < s.Len(); i++ {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "context", s.Index(i), "multi")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "context", s.Index(i).Interface(), "multi")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "context", t, "multi")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "context", t, "multi")
|
||||||
|
@ -9,7 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
deepObjectURL = `/v2/fake/deep_object_test?inputOptions[F1]=1&inputOptions[F2]=teststring&inputOptions[F3]=null&inputOptions[id]=1&inputOptions[name]=TestCat&test_pet[F1]=1&test_pet[F2]=teststring&test_pet[F3]=null&test_pet[id]=1&test_pet[name]=Test&test_pet[photoUrls]=http%3A%2F%2Flocalhost&test_pet[tags][F1]=1&test_pet[tags][F2]=teststring&test_pet[tags][F3]=null&test_pet[tags][id]=2&test_pet[tags][name]=tag1`
|
deepObjectURL = `/v2/fake/deep_object_test?inputOptions[F1]=1&inputOptions[F2]=teststring&inputOptions[F3]=null&inputOptions[id]=1&inputOptions[name]=TestCat&test_pet[F1]=1&test_pet[F2]=teststring&test_pet[F3]=null&test_pet[id]=1&test_pet[name]=Test&test_pet[photoUrls]=http%3A%2F%2Flocalhost&test_pet[tags][F1]=1&test_pet[tags][F2]=teststring&test_pet[tags][F3]=null&test_pet[tags][id]=2&test_pet[tags][name]=tag1`
|
||||||
|
paramCollectionFormatURL = `/v2/fake/test-query-parameters?context=context&http=http&ioutil=ioutil&pipe=pipe&url=url`
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestPutBodyWithFileSchema ensures a model with the name 'File'
|
// TestPutBodyWithFileSchema ensures a model with the name 'File'
|
||||||
@ -39,12 +40,12 @@ func TestQueryDeepObject(t *testing.T) {
|
|||||||
var idTag1 = int64(2)
|
var idTag1 = int64(2)
|
||||||
var nameTag1 = "tag1"
|
var nameTag1 = "tag1"
|
||||||
req = req.TestPet(sw.Pet{
|
req = req.TestPet(sw.Pet{
|
||||||
Id: &id,
|
Id: &id,
|
||||||
Name: "Test",
|
Name: "Test",
|
||||||
PhotoUrls: []string{ "http://localhost" },
|
PhotoUrls: []string{"http://localhost"},
|
||||||
Tags: []sw.Tag{
|
Tags: []sw.Tag{
|
||||||
{
|
{
|
||||||
Id: &idTag1,
|
Id: &idTag1,
|
||||||
Name: &nameTag1,
|
Name: &nameTag1,
|
||||||
AdditionalProperties: map[string]interface{}{
|
AdditionalProperties: map[string]interface{}{
|
||||||
"F1": 1,
|
"F1": 1,
|
||||||
@ -61,7 +62,7 @@ func TestQueryDeepObject(t *testing.T) {
|
|||||||
})
|
})
|
||||||
var idcat = int64(1)
|
var idcat = int64(1)
|
||||||
req = req.InputOptions(sw.Category{
|
req = req.InputOptions(sw.Category{
|
||||||
Id: &idcat,
|
Id: &idcat,
|
||||||
Name: "TestCat",
|
Name: "TestCat",
|
||||||
AdditionalProperties: map[string]interface{}{
|
AdditionalProperties: map[string]interface{}{
|
||||||
"F1": 1,
|
"F1": 1,
|
||||||
@ -76,5 +77,22 @@ func TestQueryDeepObject(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t,
|
assert.Equal(t,
|
||||||
expectedDeepObjectURL,
|
expectedDeepObjectURL,
|
||||||
r.Request.URL.String() )
|
r.Request.URL.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestQueryParameterCollectionFormat(t *testing.T) {
|
||||||
|
req := client.FakeAPI.TestQueryParameterCollectionFormat(context.Background()).
|
||||||
|
Pipe([]string{"pipe"}).
|
||||||
|
Ioutil([]string{"ioutil"}).
|
||||||
|
Http([]string{"http"}).
|
||||||
|
Url([]string{"url"}).
|
||||||
|
Context([]string{"context"})
|
||||||
|
|
||||||
|
r, _ := req.Execute()
|
||||||
|
|
||||||
|
var expectedParamCollectionFormatURL = testScheme + "://" + testHost + paramCollectionFormatURL
|
||||||
|
|
||||||
|
assert.Equal(t,
|
||||||
|
expectedParamCollectionFormatURL,
|
||||||
|
r.Request.URL.String())
|
||||||
}
|
}
|
||||||
|
@ -1453,7 +1453,7 @@ func (a *FakeAPIService) TestEnumParametersExecute(r ApiTestEnumParametersReques
|
|||||||
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
||||||
s := reflect.ValueOf(t)
|
s := reflect.ValueOf(t)
|
||||||
for i := 0; i < s.Len(); i++ {
|
for i := 0; i < s.Len(); i++ {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "enum_query_string_array", s.Index(i), "multi")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "enum_query_string_array", s.Index(i).Interface(), "multi")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "enum_query_string_array", t, "multi")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "enum_query_string_array", t, "multi")
|
||||||
@ -2093,7 +2093,7 @@ func (a *FakeAPIService) TestQueryParameterCollectionFormatExecute(r ApiTestQuer
|
|||||||
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
||||||
s := reflect.ValueOf(t)
|
s := reflect.ValueOf(t)
|
||||||
for i := 0; i < s.Len(); i++ {
|
for i := 0; i < s.Len(); i++ {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "pipe", s.Index(i), "multi")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "pipe", s.Index(i).Interface(), "multi")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "pipe", t, "multi")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "pipe", t, "multi")
|
||||||
@ -2107,7 +2107,7 @@ func (a *FakeAPIService) TestQueryParameterCollectionFormatExecute(r ApiTestQuer
|
|||||||
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
||||||
s := reflect.ValueOf(t)
|
s := reflect.ValueOf(t)
|
||||||
for i := 0; i < s.Len(); i++ {
|
for i := 0; i < s.Len(); i++ {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "context", s.Index(i), "multi")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "context", s.Index(i).Interface(), "multi")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "context", t, "multi")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "context", t, "multi")
|
||||||
@ -2226,7 +2226,7 @@ func (a *FakeAPIService) TestUniqueItemsHeaderAndQueryParameterCollectionFormatE
|
|||||||
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
if reflect.TypeOf(t).Kind() == reflect.Slice {
|
||||||
s := reflect.ValueOf(t)
|
s := reflect.ValueOf(t)
|
||||||
for i := 0; i < s.Len(); i++ {
|
for i := 0; i < s.Len(); i++ {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "queryUnique", s.Index(i), "multi")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "queryUnique", s.Index(i).Interface(), "multi")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parameterAddToHeaderOrQuery(localVarQueryParams, "queryUnique", t, "multi")
|
parameterAddToHeaderOrQuery(localVarQueryParams, "queryUnique", t, "multi")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user