save code

This commit is contained in:
白茶清欢 2025-02-11 21:28:28 +08:00
parent a4a0c197ad
commit bdd0845f1d

View File

@ -269,10 +269,9 @@ func (g *Generate) AddApiFromInAndOut(baseCfg *define.UriBaseConfig, paramType r
//
// Date : 15:25 2025/2/8
func (g *Generate) AddComponentsSchema(rootSchemaName string, schemaName string, inputType reflect.Type) string {
fmt.Println(inputType.String())
if rootSchemaName != "" {
g.docData.Components.Schemas[rootSchemaName].Properties[schemaName] = &define.Property{
Type: g.getSchemaRes(schemaName),
Type: g.realType2SwaggerType(inputType.String()),
Format: inputType.String(),
Enum: nil,
Default: nil,
@ -328,7 +327,7 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, schemaName string,
inputType.Field(i).Type.Kind() == reflect.Map ||
inputType.Field(i).Type.Kind() == reflect.Array ||
inputType.Field(i).Type.Kind() == reflect.Slice {
if convertType := g.realBaseType2SwaggerType(inputType.Field(i).Type.String()); convertType != inputType.Field(i).Type.Kind().String() {
if convertType := g.realBaseType2SwaggerType(inputType.Field(i).Type.String()); !strings.HasPrefix(convertType, "[]") && convertType != inputType.Field(i).Type.Kind().String() {
// 针对基础类型指针
g.docData.Components.Schemas[schemaName].Properties[inputType.Field(i).Name] = &define.Property{
Type: g.realBaseType2SwaggerType(convertType),
@ -337,11 +336,27 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, schemaName string,
continue
}
g.AddComponentsSchema(schemaName, schemaName+inputType.Field(i).Name, inputType.Field(i).Type)
g.docData.Components.Schemas[schemaName].Properties[schemaName+inputType.Field(i).Name] = &define.Property{
Type: consts.SwaggerDataTypeObject,
Format: inputType.Field(i).Type.String(),
Properties: map[string]*define.Property{},
if inputType.Field(i).Type.Kind() == reflect.Struct ||
inputType.Field(i).Type.Kind() == reflect.Map {
g.docData.Components.Schemas[schemaName].Properties[schemaName+inputType.Field(i).Name] = &define.Property{
Type: consts.SwaggerDataTypeObject,
Format: inputType.Field(i).Type.String(),
Properties: map[string]*define.Property{},
}
} else if inputType.Field(i).Type.Kind() == reflect.Array ||
inputType.Field(i).Type.Kind() == reflect.Slice {
g.docData.Components.Schemas[schemaName].Properties[schemaName+inputType.Field(i).Name] = &define.Property{
Type: consts.SwaggerDataTypeArray,
Format: inputType.Field(i).Type.String(),
Items: &define.PropertyXOf{
Ref: g.parseSliceItem(schemaName, inputType.Field(i).Type),
},
Properties: map[string]*define.Property{},
}
} else if inputType.Field(i).Type.Kind() == reflect.Ptr {
}
} else {
g.docData.Components.Schemas[schemaName].Properties[inputType.Field(i).Name] = &define.Property{
Type: g.realBaseType2SwaggerType(inputType.Field(i).Type.String()),
@ -438,3 +453,15 @@ func (g *Generate) realBaseType2SwaggerType(realType string) string {
return realType
}
}
// 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)
}