参数 + 返回值支持自动展开一层数组
This commit is contained in:
47
common.go
47
common.go
@ -74,7 +74,7 @@ func GetDataType(docParamType string, formatType string) consts.DataType {
|
||||
return consts.DataTypeSliceAny
|
||||
}
|
||||
default:
|
||||
return consts.DataTypeMapStrAny
|
||||
return consts.DataTypeAny
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,3 +120,48 @@ func GetSuccessResponseConfig(resultConfig map[string]*define.SwaggerPathConfigR
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DataTypeIsArray 判断数据类型是否为数组
|
||||
func DataTypeIsArray(docDataType string) bool {
|
||||
return strings.ToLower(docDataType) == "array"
|
||||
}
|
||||
|
||||
// ExpandArrayParam 展开详细的数组配置
|
||||
func ExpandArrayParam(swaggerDoc *define.Swagger, ref string, rootPath string) []*define.ParamConfig {
|
||||
pathPrefix := ""
|
||||
if len(rootPath) > 0 {
|
||||
pathPrefix = rootPath + "."
|
||||
}
|
||||
res := make([]*define.ParamConfig, 0)
|
||||
for itemKey, itemConfig := range swaggerDoc.Definitions[GetRealDefinitionsKey(ref)].Properties {
|
||||
res = append(res, &define.ParamConfig{
|
||||
Location: consts.RequestDataLocationBody.String(),
|
||||
Path: pathPrefix + "{{#idx#}}." + itemKey,
|
||||
Type: GetDataType(itemConfig.Type, "").String(),
|
||||
Title: pathPrefix + itemKey,
|
||||
Description: pathPrefix + itemKey,
|
||||
Required: false,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// ExpandArrayResult 展开返回值配置
|
||||
func ExpandArrayResult(swaggerDoc *define.Swagger, ref string, rootPath string) []*define.ResultConfig {
|
||||
pathPrefix := ""
|
||||
if len(rootPath) > 0 && rootPath != consts.ResponseDataLocationBodyRoot.String() {
|
||||
pathPrefix = rootPath + "."
|
||||
}
|
||||
ref = GetRealDefinitionsKey(ref)
|
||||
res := make([]*define.ResultConfig, 0)
|
||||
for itemKey, itemConfig := range swaggerDoc.Definitions[ref].Properties {
|
||||
res = append(res, &define.ResultConfig{
|
||||
Location: consts.ResponseDataLocationBody.String(),
|
||||
Path: pathPrefix + "{{#idx#}}." + itemKey,
|
||||
Type: GetDataType(itemConfig.Type, "").String(),
|
||||
Title: pathPrefix + itemKey,
|
||||
Description: pathPrefix + itemKey,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
Reference in New Issue
Block a user