fix issue 1914 (#2075)

* CI updates

* fix issue #1914
This commit is contained in:
John Guo
2022-08-18 21:05:58 +08:00
committed by GitHub
parent eff46bd1db
commit 26e3c7aeb8
2 changed files with 42 additions and 2 deletions

View File

@ -174,8 +174,11 @@ func (oai *OpenApiV3) structToSchema(object interface{}) (*Schema, error) {
continue
}
var fieldName = structField.Name()
if jsonName := structField.TagJsonName(); jsonName != "" {
fieldName = jsonName
for _, tagName := range gconv.StructTagPriority {
if tagValue := structField.Tag(tagName); tagValue != "" {
fieldName = tagValue
break
}
}
schemaRef, err := oai.newSchemaRefWithGolangType(
structField.Type().Type,

View File

@ -936,3 +936,40 @@ func Test_EnumOfSchemaItems(t *testing.T) {
)
})
}
func Test_AliasNameOfAtrribute(t *testing.T) {
type CreateResourceReq struct {
gmeta.Meta `path:"/CreateResourceReq" method:"POST"`
Name string `p:"n"`
Age string `json:"a"`
}
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)
t.Assert(
oai.Components.Schemas.Get(`github.com.gogf.gf.v2.net.goai_test.CreateResourceReq`).Value.
Properties.Get(`Name`), nil,
)
t.Assert(
oai.Components.Schemas.Get(`github.com.gogf.gf.v2.net.goai_test.CreateResourceReq`).Value.
Properties.Get(`Age`), nil,
)
t.AssertNE(
oai.Components.Schemas.Get(`github.com.gogf.gf.v2.net.goai_test.CreateResourceReq`).Value.
Properties.Get(`n`), nil,
)
t.AssertNE(
oai.Components.Schemas.Get(`github.com.gogf.gf.v2.net.goai_test.CreateResourceReq`).Value.
Properties.Get(`a`), nil,
)
})
}