diff --git a/openapi/generate_test.go b/openapi/generate_test.go index 1f4ab87..2b93cd5 100644 --- a/openapi/generate_test.go +++ b/openapi/generate_test.go @@ -19,8 +19,8 @@ import ( func TestGenerate_AddApiDoc(t *testing.T) { type Category struct { - ID int64 `json:"id" description:"分类ID"` - Name string `json:"name" description:"分类名称"` + ID int64 `json:"id" description:"分类ID" binding:"required,min=10,max=100"` + Name string `json:"name" description:"分类名称" binding:"required,min=8"` } type Product struct { ID int64 `json:"id,omitempty" description:"产品ID" example:"1001" required:"true" binding:"required"` diff --git a/openapi/schema.go b/openapi/schema.go index c7ef10d..6d71d25 100644 --- a/openapi/schema.go +++ b/openapi/schema.go @@ -81,7 +81,8 @@ func GenerateOpenAPISchema(s any) *openapi3.SchemaRef { } } - return generateSchemaRecursive(tType, make(map[string]bool)) + schema := generateSchemaRecursive(tType, make(map[string]bool)) + return schema } // 生成 schema