swag icon indicating copy to clipboard operation
swag copied to clipboard

is there a way to set example for map

Open axiaoxin opened this issue 5 years ago • 4 comments

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

axiaoxin avatar Mar 20 '19 02:03 axiaoxin

interface{} is diffcult to parse. Do you have any idea?

https://github.com/swaggo/swag/blob/266aebcda91591bae22ba0efe7f4c919434a88b3/parser.go#L1006-L1039

pei0804 avatar Mar 20 '19 12:03 pei0804

@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 avatar Feb 15 '21 23:02 adw1n

@adw1n How to define example value for { CustomType map[string][]string json:"map_data" example:? }

re-tunk avatar Mar 13 '23 14:03 re-tunk

@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{}.

ealyn avatar Feb 26 '24 06:02 ealyn