diff --git a/protocol/goai/goai_shema.go b/protocol/goai/goai_shema.go index fa9819f6c..3a372f3a7 100644 --- a/protocol/goai/goai_shema.go +++ b/protocol/goai/goai_shema.go @@ -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. diff --git a/protocol/goai/goai_shema_ref.go b/protocol/goai/goai_shema_ref.go index 7480b8e67..0d8327f87 100644 --- a/protocol/goai/goai_shema_ref.go +++ b/protocol/goai/goai_shema_ref.go @@ -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: diff --git a/protocol/goai/goai_z_unit_test.go b/protocol/goai/goai_z_unit_test.go index e81b04715..da0bab7f3 100644 --- a/protocol/goai/goai_z_unit_test.go +++ b/protocol/goai/goai_z_unit_test.go @@ -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"}, + ) + }) +}