Compare commits

..

4 Commits

11 changed files with 17 additions and 106 deletions

View File

@ -331,10 +331,6 @@ func (c cGenService) generateServiceFiles(
mlog.Printf(`not overwrite, ignore generating service go file: %s`, filePath)
continue
}
if !utils.IsFileDoNotEdit(filePath) {
mlog.Printf(`ignore file as it is manually maintained: %s`, filePath)
continue
}
if !c.isToGenerateServiceGoFile(filePath, funcArray) {
mlog.Printf(`not dirty, ignore generating service go file: %s`, filePath)
continue
@ -351,6 +347,10 @@ func (c cGenService) generateServiceFiles(
// isToGenerateServiceGoFile checks and returns whether the service content dirty.
func (c cGenService) isToGenerateServiceGoFile(filePath string, funcArray *garray.StrArray) bool {
if !utils.IsFileDoNotEdit(filePath) {
mlog.Debugf(`ignore file as it is manually maintained: %s`, filePath)
return false
}
var (
fileContent = gfile.GetContents(filePath)
generatedFuncArray = garray.NewSortedStrArrayFrom(funcArray.Slice())

View File

@ -1,10 +1,9 @@
package consts
const TemplateGenServiceContent = `
// ================================================================================
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
// ==========================================================================
package {PackageName}

View File

@ -132,7 +132,7 @@ func (c *Core) CheckLocalTypeForField(ctx context.Context, fieldType string, fie
typeName = gstr.Trim(match[1])
typePattern = gstr.Trim(match[2])
} else {
typeName = gstr.Split(fieldType, " ")[0]
typeName = fieldType
}
typeName = strings.ToLower(typeName)
switch typeName {
@ -234,9 +234,6 @@ func (c *Core) CheckLocalTypeForField(ctx context.Context, fieldType string, fie
return LocalTypeBytes, nil
case strings.Contains(typeName, "int"):
if gstr.ContainsI(fieldType, "unsigned") {
return LocalTypeUint, nil
}
return LocalTypeInt, nil
case strings.Contains(typeName, "time"):

View File

@ -100,7 +100,6 @@ func doPrint(ctx context.Context, content string, stack bool) {
buffer.WriteString(content)
buffer.WriteString("\n")
if stack {
buffer.WriteString("Caller Stack:\n")
buffer.WriteString(gdebug.StackWithFilter([]string{stackFilterKey}))
}
fmt.Print(buffer.String())

View File

@ -202,9 +202,6 @@ func (oai *OpenApiV3) golangTypeToOAIFormat(t reflect.Type) string {
return FormatBinary
default:
if oai.isEmbeddedStructDefinition(t) {
return `EmbeddedStructDefinition`
}
return format
}
}

View File

@ -10,7 +10,6 @@ import (
"reflect"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/text/gstr"
)
type SchemaRefs []SchemaRef
@ -20,25 +19,8 @@ type SchemaRef struct {
Value *Schema
}
// isEmbeddedStructDefine checks and returns whether given golang type is embedded struct definition, like:
// struct A struct{
// B struct{
// // ...
// }
// }
// The `B` in `A` is called `embedded struct definition`.
func (oai *OpenApiV3) isEmbeddedStructDefinition(golangType reflect.Type) bool {
s := golangType.String()
if gstr.Contains(s, `struct {`) {
return true
}
return false
}
// newSchemaRefWithGolangType creates a new Schema and returns its SchemaRef.
func (oai *OpenApiV3) newSchemaRefWithGolangType(golangType reflect.Type, tagMap map[string]string) (*SchemaRef, error) {
var (
err error
oaiType = oai.golangTypeToOAIType(golangType)
oaiFormat = oai.golangTypeToOAIFormat(golangType)
schemaRef = &SchemaRef{}
@ -103,24 +85,15 @@ func (oai *OpenApiV3) newSchemaRefWithGolangType(golangType reflect.Type, tagMap
schemaRef.Value = nil
default:
golangTypeInstance := reflect.New(golangType).Elem().Interface()
if oai.isEmbeddedStructDefinition(golangType) {
schema, err = oai.structToSchema(golangTypeInstance)
if err != nil {
// Normal struct object.
var structTypeName = oai.golangTypeToSchemaName(golangType)
if oai.Components.Schemas.Get(structTypeName) == nil {
if err := oai.addSchema(reflect.New(golangType).Elem().Interface()); err != nil {
return nil, err
}
schemaRef.Ref = ""
schemaRef.Value = schema
} else {
var structTypeName = oai.golangTypeToSchemaName(golangType)
if oai.Components.Schemas.Get(structTypeName) == nil {
if err := oai.addSchema(golangTypeInstance); err != nil {
return nil, err
}
}
schemaRef.Ref = structTypeName
schemaRef.Value = nil
}
schemaRef.Ref = structTypeName
schemaRef.Value = nil
}
}
return schemaRef, nil

View File

@ -12,7 +12,6 @@ import (
"testing"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/net/goai"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/gmeta"
@ -938,7 +937,7 @@ func Test_EnumOfSchemaItems(t *testing.T) {
})
}
func Test_AliasNameOfAttribute(t *testing.T) {
func Test_AliasNameOfAtrribute(t *testing.T) {
type CreateResourceReq struct {
gmeta.Meta `path:"/CreateResourceReq" method:"POST"`
Name string `p:"n"`
@ -974,29 +973,3 @@ func Test_AliasNameOfAttribute(t *testing.T) {
)
})
}
func Test_EmbeddedStructAttribute(t *testing.T) {
type CreateResourceReq struct {
gmeta.Meta `path:"/CreateResourceReq" method:"POST"`
Name string `dc:"This is name."`
Embedded struct {
Age uint `dc:"This is embedded age."`
}
}
gtest.C(t, func(t *gtest.T) {
var (
err error
oai = goai.New()
req = new(CreateResourceReq)
)
err = oai.Add(goai.AddInput{
Object: req,
})
t.AssertNil(err)
b, err := json.Marshal(oai)
t.AssertNil(err)
t.Assert(b, `{"openapi":"3.0.0","components":{"schemas":{"github.com.gogf.gf.v2.net.goai_test.CreateResourceReq":{"properties":{"Name":{"description":"This is name.","format":"string","properties":{},"type":"string"},"Embedded":{"properties":{"Age":{"description":"This is embedded age.","format":"uint","properties":{},"type":"integer"}},"type":"object"}},"type":"object"}}},"info":{"title":"","version":""},"paths":null}`)
})
}

View File

@ -113,7 +113,7 @@ func Uint64(any interface{}) uint64 {
if valueFloat64 := Float64(value); math.IsNaN(valueFloat64) {
return 0
} else {
return uint64(valueFloat64)
return uint64(Float64(value))
}
}
}

View File

@ -560,13 +560,8 @@ func (v *Validator) doCheckValueRecursively(ctx context.Context, in doCheckValue
// Ignore data, assoc, rules and messages from parent.
var (
validator = v.Clone()
toBeValidatedObject interface{}
)
if in.Type.Kind() == reflect.Ptr {
toBeValidatedObject = reflect.New(in.Type.Elem()).Interface()
} else {
toBeValidatedObject = reflect.New(in.Type).Interface()
}
)
validator.assoc = nil
validator.rules = nil
validator.messages = nil

View File

@ -399,25 +399,3 @@ func Test_Issue1983(t *testing.T) {
t.AssertNil(err)
})
}
// https://github.com/gogf/gf/issues/1921
func Test_Issue1921(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
type SearchOption struct {
Size int `v:"max:100"`
}
type SearchReq struct {
Option *SearchOption `json:"option,omitempty"`
}
var (
req = SearchReq{
Option: &SearchOption{
Size: 10000,
},
}
)
err := g.Validator().Data(req).Run(ctx)
t.Assert(err, "The Size value `10000` must be equal or lesser than 100")
})
}

View File

@ -1,4 +1,4 @@
package gf
const VERSION = "v2.1.4"
const VERSION = "v2.1.3"
const AUTHORS = "john<john@goframe.org>"