From 9cef7dbeec865d283a226c2bd101a6a6fbdc2b9d Mon Sep 17 00:00:00 2001 From: duanlv Date: Tue, 6 Dec 2022 19:22:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=AE=9A=E4=B9=89=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E5=8F=82=E6=95=B0=E7=B1=BB=E5=9E=8B=E6=8C=89=E7=85=A7?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=E9=81=8D=E5=8E=86=E9=98=B2=E6=AD=A2=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=9A=84=E6=96=87=E6=A1=A3=E5=86=85=E5=AE=B9=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/echo/handler_analyzer.go | 23 ++++++++++++++--------- plugins/gin/handler_analyzer.go | 23 ++++++++++++++--------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/plugins/echo/handler_analyzer.go b/plugins/echo/handler_analyzer.go index 501e012..287b2a0 100644 --- a/plugins/echo/handler_analyzer.go +++ b/plugins/echo/handler_analyzer.go @@ -10,6 +10,7 @@ import ( analyzer "github.com/gotomicro/eapi" "github.com/gotomicro/eapi/plugins/common" "github.com/gotomicro/eapi/spec" + "github.com/gotomicro/eapi/utils" "github.com/iancoleman/strcase" "github.com/robertkrimen/otto" "github.com/samber/lo" @@ -356,15 +357,19 @@ func (p *handlerAnalyzer) parseDataType(call *ast.CallExpr, dataType *common.Dat case common.DataTypeObject: schema := spec.NewObjectSchema() properties := make(spec.Schemas) - for name, dataSchema := range dataType.Properties { - if !dataSchema.Optional { - schema.Required = append(schema.Required, name) - } - s := p.parseDataType(call, dataSchema, contentType) - if s != nil { - properties[name] = s - } - } + utils.RangeMapInOrder( + dataType.Properties, + func(a, b string) bool { return a < b }, + func(name string, dataSchema *common.DataSchema) { + if !dataSchema.Optional { + schema.Required = append(schema.Required, name) + } + s := p.parseDataType(call, dataSchema, contentType) + if s != nil { + properties[name] = s + } + }, + ) schema.Properties = properties return spec.NewSchemaRef("", schema) default: // fallback to js expression diff --git a/plugins/gin/handler_analyzer.go b/plugins/gin/handler_analyzer.go index 2a81b62..ce2273a 100644 --- a/plugins/gin/handler_analyzer.go +++ b/plugins/gin/handler_analyzer.go @@ -10,6 +10,7 @@ import ( analyzer "github.com/gotomicro/eapi" "github.com/gotomicro/eapi/plugins/common" "github.com/gotomicro/eapi/spec" + "github.com/gotomicro/eapi/utils" "github.com/iancoleman/strcase" "github.com/robertkrimen/otto" "github.com/samber/lo" @@ -373,15 +374,19 @@ func (p *handlerAnalyzer) parseDataType(call *ast.CallExpr, dataType *common.Dat case common.DataTypeObject: schema := spec.NewObjectSchema() properties := make(spec.Schemas) - for name, dataSchema := range dataType.Properties { - if !dataSchema.Optional { - schema.Required = append(schema.Required, name) - } - s := p.parseDataType(call, dataSchema, contentType) - if s != nil { - properties[name] = s - } - } + utils.RangeMapInOrder( + dataType.Properties, + func(a, b string) bool { return a < b }, + func(name string, dataSchema *common.DataSchema) { + if !dataSchema.Optional { + schema.Required = append(schema.Required, name) + } + s := p.parseDataType(call, dataSchema, contentType) + if s != nil { + properties[name] = s + } + }, + ) schema.Properties = properties return spec.NewSchemaRef("", schema) default: // fallback to js expression