gin-swagger
gin-swagger copied to clipboard
[DEPRECATED]
Gin Swagger
Pick Swagger from code which wrote by gin
Rules
Path & Method
- [x] pick path and method from
*gin.Engineor*gin.RouterGroup - [x] path of
*gin.RouterGroupwill be prefix of path of*gin.Engine - [x] only support
GETPOSTPUTPATCHHEADDELETEOPTIONS - [x] gin-style router will be convert to swagger-style,
:id=>{id}, double check with parameter definitions, undefined path parameter will be use0instead.
Operation
- [x] pick operation in scope of gin-handler (not support anonymous func, we need func name as operationId)
- [x] name of gin-handler will be
operationId - [x] only support single gin-handler.
Parameter
- [x] struct type of variable
reqorrequestin scope of gin-handler will be used for picking parameters. - [x] tag
inof struct field must be defined, expect body parameter, but need to use fieldNameBody. - [x] tag
jsonwill be used asname - [x] struct type of anonymous struct field will be picked too.
- [x] others will be same as Schema
Response
- [x]
statuswill be picked by gin-context render method. - [x]
c.JSONwill set schema by type of return value and with produceapplication/json - [x]
c.HTMLwill with produceapplication/html - [x]
c.Rediectc.Dataandc.Renderwill be no responce
Schema
- [x] only support
json - [x] basic type will be translated, but
json:"key,string"will force converting tostring - [x] tag
defaultwill be set the default value, if it not exists, we will set fieldrequired - [x] tag
validatewill be set common validations, for example,validate:"@int[0,100)"will be{ "minimum": 0, "exclusiveMinimum": true, "maximum": 100 } - [x] anonymous struct field will be used with
allOf
Enums
-
[x] pick
enumfrom commentedswagger:enumtype -
[x] string
enumfrom const
// swagger:enum State
type State int
const (
STATE_UNKNOWN = iota
STATE__ONE // one
STATE__TWO // two
STATE__THREE // three
)
will be
{
"enum": [
"ONE",
"TWO",
"THREE"
],
"x-enum-labels": [
"one",
"two",
"three"
],
"x-enum-type": "State"
}
- [x]
validate:"@string{ONE,TWO}"orvalidate:"@int{1,2}"will be used for partial pick enum values;
String format
- [x] pick format from commented
swagger:strfmt <format-name>type
Definitions
- [x] only collect the named complex type, like struct type, slice type, map type