I am trying to use go-swagger to generate my service swagger spec
I have a response struct like
type MyResponse struct {
// example: ["This", "Is", "A", "Test"]
MyTestArray MyArray `json:"MyTestArray"`
}
type MyArray []string
So, MyArray is just a typedef for []string, but when I try to use // example: the field, it is not working because MyArray is a ref model. When I use []string directly in the struct, it is working. Is there a way to add example for ref array model with go-swagger?
This problem is not really related to go-swagger, you just need to type and format your array into JSON to be compatible with go-swagger. One way to do this is to create a separate model definition for your
MyArray(and its schema -MyArraySchema) and then reference it in yourMyresponsestruct (and its schema -MyResponseSchema). Like this (run in Playground):The output of playground code: