|
@@ -3,6 +3,7 @@ package ast
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
|
|
+ "path"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
@@ -113,13 +114,13 @@ func (p *Parser) parse(filename, content string) (*Api, error) {
|
|
apiAstList = append(apiAstList, root)
|
|
apiAstList = append(apiAstList, root)
|
|
for _, imp := range root.Import {
|
|
for _, imp := range root.Import {
|
|
dir := filepath.Dir(p.src)
|
|
dir := filepath.Dir(p.src)
|
|
- path := filepath.Join(dir, imp.Value.Text())
|
|
|
|
- data, err := p.readContent(path)
|
|
|
|
|
|
+ imp := filepath.Join(dir, imp.Value.Text())
|
|
|
|
+ data, err := p.readContent(imp)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- nestedApi, err := p.invoke(path, data)
|
|
|
|
|
|
+ nestedApi, err := p.invoke(imp, data)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -196,8 +197,8 @@ func (p *Parser) valid(mainApi, nestedApi *Api) error {
|
|
if handler.IsNotNil() {
|
|
if handler.IsNotNil() {
|
|
handlerName := handler.Text()
|
|
handlerName := handler.Text()
|
|
handlerMap[handlerName] = Holder
|
|
handlerMap[handlerName] = Holder
|
|
- path := fmt.Sprintf("%s://%s", g.Route.Method.Text(), g.Route.Path.Text())
|
|
|
|
- routeMap[path] = Holder
|
|
|
|
|
|
+ route := fmt.Sprintf("%s://%s", g.Route.Method.Text(), g.Route.Path.Text())
|
|
|
|
+ routeMap[route] = Holder
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -239,6 +240,13 @@ func (p *Parser) valid(mainApi, nestedApi *Api) error {
|
|
|
|
|
|
func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap, mainRouteMap map[string]PlaceHolder) error {
|
|
func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap, mainRouteMap map[string]PlaceHolder) error {
|
|
for _, each := range nestedApi.Service {
|
|
for _, each := range nestedApi.Service {
|
|
|
|
+ var prefix string
|
|
|
|
+ if each.AtServer != nil {
|
|
|
|
+ p := each.AtServer.Kv.Get(prefixKey)
|
|
|
|
+ if p != nil {
|
|
|
|
+ prefix = p.Text()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
for _, r := range each.ServiceApi.ServiceRoute {
|
|
for _, r := range each.ServiceApi.ServiceRoute {
|
|
handler := r.GetHandler()
|
|
handler := r.GetHandler()
|
|
if !handler.IsNotNil() {
|
|
if !handler.IsNotNil() {
|
|
@@ -250,8 +258,8 @@ func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap, mainRouteMa
|
|
nestedApi.LinePrefix, handler.Line(), handler.Column(), handler.Text())
|
|
nestedApi.LinePrefix, handler.Line(), handler.Column(), handler.Text())
|
|
}
|
|
}
|
|
|
|
|
|
- path := fmt.Sprintf("%s://%s", r.Route.Method.Text(), r.Route.Path.Text())
|
|
|
|
- if _, ok := mainRouteMap[path]; ok {
|
|
|
|
|
|
+ p := fmt.Sprintf("%s://%s", r.Route.Method.Text(), path.Join(prefix, r.Route.Path.Text()))
|
|
|
|
+ if _, ok := mainRouteMap[p]; ok {
|
|
return fmt.Errorf("%s line %d:%d duplicate route '%s'",
|
|
return fmt.Errorf("%s line %d:%d duplicate route '%s'",
|
|
nestedApi.LinePrefix, r.Route.Method.Line(), r.Route.Method.Column(), r.Route.Method.Text()+" "+r.Route.Path.Text())
|
|
nestedApi.LinePrefix, r.Route.Method.Line(), r.Route.Method.Column(), r.Route.Method.Text()+" "+r.Route.Path.Text())
|
|
}
|
|
}
|