upgrade: update wrapper
This commit is contained in:
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
apiDocDefine "git.zhangdeman.cn/zhangdeman/api-doc/define"
|
apiDocDefine "git.zhangdeman.cn/zhangdeman/api-doc/define"
|
||||||
"git.zhangdeman.cn/zhangdeman/consts"
|
"git.zhangdeman.cn/zhangdeman/consts"
|
||||||
"git.zhangdeman.cn/zhangdeman/wrapper"
|
"git.zhangdeman.cn/zhangdeman/wrapper/op_any"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandleOpenapiDocRes ...
|
// HandleOpenapiDocRes ...
|
||||||
@ -200,7 +200,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayRequest(importUriConfig *apiDocD
|
|||||||
if len(parentPath) > 0 {
|
if len(parentPath) > 0 {
|
||||||
currentPropertyName = parentPath + "." + currentPropertyName
|
currentPropertyName = parentPath + "." + currentPropertyName
|
||||||
}
|
}
|
||||||
defaultValue := wrapper.AnyDataType(currentProperty.Default).ToString().Value()
|
defaultValue := op_any.AnyDataType(currentProperty.Default).ToString()
|
||||||
// 基础数据类型
|
// 基础数据类型
|
||||||
if len(currentProperty.Properties) == 0 && currentProperty.Type != consts.SwaggerDataTypeObject && currentProperty.Type != consts.SwaggerDataTypeArray && len(currentProperty.Ref) == 0 {
|
if len(currentProperty.Properties) == 0 && currentProperty.Type != consts.SwaggerDataTypeObject && currentProperty.Type != consts.SwaggerDataTypeArray && len(currentProperty.Ref) == 0 {
|
||||||
importUriConfig.ParamList = append(importUriConfig.ParamList, &apiDocDefine.ApiParamItem{
|
importUriConfig.ParamList = append(importUriConfig.ParamList, &apiDocDefine.ApiParamItem{
|
||||||
@ -432,7 +432,7 @@ func (hod *handleOpenapiDoc) expendObjectOrArrayPath(importUriConfig *apiDocDefi
|
|||||||
if len(parentPath) > 0 {
|
if len(parentPath) > 0 {
|
||||||
currentPropertyName = parentPath + "." + currentPropertyName
|
currentPropertyName = parentPath + "." + currentPropertyName
|
||||||
}
|
}
|
||||||
defaultValue := wrapper.AnyDataType(currentProperty.Default).ToString().Value()
|
defaultValue := op_any.AnyDataType(currentProperty.Default).ToString()
|
||||||
// 基础数据类型
|
// 基础数据类型
|
||||||
if len(currentProperty.Properties) == 0 && currentProperty.Type != consts.SwaggerDataTypeObject && currentProperty.Type != consts.SwaggerDataTypeArray && len(currentProperty.Ref) == 0 {
|
if len(currentProperty.Properties) == 0 && currentProperty.Type != consts.SwaggerDataTypeObject && currentProperty.Type != consts.SwaggerDataTypeArray && len(currentProperty.Ref) == 0 {
|
||||||
importUriConfig.ResultList = append(importUriConfig.ResultList, &apiDocDefine.ApiResultItem{
|
importUriConfig.ResultList = append(importUriConfig.ResultList, &apiDocDefine.ApiResultItem{
|
||||||
|
@ -15,7 +15,9 @@ import (
|
|||||||
"git.zhangdeman.cn/zhangdeman/api-doc/enums"
|
"git.zhangdeman.cn/zhangdeman/api-doc/enums"
|
||||||
"git.zhangdeman.cn/zhangdeman/api-doc/util"
|
"git.zhangdeman.cn/zhangdeman/api-doc/util"
|
||||||
"git.zhangdeman.cn/zhangdeman/consts"
|
"git.zhangdeman.cn/zhangdeman/consts"
|
||||||
"git.zhangdeman.cn/zhangdeman/wrapper"
|
"git.zhangdeman.cn/zhangdeman/wrapper/op_array"
|
||||||
|
"git.zhangdeman.cn/zhangdeman/wrapper/op_string"
|
||||||
|
"git.zhangdeman.cn/zhangdeman/wrapper/op_ternary"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Generate 生成文档
|
// Generate 生成文档
|
||||||
@ -49,20 +51,20 @@ func formatDocConfig(docConfig *define.SwaggerInput) {
|
|||||||
consts.SchemeHTTP.String(),
|
consts.SchemeHTTP.String(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
docConfig.Host = wrapper.String(docConfig.Host).ReplaceChar(map[string]string{
|
docConfig.Host = op_string.ReplaceChar(docConfig.Host, map[string]string{
|
||||||
consts.SchemeHTTP.String() + "://": "",
|
consts.SchemeHTTP.String() + "://": "",
|
||||||
consts.SchemeHTTPS.String() + "://": "",
|
consts.SchemeHTTPS.String() + "://": "",
|
||||||
}).Value()
|
})
|
||||||
for _, itemPath := range docConfig.PathConfigList {
|
for _, itemPath := range docConfig.PathConfigList {
|
||||||
// 默认请求类型 application/json
|
// 默认请求类型 application/json
|
||||||
itemPath.ContentType = strings.TrimSpace(itemPath.ContentType)
|
itemPath.ContentType = strings.TrimSpace(itemPath.ContentType)
|
||||||
itemPath.ContentType = wrapper.TernaryOperator.String(len(itemPath.ContentType) == 0, consts.MimeTypeJson, wrapper.String(itemPath.ContentType)).Value()
|
itemPath.ContentType = op_ternary.BaseType[string](len(itemPath.ContentType) == 0, consts.MimeTypeJson, itemPath.ContentType)
|
||||||
// 默认post请求
|
// 默认post请求
|
||||||
itemPath.Method = strings.TrimSpace(itemPath.Method)
|
itemPath.Method = strings.TrimSpace(itemPath.Method)
|
||||||
itemPath.Method = wrapper.TernaryOperator.String(len(itemPath.ContentType) == 0, wrapper.String(strings.ToLower(http.MethodPost)), wrapper.String(strings.ToLower(itemPath.Method))).Value()
|
itemPath.Method = op_ternary.BaseType[string](len(itemPath.ContentType) == 0, strings.ToLower(http.MethodPost), strings.ToLower(itemPath.Method))
|
||||||
// 默认summary
|
// 默认summary
|
||||||
itemPath.Summary = strings.TrimSpace(itemPath.Summary)
|
itemPath.Summary = strings.TrimSpace(itemPath.Summary)
|
||||||
itemPath.Summary = wrapper.TernaryOperator.String(len(itemPath.Summary) == 0, wrapper.String("接口 : "+itemPath.Uri), wrapper.String(itemPath.Summary)).Value()
|
itemPath.Summary = op_ternary.BaseType[string](len(itemPath.Summary) == 0, "接口 : "+itemPath.Uri, itemPath.Summary)
|
||||||
// 默认标签
|
// 默认标签
|
||||||
if len(itemPath.TagList) == 0 {
|
if len(itemPath.TagList) == 0 {
|
||||||
itemPath.TagList = []string{"未分组"}
|
itemPath.TagList = []string{"未分组"}
|
||||||
@ -70,25 +72,25 @@ func formatDocConfig(docConfig *define.SwaggerInput) {
|
|||||||
for _, itemParam := range itemPath.ParameterList {
|
for _, itemParam := range itemPath.ParameterList {
|
||||||
// 填充默认参数位置
|
// 填充默认参数位置
|
||||||
itemParam.In = strings.TrimSpace(itemParam.In)
|
itemParam.In = strings.TrimSpace(itemParam.In)
|
||||||
itemParam.In = wrapper.TernaryOperator.String(len(itemParam.In) == 0, wrapper.String(util.GetParameterDefaultLocation(itemPath.Method)), wrapper.String(itemParam.In)).Value()
|
itemParam.In = op_ternary.BaseType[string](len(itemParam.In) == 0, util.GetParameterDefaultLocation(itemPath.Method), itemParam.In)
|
||||||
|
|
||||||
// 参数类型没填, 按照字符串处理
|
// 参数类型没填, 按照字符串处理
|
||||||
itemParam.Type = strings.TrimSpace(itemParam.Type)
|
itemParam.Type = strings.TrimSpace(itemParam.Type)
|
||||||
itemParam.Type = wrapper.TernaryOperator.String(len(itemParam.Type) == 0, wrapper.String(itemParam.Type), wrapper.String(itemParam.Type)).Value()
|
itemParam.Type = op_ternary.BaseType[string](len(itemParam.Type) == 0, itemParam.Type, itemParam.Type)
|
||||||
|
|
||||||
// 参数描述
|
// 参数描述
|
||||||
itemParam.Description = strings.TrimSpace(itemParam.Description)
|
itemParam.Description = strings.TrimSpace(itemParam.Description)
|
||||||
itemParam.Description = wrapper.TernaryOperator.String(len(itemParam.Description) == 0, wrapper.String(itemParam.Type+" : "+itemParam.Name), wrapper.String(itemParam.Description)).Value()
|
itemParam.Description = op_ternary.BaseType[string](len(itemParam.Description) == 0, itemParam.Type+" : "+itemParam.Name, itemParam.Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, itemResponseConfig := range itemPath.ResponseList {
|
for _, itemResponseConfig := range itemPath.ResponseList {
|
||||||
for _, itemResponse := range itemResponseConfig.List {
|
for _, itemResponse := range itemResponseConfig.List {
|
||||||
// 默认返回数据类型
|
// 默认返回数据类型
|
||||||
itemResponse.Type = strings.TrimSpace(itemResponse.Type)
|
itemResponse.Type = strings.TrimSpace(itemResponse.Type)
|
||||||
itemResponse.Type = wrapper.TernaryOperator.String(len(itemResponse.Type) == 0, wrapper.String(consts.DataTypeString), wrapper.String(itemResponse.Type)).Value()
|
itemResponse.Type = op_ternary.BaseType[string](len(itemResponse.Type) == 0, consts.DataTypeString.String(), itemResponse.Type)
|
||||||
// 填充默认描述
|
// 填充默认描述
|
||||||
itemResponse.Description = strings.TrimSpace(itemResponse.Description)
|
itemResponse.Description = strings.TrimSpace(itemResponse.Description)
|
||||||
itemResponse.Description = wrapper.TernaryOperator.String(len(itemResponse.Description) == 0, wrapper.String(itemResponse.Type+" : "+itemResponse.Field), wrapper.String(itemResponse.Description)).Value()
|
itemResponse.Description = op_ternary.BaseType[string](len(itemResponse.Description) == 0, itemResponse.Type+" : "+itemResponse.Field, itemResponse.Description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,8 +149,8 @@ func generatePathParameterConfig(swaggerInfo *define.Swagger, pathConfig *define
|
|||||||
if _, exist := hasDealTable[realParamName]; !exist {
|
if _, exist := hasDealTable[realParamName]; !exist {
|
||||||
hasDealTable[realParamName] = true
|
hasDealTable[realParamName] = true
|
||||||
generateParam := &define.SwaggerPathConfigParameter{
|
generateParam := &define.SwaggerPathConfigParameter{
|
||||||
Type: wrapper.TernaryOperator.String(realParamName == "jsonBody", "", wrapper.String(itemParamInput.Type)).Value(),
|
Type: op_ternary.BaseType[string](realParamName == "jsonBody", "", itemParamInput.Type),
|
||||||
Description: wrapper.TernaryOperator.String(realParamName == "jsonBody", "参数结构", wrapper.String(itemParamInput.Description)).Value(),
|
Description: op_ternary.BaseType[string](realParamName == "jsonBody", "参数结构", itemParamInput.Description),
|
||||||
Name: realParamName,
|
Name: realParamName,
|
||||||
In: itemParamInput.In,
|
In: itemParamInput.In,
|
||||||
Required: itemParamInput.Required,
|
Required: itemParamInput.Required,
|
||||||
@ -257,7 +259,7 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
|||||||
storageSubPath += ".item"
|
storageSubPath += ".item"
|
||||||
}
|
}
|
||||||
initAnyDefinition(swaggerInfo, storageSubPath)
|
initAnyDefinition(swaggerInfo, storageSubPath)
|
||||||
swaggerInfo.Definitions[storageSubPath].Type = wrapper.TernaryOperator.String(strings.HasSuffix(parentPath, "[]"), "array", consts.SwaggerDataTypeObject).Value()
|
swaggerInfo.Definitions[storageSubPath].Type = op_ternary.BaseType[string](strings.HasSuffix(parentPath, "[]"), "array", consts.SwaggerDataTypeObject)
|
||||||
// 设置字段必传
|
// 设置字段必传
|
||||||
addRequiredField(swaggerInfo, storageSubPath, subPathArr[1], paramConfig.Required)
|
addRequiredField(swaggerInfo, storageSubPath, subPathArr[1], paramConfig.Required)
|
||||||
swaggerInfo.Definitions[storageSubPath].Properties[subPathArr[1]] = &define.SwaggerDefinitionProperty{
|
swaggerInfo.Definitions[storageSubPath].Properties[subPathArr[1]] = &define.SwaggerDefinitionProperty{
|
||||||
@ -285,7 +287,7 @@ func generateParameterDefinitions(swaggerInfo *define.Swagger, uri string, paren
|
|||||||
}
|
}
|
||||||
itemSwaggerDefinition := &define.SwaggerDefinitionProperty{
|
itemSwaggerDefinition := &define.SwaggerDefinitionProperty{
|
||||||
Description: "对象描述",
|
Description: "对象描述",
|
||||||
Type: wrapper.TernaryOperator.String(subPathArr[1] == "[]", "array", consts.SwaggerDataTypeObject).Value(),
|
Type: op_ternary.BaseType[string](subPathArr[1] == "[]", "array", consts.SwaggerDataTypeObject),
|
||||||
Items: nil,
|
Items: nil,
|
||||||
AllOf: nil,
|
AllOf: nil,
|
||||||
}
|
}
|
||||||
@ -383,7 +385,7 @@ func setGlobalMapDefinition(swaggerInfo *define.Swagger, dataType string) {
|
|||||||
//
|
//
|
||||||
// Date : 15:46 2024/4/25
|
// Date : 15:46 2024/4/25
|
||||||
func isGlobalMapType(dataType string) bool {
|
func isGlobalMapType(dataType string) bool {
|
||||||
return wrapper.ArrayType([]string{
|
return op_array.Has(*op_array.ArrayType[string]([]string{
|
||||||
consts.DataTypeMapAnyAny.String(),
|
consts.DataTypeMapAnyAny.String(),
|
||||||
consts.DataTypeMapStrUint.String(),
|
consts.DataTypeMapStrUint.String(),
|
||||||
consts.DataTypeMapStrInt.String(),
|
consts.DataTypeMapStrInt.String(),
|
||||||
@ -391,7 +393,7 @@ func isGlobalMapType(dataType string) bool {
|
|||||||
consts.DataTypeMapStrFloat.String(),
|
consts.DataTypeMapStrFloat.String(),
|
||||||
consts.DataTypeMapStrBool.String(),
|
consts.DataTypeMapStrBool.String(),
|
||||||
consts.DataTypeMapStrAny.String(),
|
consts.DataTypeMapStrAny.String(),
|
||||||
}).Has(dataType) >= 0
|
}), dataType) >= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// initAnyDefinition 初始化一个definition
|
// initAnyDefinition 初始化一个definition
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.zhangdeman.cn/zhangdeman/api-doc/define"
|
"git.zhangdeman.cn/zhangdeman/api-doc/define"
|
||||||
|
"git.zhangdeman.cn/zhangdeman/consts"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenerate(t *testing.T) {
|
func TestGenerate(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user