优化ref生成
This commit is contained in:
parent
8a7999a480
commit
f82c691011
28
generate.go
28
generate.go
@ -206,7 +206,7 @@ func (g *Generate) AddApiFromInAndOut(baseCfg *define.UriBaseConfig, paramType r
|
|||||||
Summary: baseCfg.Summary,
|
Summary: baseCfg.Summary,
|
||||||
Description: baseCfg.Description,
|
Description: baseCfg.Description,
|
||||||
ExternalDocs: nil,
|
ExternalDocs: nil,
|
||||||
OperationID: defaultPkgPath + baseCfg.Method,
|
OperationID: baseCfg.Method + "-" + defaultPkgPath,
|
||||||
Parameters: nil,
|
Parameters: nil,
|
||||||
RequestBody: &define.RequestBody{
|
RequestBody: &define.RequestBody{
|
||||||
Required: true,
|
Required: true,
|
||||||
@ -287,7 +287,7 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|||||||
Properties: make(map[string]*define.Property),
|
Properties: make(map[string]*define.Property),
|
||||||
Required: make([]string, 0),
|
Required: make([]string, 0),
|
||||||
Enum: make([]any, 0),
|
Enum: make([]any, 0),
|
||||||
Type: "",
|
Type: consts.SwaggerDataTypeObject,
|
||||||
Ref: g.getSchemaRef(schemaName),
|
Ref: g.getSchemaRef(schemaName),
|
||||||
}
|
}
|
||||||
if len(rootSchemaName) == 0 || inputType.Kind() == reflect.Struct {
|
if len(rootSchemaName) == 0 || inputType.Kind() == reflect.Struct {
|
||||||
@ -305,7 +305,7 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|||||||
if len(rootSchemaName) == 0 {
|
if len(rootSchemaName) == 0 {
|
||||||
g.docData.Components.Schemas[schemaName].Type = consts.SwaggerDataTypeArray
|
g.docData.Components.Schemas[schemaName].Type = consts.SwaggerDataTypeArray
|
||||||
sliceItemType := g.parseSliceItem(schemaName, inputType)
|
sliceItemType := g.parseSliceItem(schemaName, inputType)
|
||||||
g.docData.Components.Schemas[schemaName].Items = &define.PropertyXOf{Ref: g.getSchemaRef(g.getSchemaRef(sliceItemType))}
|
g.docData.Components.Schemas[schemaName].Items = &define.PropertyXOf{Ref: g.getSchemaRef(sliceItemType)}
|
||||||
} else {
|
} else {
|
||||||
sliceItemType := g.parseSliceItem(schemaName, inputType)
|
sliceItemType := g.parseSliceItem(schemaName, inputType)
|
||||||
g.docData.Components.Schemas[rootSchemaName].Properties[schemaName] = &define.Property{
|
g.docData.Components.Schemas[rootSchemaName].Properties[schemaName] = &define.Property{
|
||||||
@ -356,7 +356,7 @@ func (g *Generate) AddComponentsSchema(rootSchemaName string, pkgPath string, in
|
|||||||
Format: inputType.Field(i).Type.String(),
|
Format: inputType.Field(i).Type.String(),
|
||||||
Description: ParseStructField.GetParamDesc(inputType.Field(i)),
|
Description: ParseStructField.GetParamDesc(inputType.Field(i)),
|
||||||
Items: &define.PropertyXOf{
|
Items: &define.PropertyXOf{
|
||||||
Ref: g.parseSliceItem(schemaName, inputType.Field(i).Type),
|
Ref: g.getSchemaRef(g.parseSliceItem(schemaName, inputType.Field(i).Type)),
|
||||||
},
|
},
|
||||||
Properties: map[string]*define.Property{},
|
Properties: map[string]*define.Property{},
|
||||||
}
|
}
|
||||||
@ -407,22 +407,6 @@ func (g *Generate) parseSliceItem(rootSchemaName string, inputType reflect.Type)
|
|||||||
sliceValue := reflect.MakeSlice(inputType, 1, 1)
|
sliceValue := reflect.MakeSlice(inputType, 1, 1)
|
||||||
sliceItemType := sliceValue.Index(0).Type()
|
sliceItemType := sliceValue.Index(0).Type()
|
||||||
g.AddComponentsSchema(rootSchemaName, sliceItemType.PkgPath(), sliceItemType)
|
g.AddComponentsSchema(rootSchemaName, sliceItemType.PkgPath(), sliceItemType)
|
||||||
/* if rootSchemaName != "" {
|
|
||||||
g.docData.Components.Schemas[rootSchemaName].Properties[sliceItemType.PkgPath()] = &define.Property{
|
|
||||||
Type: "",
|
|
||||||
Format: inputType.String(),
|
|
||||||
Enum: nil,
|
|
||||||
Default: "",
|
|
||||||
Description: "",
|
|
||||||
AllOf: nil,
|
|
||||||
OneOf: nil,
|
|
||||||
AnyOf: nil,
|
|
||||||
Items: nil,
|
|
||||||
AdditionalProperties: nil,
|
|
||||||
Properties: nil,
|
|
||||||
Ref: g.getSchemaRef(sliceItemType.PkgPath()),
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
if len(sliceItemType.PkgPath()) == 0 {
|
if len(sliceItemType.PkgPath()) == 0 {
|
||||||
return sliceItemType.String()
|
return sliceItemType.String()
|
||||||
}
|
}
|
||||||
@ -455,9 +439,9 @@ func (g *Generate) realBaseType2SwaggerType(realType string) string {
|
|||||||
case "byte", "*byte":
|
case "byte", "*byte":
|
||||||
return consts.SwaggerDataTypeByte
|
return consts.SwaggerDataTypeByte
|
||||||
case "float32", "*float32", "float64", "*float64":
|
case "float32", "*float32", "float64", "*float64":
|
||||||
return consts.SwaggerDataTypeNumber
|
return consts.SwaggerDataTypeDouble
|
||||||
case "int", "*int", "uint", "*uint", "int64", "*int64", "uint64", "*uint64":
|
case "int", "*int", "uint", "*uint", "int64", "*int64", "uint64", "*uint64":
|
||||||
return consts.SwaggerDataTypeNumber
|
return consts.SwaggerDataTypeInteger
|
||||||
case "int8", "*int8", "uint8", "*uint8", "int16", "*int16", "uint16", "*uint16", "int32", "*int32", "uint32", "*uint32":
|
case "int8", "*int8", "uint8", "*uint8", "int16", "*int16", "uint16", "*uint16", "int32", "*int32", "uint32", "*uint32":
|
||||||
return consts.SwaggerDataTypeInteger
|
return consts.SwaggerDataTypeInteger
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user