增加全局安全类参数解析
This commit is contained in:
parent
e70634a318
commit
368fb02efc
@ -57,7 +57,7 @@ func GetDataType(docParamType string, formatType string) consts.DataType {
|
||||
return consts.DataTypeInt
|
||||
}
|
||||
return consts.DataTypeUint
|
||||
case "string":
|
||||
case "string", "apikey":
|
||||
return consts.DataTypeString
|
||||
case "object":
|
||||
return consts.DataTypeMapStrAny
|
||||
|
@ -19,6 +19,7 @@ type DocParseResult struct {
|
||||
Title string `json:"title"` // 标题
|
||||
Description string `json:"description"` // 描述
|
||||
UriList []*UriBaseConfig `json:"uri_list"` // 接口列表
|
||||
GlobalSecurityParamList []*ParamConfig `json:"global_security_param_list"` // 全局安全类参数配置
|
||||
}
|
||||
|
||||
// UriBaseConfig 添加接口时的基础配置
|
||||
|
@ -109,6 +109,7 @@ type Swagger struct {
|
||||
Paths map[string]map[string]*SwaggerPathConfig `json:"paths"` // 接口列表 : 接口 => 请求方法 => 请求配置
|
||||
Definitions map[string]*SwaggerDefinition `json:"definitions"` // 数据定义
|
||||
Responses map[string]*SwaggerPathConfigResponse `json:"responses"` // 响应结构列表
|
||||
SecurityDefinitions map[string]*SwaggerPathConfigParameter `json:"securityDefinitions"` // 安全选项
|
||||
}
|
||||
|
||||
// SwaggerInput ...
|
||||
|
21
swagger.go
21
swagger.go
@ -35,13 +35,34 @@ func ParseSwagger2(docContent []byte) (*define.DocParseResult, error) {
|
||||
Title: swaggerDoc.Info.Title,
|
||||
Description: swaggerDoc.Info.Description,
|
||||
UriList: make([]*define.UriBaseConfig, 0),
|
||||
GlobalSecurityParamList: make([]*define.ParamConfig, 0),
|
||||
}
|
||||
if docResult.UriList, err = buildUriList(&swaggerDoc); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
docResult.GlobalSecurityParamList = buildSwagger2GlobalSecurityParamList(&swaggerDoc)
|
||||
return docResult, nil
|
||||
}
|
||||
|
||||
// buildSwagger2GlobalSecurityParamList 构建全局安全类参数
|
||||
func buildSwagger2GlobalSecurityParamList(swaggerDoc *define.Swagger) []*define.ParamConfig {
|
||||
result := make([]*define.ParamConfig, 0)
|
||||
for paramName, paramConfig := range swaggerDoc.SecurityDefinitions {
|
||||
if len(paramConfig.In) == 0 {
|
||||
continue
|
||||
}
|
||||
result = append(result, &define.ParamConfig{
|
||||
Location: GetParamLocation(paramConfig.In).String(),
|
||||
Path: paramName,
|
||||
Type: GetDataType(paramConfig.Type, "").String(),
|
||||
Title: paramName,
|
||||
Description: paramConfig.Description,
|
||||
Required: false,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 解析uri列表
|
||||
func buildUriList(swaggerDoc *define.Swagger) ([]*define.UriBaseConfig, error) {
|
||||
uriList := make([]*define.UriBaseConfig, 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user