mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
fix issue in empty json name along with omitempty tag in package oai (#2500)
This commit is contained in:
@ -38,7 +38,10 @@ func (oai *OpenApiV3) newParameterRefWithStructMethod(field gstructs.Field, path
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldName = gstr.SplitAndTrim(fieldName, ",")[0]
|
||||
fieldName = gstr.Split(gstr.Trim(fieldName), ",")[0]
|
||||
if fieldName == "" {
|
||||
fieldName = field.Name()
|
||||
}
|
||||
var parameter = &Parameter{
|
||||
Name: fieldName,
|
||||
XExtensions: make(XExtensions),
|
||||
|
||||
@ -180,7 +180,10 @@ func (oai *OpenApiV3) structToSchema(object interface{}) (*Schema, error) {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldName = gstr.SplitAndTrim(fieldName, ",")[0]
|
||||
fieldName = gstr.Split(gstr.Trim(fieldName), ",")[0]
|
||||
if fieldName == "" {
|
||||
fieldName = structField.Name()
|
||||
}
|
||||
schemaRef, err := oai.newSchemaRefWithGolangType(
|
||||
structField.Type().Type,
|
||||
structField.TagMap(),
|
||||
|
||||
@ -1099,3 +1099,27 @@ func TestOpenApiV3_PathSecurity(t *testing.T) {
|
||||
t.Assert(len(oai.Paths["/index"].Put.Responses["200"].Value.Content["application/json"].Schema.Value.Properties.Map()), 3)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_EmptyJsonNameWithOmitEmpty(t *testing.T) {
|
||||
type CreateResourceReq struct {
|
||||
gmeta.Meta `path:"/CreateResourceReq" method:"POST" tags:"default"`
|
||||
Name string `description:"实例名称" json:",omitempty"`
|
||||
Product string `description:"业务类型" json:",omitempty"`
|
||||
}
|
||||
|
||||
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)
|
||||
var reqKey = "github.com.gogf.gf.v2.net.goai_test.CreateResourceReq"
|
||||
t.AssertNE(oai.Components.Schemas.Get(reqKey).Value.Properties.Get("Name"), nil)
|
||||
t.AssertNE(oai.Components.Schemas.Get(reqKey).Value.Properties.Get("Product"), nil)
|
||||
t.Assert(oai.Components.Schemas.Get(reqKey).Value.Properties.Get("None"), nil)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user