From 8ed6735d48468ec6cecd658e89e0c3dec0a7ae40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 6 Jan 2026 18:52:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E8=AF=95=E5=BF=85=E4=BC=A0?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openapi/generate_test.go | 4 ++-- openapi/schema.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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