From 685d14e662b4ca5ed7c811067c437384f2c75168 Mon Sep 17 00:00:00 2001 From: fisnone <20309982+fisnone@users.noreply.github.com> Date: Sun, 24 Jul 2022 10:48:50 +0800 Subject: [PATCH] fix:duplicate route check (#2154) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 黄志荣 --- tools/goctl/api/parser/g4/ast/apiparser.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/goctl/api/parser/g4/ast/apiparser.go b/tools/goctl/api/parser/g4/ast/apiparser.go index f454850b..46cc6740 100644 --- a/tools/goctl/api/parser/g4/ast/apiparser.go +++ b/tools/goctl/api/parser/g4/ast/apiparser.go @@ -232,20 +232,27 @@ func (p *Parser) invoke(linePrefix, content string) (v *Api, err error) { // storeVerificationInfo stores information for verification func (p *Parser) storeVerificationInfo(api *Api) { - routeMap := func(list []*ServiceRoute) { + routeMap := func(list []*ServiceRoute, prefix string) { for _, g := range list { handler := g.GetHandler() if handler.IsNotNil() { handlerName := handler.Text() p.handlerMap[handlerName] = Holder - route := fmt.Sprintf("%s://%s", g.Route.Method.Text(), g.Route.Path.Text()) + route := fmt.Sprintf("%s://%s", g.Route.Method.Text(), path.Join(prefix, g.Route.Path.Text())) p.routeMap[route] = Holder } } } for _, each := range api.Service { - routeMap(each.ServiceApi.ServiceRoute) + var prefix string + if each.AtServer != nil { + pExp := each.AtServer.Kv.Get(prefixKey) + if pExp != nil { + prefix = pExp.Text() + } + } + routeMap(each.ServiceApi.ServiceRoute, prefix) } for _, each := range api.Type {