增加标签获取
This commit is contained in:
57
generate.go
57
generate.go
@ -274,7 +274,7 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, schemaName string,
|
||||
Type: g.realType2SwaggerType(inputType.String()),
|
||||
Format: inputType.String(),
|
||||
Enum: nil,
|
||||
Default: nil,
|
||||
Default: "",
|
||||
Description: "",
|
||||
AllOf: nil,
|
||||
OneOf: nil,
|
||||
@ -401,7 +401,7 @@ func (g *Generate) parseSliceItem(rootSchemaName string, inputType reflect.Type)
|
||||
Type: "",
|
||||
Format: inputType.String(),
|
||||
Enum: nil,
|
||||
Default: nil,
|
||||
Default: "",
|
||||
Description: "",
|
||||
AllOf: nil,
|
||||
OneOf: nil,
|
||||
@ -465,3 +465,56 @@ func (g *Generate) realType2SwaggerType(realType string) string {
|
||||
}
|
||||
return g.realBaseType2SwaggerType(realType)
|
||||
}
|
||||
|
||||
// getParamName 获取参数名称
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 21:58 2025/2/11
|
||||
func (g *Generate) getParamName(structField reflect.StructField) string {
|
||||
paramNameTagList := []string{
|
||||
define.TagJson, define.TagForm,
|
||||
define.TagXml, define.TagYaml,
|
||||
define.TagYml,
|
||||
}
|
||||
for _, tag := range paramNameTagList {
|
||||
tagVal := structField.Tag.Get(tag)
|
||||
if tagVal != "" {
|
||||
return tagVal
|
||||
}
|
||||
}
|
||||
// 未设置相关字段, 则字段名即为参数名
|
||||
return structField.Name
|
||||
}
|
||||
|
||||
// getParamDesc ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 22:01 2025/2/11
|
||||
func (g *Generate) getParamDesc(structField reflect.StructField) string {
|
||||
descTagList := []string{define.TagDesc, define.TagDescription}
|
||||
for _, tag := range descTagList {
|
||||
tagVal := structField.Tag.Get(tag)
|
||||
if tagVal != "" {
|
||||
return tagVal
|
||||
}
|
||||
}
|
||||
// 没有显示的设置参数描述, 则使用参数名作为参数描述
|
||||
return g.getParamName(structField)
|
||||
}
|
||||
|
||||
// getDefaultValue 获取默认值
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 22:05 2025/2/11
|
||||
func (g *Generate) getDefaultValue(structField reflect.StructField) string {
|
||||
defaultTagList := []string{define.TagD, define.TagDefault}
|
||||
for _, tag := range defaultTagList {
|
||||
if tagVal, exist := structField.Tag.Lookup(tag); exist {
|
||||
return tagVal
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user