支持生成描述,默认值,参数名称
This commit is contained in:
parent
f9a1222712
commit
613e004bf2
34
generate.go
34
generate.go
@ -329,25 +329,29 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, schemaName string,
|
||||
inputType.Field(i).Type.Kind() == reflect.Slice {
|
||||
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),
|
||||
Format: inputType.Field(i).Type.String(),
|
||||
g.docData.Components.Schemas[schemaName].Properties[g.getParamName(inputType.Field(i))] = &define.Property{
|
||||
Type: g.realBaseType2SwaggerType(convertType),
|
||||
Format: inputType.Field(i).Type.String(),
|
||||
Default: g.getDefaultValue(inputType.Field(i)),
|
||||
Description: g.getParamDesc(inputType.Field(i)),
|
||||
}
|
||||
continue
|
||||
}
|
||||
g.AddComponentsSchema(schemaName, schemaName+inputType.Field(i).Name, inputType.Field(i).Type)
|
||||
g.AddComponentsSchema(schemaName, schemaName+g.getParamName(inputType.Field(i)), inputType.Field(i).Type)
|
||||
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{},
|
||||
g.docData.Components.Schemas[schemaName].Properties[schemaName+g.getParamName(inputType.Field(i))] = &define.Property{
|
||||
Type: consts.SwaggerDataTypeObject,
|
||||
Format: inputType.Field(i).Type.String(),
|
||||
Description: g.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 {
|
||||
g.docData.Components.Schemas[schemaName].Properties[schemaName+inputType.Field(i).Name] = &define.Property{
|
||||
Type: consts.SwaggerDataTypeArray,
|
||||
Format: inputType.Field(i).Type.String(),
|
||||
g.docData.Components.Schemas[schemaName].Properties[schemaName+g.getParamName(inputType.Field(i))] = &define.Property{
|
||||
Type: consts.SwaggerDataTypeArray,
|
||||
Format: inputType.Field(i).Type.String(),
|
||||
Description: g.getParamDesc(inputType.Field(i)),
|
||||
Items: &define.PropertyXOf{
|
||||
Ref: g.parseSliceItem(schemaName, inputType.Field(i).Type),
|
||||
},
|
||||
@ -358,9 +362,11 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, schemaName string,
|
||||
}
|
||||
|
||||
} else {
|
||||
g.docData.Components.Schemas[schemaName].Properties[inputType.Field(i).Name] = &define.Property{
|
||||
Type: g.realBaseType2SwaggerType(inputType.Field(i).Type.String()),
|
||||
Format: inputType.Field(i).Type.String(),
|
||||
g.docData.Components.Schemas[schemaName].Properties[g.getParamName(inputType.Field(i))] = &define.Property{
|
||||
Type: g.realBaseType2SwaggerType(inputType.Field(i).Type.String()),
|
||||
Format: inputType.Field(i).Type.String(),
|
||||
Default: g.getDefaultValue(inputType.Field(i)),
|
||||
Description: g.getParamDesc(inputType.Field(i)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
// Date : 17:55 2024/7/19
|
||||
func Test_parser_Openapi3(t *testing.T) {
|
||||
type A struct {
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name" d:"zhang" desc:"用户姓名"`
|
||||
}
|
||||
type B struct {
|
||||
List []A `json:"list"`
|
||||
|
Loading…
x
Reference in New Issue
Block a user