mirror of
https://gitee.com/johng/gf
synced 2026-07-04 21:03:13 +08:00
improve enum handling for array property of goai schema
This commit is contained in:
@ -157,6 +157,10 @@ func (oai *OpenApiV3) structToSchema(object interface{}) (*Schema, error) {
|
||||
return nil, err
|
||||
}
|
||||
schema.Items = subSchemaRef
|
||||
if len(schema.Enum) > 0 {
|
||||
schema.Items.Value.Enum = schema.Enum
|
||||
schema.Enum = nil
|
||||
}
|
||||
return schema, nil
|
||||
}
|
||||
// struct.
|
||||
|
||||
@ -51,6 +51,10 @@ func (oai *OpenApiV3) newSchemaRefWithGolangType(golangType reflect.Type, tagMap
|
||||
return nil, err
|
||||
}
|
||||
schema.Items = subSchemaRef
|
||||
if len(schema.Enum) > 0 {
|
||||
schema.Items.Value.Enum = schema.Enum
|
||||
schema.Enum = nil
|
||||
}
|
||||
|
||||
case
|
||||
TypeObject:
|
||||
|
||||
@ -875,3 +875,29 @@ func TestOpenApiV3_Ignore_Parameter(t *testing.T) {
|
||||
t.Assert(len(oai.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Properties.Map()), 8)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_EnumOfSchemaItems(t *testing.T) {
|
||||
type CreateResourceReq struct {
|
||||
gmeta.Meta `path:"/CreateResourceReq" method:"POST"`
|
||||
Members []string `v:"required|in:a,b,c"`
|
||||
}
|
||||
|
||||
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.protocol.goai_test.CreateResourceReq`).Value.
|
||||
Properties.Get(`Members`).Value.
|
||||
Items.Value.Enum,
|
||||
g.Slice{"a", "b", "c"},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user