|
|
|
@ -270,7 +270,7 @@ func (g *Generate) getApiDocBaseCfg(baseCfg *define.UriBaseConfig, paramType ref
|
|
|
|
|
Summary: baseCfg.Summary,
|
|
|
|
|
Description: baseCfg.Description,
|
|
|
|
|
ExternalDocs: nil,
|
|
|
|
|
OperationID: baseCfg.Summary + "(" + strings.ReplaceAll(strings.TrimLeft(baseCfg.Uri, "/"), "/", "-") + ")",
|
|
|
|
|
OperationID: baseCfg.Summary + "(" + baseCfg.Method + "-" + strings.ReplaceAll(strings.TrimLeft(baseCfg.Uri, "/"), "/", "-") + ")",
|
|
|
|
|
Parameters: make([]*define.PathConfigParameter, 0),
|
|
|
|
|
RequestBody: &define.RequestBody{
|
|
|
|
|
Required: true,
|
|
|
|
@ -326,7 +326,11 @@ func (g *Generate) ParseReadConfigParam(requestCfg *define.UriBaseConfig, baseRe
|
|
|
|
|
baseReqCfg.Parameters = make([]*define.PathConfigParameter, 0)
|
|
|
|
|
}
|
|
|
|
|
for i := 0; i < inputType.NumField(); i++ {
|
|
|
|
|
propertyName := ParseStructField.GetParamName(inputType.Field(i))
|
|
|
|
|
if inputType.Field(i).Anonymous {
|
|
|
|
|
// 匿名字段, 直接对齐到当前的父级
|
|
|
|
|
g.ParseReadConfigParam(requestCfg, baseReqCfg, inputType.Field(i).Type)
|
|
|
|
|
}
|
|
|
|
|
propertyName := ParseStructFieldTag.GetParamName(inputType.Field(i))
|
|
|
|
|
if propertyName == "-" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
@ -334,22 +338,43 @@ func (g *Generate) ParseReadConfigParam(requestCfg *define.UriBaseConfig, baseRe
|
|
|
|
|
// 空Meta字段认为是用来描述元信息的, 忽略
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
convertBaseType, isBaseType := g.realBaseType2SwaggerType(inputType.Field(i).Type.String())
|
|
|
|
|
realInputTypeFormat := inputType.Field(i).Type.String()
|
|
|
|
|
fieldType := inputType.Field(i).Type
|
|
|
|
|
/*if inputType.Field(i).Type.Kind() == reflect.Ptr {
|
|
|
|
|
fieldType = inputType.Field(i).Type.Elem()
|
|
|
|
|
}*/
|
|
|
|
|
if isBaseType {
|
|
|
|
|
// 当做默认基础类型, 默认不会出现 *map *[]
|
|
|
|
|
baseReqCfg.Parameters = append(baseReqCfg.Parameters, &define.PathConfigParameter{
|
|
|
|
|
Name: propertyName,
|
|
|
|
|
In: consts.SwaggerParameterInQuery,
|
|
|
|
|
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Required: ValidateRule.IsRequired(inputType.Field(i)),
|
|
|
|
|
Deprecated: ParseStructFieldTag.Deprecated(inputType.Field(i)),
|
|
|
|
|
Schema: &define.Schema{
|
|
|
|
|
Type: convertBaseType,
|
|
|
|
|
Format: realInputTypeFormat,
|
|
|
|
|
},
|
|
|
|
|
AllowEmptyValue: false,
|
|
|
|
|
Style: "",
|
|
|
|
|
Explode: false,
|
|
|
|
|
AllowReserved: false,
|
|
|
|
|
})
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if inputType.Field(i).Type.Kind() == reflect.Ptr {
|
|
|
|
|
// 处理指针
|
|
|
|
|
if inputType.Field(i).Type.Elem().Kind() == reflect.Struct {
|
|
|
|
|
|
|
|
|
|
// 结构体指针
|
|
|
|
|
schemaNameNext := g.AddComponentsSchema("", propertyName, inputType.Field(i).Type.Elem())
|
|
|
|
|
baseReqCfg.Parameters = append(baseReqCfg.Parameters, &define.PathConfigParameter{
|
|
|
|
|
Name: propertyName,
|
|
|
|
|
In: consts.SwaggerParameterInQuery,
|
|
|
|
|
Description: ParseStructField.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Required: ValidateRule.IsRequired(inputType.Field(i)),
|
|
|
|
|
Deprecated: ParseStructField.Deprecated(inputType.Field(i)),
|
|
|
|
|
Deprecated: ParseStructFieldTag.Deprecated(inputType.Field(i)),
|
|
|
|
|
Schema: &define.Schema{
|
|
|
|
|
// Format: realInputTypeFormat,
|
|
|
|
|
Ref: g.getSchemaRef(schemaNameNext),
|
|
|
|
@ -359,22 +384,7 @@ func (g *Generate) ParseReadConfigParam(requestCfg *define.UriBaseConfig, baseRe
|
|
|
|
|
AllowReserved: false,
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
// 当做默认基础类型, 默认不会出现 *map *[]
|
|
|
|
|
baseReqCfg.Parameters = append(baseReqCfg.Parameters, &define.PathConfigParameter{
|
|
|
|
|
Name: propertyName,
|
|
|
|
|
In: consts.SwaggerParameterInQuery,
|
|
|
|
|
Description: ParseStructField.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Required: ValidateRule.IsRequired(inputType.Field(i)),
|
|
|
|
|
Deprecated: ParseStructField.Deprecated(inputType.Field(i)),
|
|
|
|
|
Schema: &define.Schema{
|
|
|
|
|
Type: g.realBaseType2SwaggerType(inputType.Field(i).Type.String()),
|
|
|
|
|
Format: realInputTypeFormat,
|
|
|
|
|
},
|
|
|
|
|
AllowEmptyValue: false,
|
|
|
|
|
Style: "",
|
|
|
|
|
Explode: false,
|
|
|
|
|
AllowReserved: false,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
@ -382,37 +392,14 @@ func (g *Generate) ParseReadConfigParam(requestCfg *define.UriBaseConfig, baseRe
|
|
|
|
|
fieldType.Kind() == reflect.Map ||
|
|
|
|
|
fieldType.Kind() == reflect.Array ||
|
|
|
|
|
fieldType.Kind() == reflect.Slice {
|
|
|
|
|
if convertType := g.realBaseType2SwaggerType(fieldType.String()); !strings.HasPrefix(convertType, "[]") && convertType != inputType.Field(i).Type.Kind().String() {
|
|
|
|
|
// 针对基础类型指针
|
|
|
|
|
baseReqCfg.Parameters = append(baseReqCfg.Parameters, &define.PathConfigParameter{
|
|
|
|
|
Name: ParseStructField.GetParamName(inputType.Field(i)),
|
|
|
|
|
In: consts.SwaggerParameterInQuery,
|
|
|
|
|
Description: ParseStructField.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Required: ValidateRule.IsRequired(inputType.Field(i)),
|
|
|
|
|
Deprecated: ParseStructField.Deprecated(inputType.Field(i)),
|
|
|
|
|
Schema: &define.Schema{
|
|
|
|
|
Type: g.realBaseType2SwaggerType(inputType.Field(i).Type.String()),
|
|
|
|
|
Items: nil,
|
|
|
|
|
Ref: "",
|
|
|
|
|
Format: realInputTypeFormat,
|
|
|
|
|
},
|
|
|
|
|
AllowEmptyValue: false,
|
|
|
|
|
Style: "",
|
|
|
|
|
Explode: false,
|
|
|
|
|
AllowReserved: false,
|
|
|
|
|
Ref: "",
|
|
|
|
|
})
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
baseReqCfg.Parameters = append(baseReqCfg.Parameters, &define.PathConfigParameter{
|
|
|
|
|
Name: ParseStructField.GetParamName(inputType.Field(i)),
|
|
|
|
|
Name: ParseStructFieldTag.GetParamName(inputType.Field(i)),
|
|
|
|
|
In: consts.SwaggerParameterInQuery,
|
|
|
|
|
Description: ParseStructField.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Required: ValidateRule.IsRequired(inputType.Field(i)),
|
|
|
|
|
Deprecated: ParseStructField.Deprecated(inputType.Field(i)),
|
|
|
|
|
Deprecated: ParseStructFieldTag.Deprecated(inputType.Field(i)),
|
|
|
|
|
Schema: &define.Schema{
|
|
|
|
|
Type: g.realBaseType2SwaggerType(inputType.Field(i).Type.String()),
|
|
|
|
|
Type: convertBaseType,
|
|
|
|
|
Items: nil,
|
|
|
|
|
Ref: "",
|
|
|
|
|
Format: realInputTypeFormat,
|
|
|
|
@ -482,16 +469,25 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|
|
|
|
}
|
|
|
|
|
// 数组
|
|
|
|
|
if inputType.Kind() == reflect.Slice || inputType.Kind() == reflect.Array {
|
|
|
|
|
sliceItemType, itemIsBaseType := g.parseSliceItem(schemaName, inputType)
|
|
|
|
|
propertyXOf := &define.PropertyXOf{}
|
|
|
|
|
if itemIsBaseType {
|
|
|
|
|
propertyXOf.Type, _ = g.realBaseType2SwaggerType(sliceItemType)
|
|
|
|
|
propertyXOf.Format = sliceItemType
|
|
|
|
|
propertyXOf.Ref = ""
|
|
|
|
|
} else {
|
|
|
|
|
propertyXOf.Type = ""
|
|
|
|
|
propertyXOf.Format = ""
|
|
|
|
|
propertyXOf.Ref = g.getSchemaRef(sliceItemType)
|
|
|
|
|
}
|
|
|
|
|
if len(rootSchemaName) == 0 {
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Type = consts.SwaggerDataTypeArray
|
|
|
|
|
sliceItemType := g.parseSliceItem(schemaName, inputType)
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Items = &define.PropertyXOf{Ref: g.getSchemaRef(sliceItemType)}
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Items = propertyXOf
|
|
|
|
|
} else {
|
|
|
|
|
sliceItemType := g.parseSliceItem(schemaName, inputType)
|
|
|
|
|
g.docData.Components.Schemas[rootSchemaName].Properties[schemaName] = &define.Property{
|
|
|
|
|
Type: consts.SwaggerDataTypeArray,
|
|
|
|
|
Format: inputType.String(),
|
|
|
|
|
Items: &define.PropertyXOf{Ref: g.getSchemaRef(sliceItemType)},
|
|
|
|
|
Items: propertyXOf,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -500,7 +496,12 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|
|
|
|
// 结构体
|
|
|
|
|
if inputType.Kind() == reflect.Struct {
|
|
|
|
|
for i := 0; i < inputType.NumField(); i++ {
|
|
|
|
|
propertyName := ParseStructField.GetParamName(inputType.Field(i))
|
|
|
|
|
if inputType.Field(i).Anonymous {
|
|
|
|
|
// 处理匿名字段
|
|
|
|
|
g.handleAnonymousField(schemaName, inputType.Field(i))
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
propertyName := ParseStructFieldTag.GetParamName(inputType.Field(i))
|
|
|
|
|
if propertyName == "-" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
@ -514,11 +515,12 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 当做默认基础类型, 默认不会出现 *map *[]
|
|
|
|
|
convertBaseType, _ := g.realBaseType2SwaggerType(inputType.Field(i).Type.String())
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Properties[propertyName] = &define.Property{
|
|
|
|
|
Type: g.realBaseType2SwaggerType(g.realBaseType2SwaggerType(inputType.Field(i).Type.String())),
|
|
|
|
|
Type: convertBaseType,
|
|
|
|
|
Format: inputType.Field(i).Type.String(),
|
|
|
|
|
Default: ParseStructField.GetDefaultValue(inputType.Field(i)),
|
|
|
|
|
Description: ParseStructField.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Default: ParseStructFieldTag.GetDefaultValue(inputType.Field(i)),
|
|
|
|
|
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
@ -532,30 +534,38 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Properties[propertyName] = &define.Property{
|
|
|
|
|
Type: consts.SwaggerDataTypeObject,
|
|
|
|
|
Format: inputType.Field(i).Type.String(),
|
|
|
|
|
Description: ParseStructField.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Properties: map[string]*define.Property{},
|
|
|
|
|
}
|
|
|
|
|
} else if inputType.Field(i).Type.Kind() == reflect.Array ||
|
|
|
|
|
inputType.Field(i).Type.Kind() == reflect.Slice {
|
|
|
|
|
sliceItemType, itemIsBaseType := g.parseSliceItem(schemaName, inputType.Field(i).Type)
|
|
|
|
|
propertyXOf := &define.PropertyXOf{}
|
|
|
|
|
if itemIsBaseType {
|
|
|
|
|
propertyXOf.Type, _ = g.realBaseType2SwaggerType(sliceItemType)
|
|
|
|
|
propertyXOf.Format = sliceItemType
|
|
|
|
|
propertyXOf.Ref = ""
|
|
|
|
|
} else {
|
|
|
|
|
propertyXOf.Type = ""
|
|
|
|
|
propertyXOf.Format = ""
|
|
|
|
|
propertyXOf.Ref = g.getSchemaRef(sliceItemType)
|
|
|
|
|
}
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Properties[propertyName] = &define.Property{
|
|
|
|
|
Type: consts.SwaggerDataTypeArray,
|
|
|
|
|
Format: inputType.Field(i).Type.String(),
|
|
|
|
|
Description: ParseStructField.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Items: &define.PropertyXOf{
|
|
|
|
|
Ref: g.getSchemaRef(g.parseSliceItem(schemaName, inputType.Field(i).Type)),
|
|
|
|
|
},
|
|
|
|
|
Properties: map[string]*define.Property{},
|
|
|
|
|
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Items: propertyXOf,
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
g.AddComponentsSchema(schemaName, propertyName, inputType.Field(i).Type)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
convertBaseType, _ := g.realBaseType2SwaggerType(inputType.Field(i).Type.String())
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Properties[propertyName] = &define.Property{
|
|
|
|
|
Type: g.realBaseType2SwaggerType(inputType.Field(i).Type.String()),
|
|
|
|
|
Type: convertBaseType,
|
|
|
|
|
Format: inputType.Field(i).Type.String(),
|
|
|
|
|
Default: ParseStructField.GetDefaultValue(inputType.Field(i)),
|
|
|
|
|
Description: ParseStructField.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
Default: ParseStructFieldTag.GetDefaultValue(inputType.Field(i)),
|
|
|
|
|
Description: ParseStructFieldTag.GetParamDesc(inputType.Field(i)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 设置参数各种属性
|
|
|
|
@ -569,7 +579,7 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|
|
|
|
// 非基础数据类型
|
|
|
|
|
return g.AddComponentsSchema(schemaName, inputType.Elem().String(), inputType.Elem())
|
|
|
|
|
} else {
|
|
|
|
|
convertType := g.realBaseType2SwaggerType(inputType.String())
|
|
|
|
|
convertType, _ := g.realBaseType2SwaggerType(inputType.String())
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Properties[schemaName] = &define.Property{
|
|
|
|
|
Type: convertType,
|
|
|
|
|
Format: inputType.String(),
|
|
|
|
@ -580,26 +590,73 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|
|
|
|
return schemaName
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleAnonymousField 处理匿名字段
|
|
|
|
|
//
|
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
|
//
|
|
|
|
|
// Date : 18:43 2025/2/17
|
|
|
|
|
func (g *Generate) handleAnonymousField(schemaName string, field reflect.StructField) {
|
|
|
|
|
if !field.Anonymous {
|
|
|
|
|
// 不是匿名字段
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
handleType := field.Type
|
|
|
|
|
if handleType.Kind() == reflect.Ptr {
|
|
|
|
|
handleType = handleType.Elem()
|
|
|
|
|
}
|
|
|
|
|
for i := 0; i < handleType.NumField(); i++ {
|
|
|
|
|
if handleType.Field(i).Anonymous {
|
|
|
|
|
// 递归处理多层嵌套匿名字段
|
|
|
|
|
g.handleAnonymousField(schemaName, handleType.Field(i))
|
|
|
|
|
continue
|
|
|
|
|
} else {
|
|
|
|
|
itemField := handleType.Field(i)
|
|
|
|
|
baseConvertType, isBaseType := g.realBaseType2SwaggerType(itemField.Type.String())
|
|
|
|
|
if !isBaseType {
|
|
|
|
|
g.AddComponentsSchema(schemaName, itemField.Type.PkgPath(), itemField.Type)
|
|
|
|
|
continue
|
|
|
|
|
} else {
|
|
|
|
|
paramName := ParseStructFieldTag.GetParamName(itemField)
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Properties[paramName] = &define.Property{
|
|
|
|
|
Type: baseConvertType,
|
|
|
|
|
Format: itemField.Type.String(),
|
|
|
|
|
Enum: ValidateRule.Enum(itemField),
|
|
|
|
|
Default: ParseStructFieldTag.GetDefaultValue(itemField),
|
|
|
|
|
Description: ParseStructFieldTag.GetParamDesc(itemField),
|
|
|
|
|
}
|
|
|
|
|
if ValidateRule.IsRequired(itemField) {
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Required = append(g.docData.Components.Schemas[schemaName].Required, paramName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parseSliceItem 解析数组每一项
|
|
|
|
|
//
|
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
|
//
|
|
|
|
|
// Date : 21:33 2025/2/8
|
|
|
|
|
func (g *Generate) parseSliceItem(rootSchemaName string, inputType reflect.Type) string {
|
|
|
|
|
func (g *Generate) parseSliceItem(rootSchemaName string, inputType reflect.Type) (string, bool) {
|
|
|
|
|
if inputType.Kind() != reflect.Slice && inputType.Kind() != reflect.Array {
|
|
|
|
|
// 不是数组
|
|
|
|
|
return ""
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
sliceValue := reflect.MakeSlice(inputType, 1, 1)
|
|
|
|
|
sliceItemType := sliceValue.Index(0).Type()
|
|
|
|
|
realSliceItemType := sliceItemType.String()
|
|
|
|
|
if sliceItemType.Kind() == reflect.Ptr {
|
|
|
|
|
sliceItemType = sliceItemType.Elem()
|
|
|
|
|
}
|
|
|
|
|
_, isBaseType := g.realBaseType2SwaggerType(sliceItemType.String())
|
|
|
|
|
if isBaseType {
|
|
|
|
|
return realSliceItemType, true
|
|
|
|
|
}
|
|
|
|
|
g.AddComponentsSchema(rootSchemaName, sliceItemType.PkgPath(), sliceItemType)
|
|
|
|
|
if len(sliceItemType.PkgPath()) == 0 {
|
|
|
|
|
return sliceItemType.String()
|
|
|
|
|
return realSliceItemType, false
|
|
|
|
|
}
|
|
|
|
|
return sliceItemType.PkgPath() + "." + sliceItemType.Name()
|
|
|
|
|
return sliceItemType.PkgPath() + "." + sliceItemType.Name(), false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// getSchemaRef 获取引用的类型
|
|
|
|
@ -612,7 +669,11 @@ func (g *Generate) getSchemaRef(schemaName string) string {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
schemaName = strings.ReplaceAll(schemaName, "*", "") // 去除指针类型 *
|
|
|
|
|
return "#/components/schemas/" + strings.ReplaceAll(schemaName, "/", ".")
|
|
|
|
|
convertType, isBaseType := g.realBaseType2SwaggerType(schemaName)
|
|
|
|
|
if isBaseType {
|
|
|
|
|
return convertType
|
|
|
|
|
}
|
|
|
|
|
return "#/components/schemas/" + strings.ReplaceAll(convertType, "/", ".")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// realType2SwaggerType golang 真实数据类型转换为golang数据类型
|
|
|
|
@ -620,48 +681,39 @@ func (g *Generate) getSchemaRef(schemaName string) string {
|
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
|
//
|
|
|
|
|
// Date : 20:25 2025/2/11
|
|
|
|
|
func (g *Generate) realBaseType2SwaggerType(realType string) string {
|
|
|
|
|
func (g *Generate) realBaseType2SwaggerType(realType string) (string, bool) {
|
|
|
|
|
switch realType {
|
|
|
|
|
case "bool", "*bool":
|
|
|
|
|
return consts.SwaggerDataTypeBoolean
|
|
|
|
|
return consts.SwaggerDataTypeBoolean, true
|
|
|
|
|
case "string", "*string":
|
|
|
|
|
return consts.SwaggerDataTypeString
|
|
|
|
|
return consts.SwaggerDataTypeString, true
|
|
|
|
|
case "byte", "*byte":
|
|
|
|
|
return consts.SwaggerDataTypeByte
|
|
|
|
|
return consts.SwaggerDataTypeByte, true
|
|
|
|
|
case "float32", "*float32", "float64", "*float64":
|
|
|
|
|
return consts.SwaggerDataTypeDouble
|
|
|
|
|
return consts.SwaggerDataTypeDouble, true
|
|
|
|
|
case "int", "*int", "uint", "*uint", "int64", "*int64", "uint64", "*uint64":
|
|
|
|
|
return consts.SwaggerDataTypeInteger
|
|
|
|
|
return consts.SwaggerDataTypeInteger, true
|
|
|
|
|
case "int8", "*int8", "uint8", "*uint8", "int16", "*int16", "uint16", "*uint16", "int32", "*int32", "uint32", "*uint32":
|
|
|
|
|
return consts.SwaggerDataTypeInteger
|
|
|
|
|
return consts.SwaggerDataTypeInteger, true
|
|
|
|
|
default:
|
|
|
|
|
return realType
|
|
|
|
|
if strings.HasPrefix(realType, "[]") {
|
|
|
|
|
return consts.SwaggerDataTypeArray, true
|
|
|
|
|
}
|
|
|
|
|
return realType, false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// realType2SwaggerType ...
|
|
|
|
|
//
|
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
|
//
|
|
|
|
|
// Date : 21:20 2025/2/11
|
|
|
|
|
func (g *Generate) realType2SwaggerType(realType string) string {
|
|
|
|
|
if strings.HasPrefix(realType, "[]") {
|
|
|
|
|
return consts.SwaggerDataTypeArray
|
|
|
|
|
}
|
|
|
|
|
return g.realBaseType2SwaggerType(realType)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setStructFieldProperty 添加struct_field各种属性
|
|
|
|
|
//
|
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
|
//
|
|
|
|
|
// Date : 16:13 2025/2/13
|
|
|
|
|
func (g *Generate) setStructFieldProperty(schemaName string, structField reflect.StructField) {
|
|
|
|
|
paramName := ParseStructField.GetParamName(structField)
|
|
|
|
|
paramName := ParseStructFieldTag.GetParamName(structField)
|
|
|
|
|
if ValidateRule.IsRequired(structField) {
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Required = append(g.docData.Components.Schemas[schemaName].Required, paramName)
|
|
|
|
|
}
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Properties[ParseStructField.GetParamName(structField)].Enum = ValidateRule.Enum(structField)
|
|
|
|
|
g.docData.Components.Schemas[schemaName].Properties[ParseStructFieldTag.GetParamName(structField)].Enum = ValidateRule.Enum(structField)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parseBaseUriConfig 通过Meta字段解析Uri基础配置信息
|
|
|
|
@ -718,7 +770,10 @@ func (g *Generate) parseBaseUriConfig(uriPrefix string, paramType reflect.Type)
|
|
|
|
|
responseContentType = consts.MimeTypeJson
|
|
|
|
|
}
|
|
|
|
|
res.OutputContentType = strings.Split(responseContentType, ",")
|
|
|
|
|
res.Summary = ParseStructField.Summary(metaField)
|
|
|
|
|
res.Summary = ParseStructFieldTag.Summary(metaField)
|
|
|
|
|
if len(res.Summary) == 0 {
|
|
|
|
|
res.Summary = wrapper.String(strings.ReplaceAll(strings.TrimLeft(res.Uri, "/"), "/", "_")).SnakeCaseToCamel()
|
|
|
|
|
}
|
|
|
|
|
if res.Method == "" {
|
|
|
|
|
return nil, errors.New("baseCfg.Method is empty")
|
|
|
|
|
}
|
|
|
|
|