mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
openapi
This commit is contained in:
@ -199,6 +199,9 @@ func golangTypeToSchemaName(t reflect.Type) string {
|
||||
var (
|
||||
s = gstr.TrimLeft(t.String(), "*")
|
||||
)
|
||||
if pkgPath := t.PkgPath(); pkgPath != "" && pkgPath != "." {
|
||||
s = gstr.Replace(t.PkgPath(), `/`, `_`) + gstr.SubStrFrom(s, ".")
|
||||
}
|
||||
s = gstr.ReplaceByMap(s, map[string]string{
|
||||
` `: ``,
|
||||
`{`: ``,
|
||||
|
||||
@ -83,7 +83,7 @@ func (oai *OpenApiV3) newParameterRefWithStructMethod(field *structs.Field, meth
|
||||
return nil, gerror.NewCodef(gcode.CodeInvalidParameter, `invalid tag value "%s" for In`, parameter.In)
|
||||
}
|
||||
// Necessary schema or content.
|
||||
schemaRef, err := oai.newSchemaRefWithGolangType(field.Type(), tagMap)
|
||||
schemaRef, err := oai.newSchemaRefWithGolangType(field.Type().Type, tagMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ func (oai *OpenApiV3) addPath(in addPathInput) error {
|
||||
)
|
||||
// Create instance according input/output types.
|
||||
if reflectType.In(1).Kind() == reflect.Ptr {
|
||||
inputObject = reflect.New(reflectType.In(1).Elem())
|
||||
inputObject = reflect.New(reflectType.In(1).Elem()).Elem()
|
||||
} else {
|
||||
inputObject = reflect.New(reflectType.In(1).Elem()).Elem()
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ func (oai *OpenApiV3) getRequestSchemaRef(in getRequestSchemaRefInput) (*SchemaR
|
||||
default:
|
||||
if structField.Name() == dataFieldsPartsArray[0] {
|
||||
var (
|
||||
structFieldInstance = reflect.New(structField.Type().Type)
|
||||
structFieldInstance = reflect.New(structField.Type().Type).Elem()
|
||||
)
|
||||
schemaRef, err := oai.getRequestSchemaRef(getRequestSchemaRefInput{
|
||||
BusinessStructName: in.BusinessStructName,
|
||||
|
||||
@ -82,7 +82,7 @@ func (oai *OpenApiV3) getResponseSchemaRef(in getResponseSchemaRefInput) (*Schem
|
||||
default:
|
||||
if structField.Name() == dataFieldsPartsArray[0] {
|
||||
var (
|
||||
structFieldInstance = reflect.New(structField.Type().Type)
|
||||
structFieldInstance = reflect.New(structField.Type().Type).Elem()
|
||||
)
|
||||
schemaRef, err := oai.getResponseSchemaRef(getResponseSchemaRefInput{
|
||||
BusinessStructName: in.BusinessStructName,
|
||||
|
||||
@ -68,7 +68,7 @@ func (oai *OpenApiV3) newSchemaRefWithGolangType(golangType reflect.Type, tagMap
|
||||
}
|
||||
// Normal struct object.
|
||||
if _, ok := oai.Components.Schemas[structTypeName]; !ok {
|
||||
if err := oai.addSchema(reflect.New(golangType).Interface()); err != nil {
|
||||
if err := oai.addSchema(reflect.New(golangType).Elem().Interface()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user