文档生成支持即系url中的参数
This commit is contained in:
21
generate.go
21
generate.go
@ -208,7 +208,7 @@ func (g *Generate) AddApiFromInAndOut(paramType reflect.Type, resultType reflect
|
||||
Description: baseCfg.Description,
|
||||
ExternalDocs: nil,
|
||||
OperationID: baseCfg.Method + "-" + defaultPkgPath,
|
||||
Parameters: nil,
|
||||
Parameters: make([]*define.PathConfigParameter, 0),
|
||||
RequestBody: &define.RequestBody{
|
||||
Required: true,
|
||||
Description: "",
|
||||
@ -225,6 +225,25 @@ func (g *Generate) AddApiFromInAndOut(paramType reflect.Type, resultType reflect
|
||||
Security: nil,
|
||||
Servers: nil,
|
||||
}
|
||||
// 解析绑定在url中的参数
|
||||
if paramList := define.UriParamRegexp.FindAllString(baseCfg.Uri, -1); len(paramList) > 0 {
|
||||
for _, param := range paramList {
|
||||
param = strings.TrimPrefix(param, "{")
|
||||
param = strings.TrimSuffix(param, "}")
|
||||
cfg.Parameters = append(cfg.Parameters, &define.PathConfigParameter{
|
||||
Name: param,
|
||||
In: consts.SwaggerParameterInPath,
|
||||
Description: param,
|
||||
Required: true,
|
||||
Deprecated: false,
|
||||
Schema: &define.Schema{
|
||||
Type: consts.SwaggerDataTypeString,
|
||||
Format: consts.DataTypeString.String(),
|
||||
},
|
||||
AllowEmptyValue: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
for _, itemType := range baseCfg.ContentType {
|
||||
cfg.RequestBody.Content[itemType] = &define.Media{
|
||||
Schema: &define.Schema{
|
||||
|
Reference in New Issue
Block a user