Closed maticmeznar closed 6 months ago
Changing that field from *[]string
to []string
should do the trick. At the moment binder knows to only to handle pointers to common types ala string,bool, structs etc and not their slice variants.
InputData struct {
Tags []string `json:"tags" query:"tags"`
}
Anyway, I think you are overthinking here with pointers. Unitilialized slice is nil. So if that testcase would have no tags
query params this would be after bind:
Couple of articles about empty slices:
Thank you for the reply. The problem is that the struct is automatically generated by oapi-codegen and it creates a pointer unless I set the field as required in the OpenAPI spec.
I was hoping this was a bug since binding into a pointer to a slice works with JSON in the request body.
I'll take a look we probably can do something with binder.
for history sake: pointer to slice related issue https://github.com/deepmap/oapi-codegen/issues/266
Issue Description
When binding input data into a struct with a field with a pointer to a slice, *[]string for example, Bind method returns "unknown type" error.
Checklist
Expected behaviour
Successfully bind input data into the provided struct
Actual behaviour
Bind method returns "unknown type" error
Steps to reproduce
Version/commit
v4.9.1