swag
swag copied to clipboard
is there a way to set example for map
there is a struct like
type RunBody struct {
SecretID string `json:"secretID" binding:"required" example:"apidocs"`
FuncName string `json:"funcName" binding:"required" example:"default/ZNSNotify"`
FuncArgs map[string]interface{} `json:"funcArgs" binding:"" example:""`
}
how to set the example tag for FuncArgs field which is a map? when I set value in example tag, swag init will raise error:
panic: object is unsupported type in example value
interface{}
is diffcult to parse.
Do you have any idea?
https://github.com/swaggo/swag/blob/266aebcda91591bae22ba0efe7f4c919434a88b3/parser.go#L1006-L1039
@axiaoxin recently an example was added that hopefully answers your question: https://github.com/swaggo/swag/blob/3d90fc0a5c6ef9566df81fe34425b0b35b0f651e/example/object-map-example/controller/response.go#L5
@adw1n How to define example value for
{ CustomType map[string][]string
json:"map_data" example:? }
@axiaoxin recently an example was added that hopefully answers your question:
https://github.com/swaggo/swag/blob/3d90fc0a5c6ef9566df81fe34425b0b35b0f651e/example/object-map-example/controller/response.go#L5
While using goswagger API client code generator, swaggertype:"object,string"
will generated with map[string]string
, and swaggertype:"object,object"
will be map[string]interface{}
.