diff --git a/tools/goctl/api/parser/g4/ast/apiparser.go b/tools/goctl/api/parser/g4/ast/apiparser.go index 4b416976..890ba002 100644 --- a/tools/goctl/api/parser/g4/ast/apiparser.go +++ b/tools/goctl/api/parser/g4/ast/apiparser.go @@ -19,7 +19,6 @@ type ( linePrefix string debug bool log console.Console - src string skipCheckTypeDeclaration bool handlerMap map[string]PlaceHolder routeMap map[string]PlaceHolder @@ -88,30 +87,29 @@ func (p *Parser) Parse(filename string) (*Api, error) { return nil, err } - p.src = abs data, err := p.readContent(filename) if err != nil { return nil, err } - p.importStatck.push(p.src) + p.importStatck.push(abs) return p.parse(filename, data) } // ParseContent is used to parse the api from the specified content func (p *Parser) ParseContent(content string, filename ...string) (*Api, error) { - var f string + var f, abs string if len(filename) > 0 { f = filename[0] - abs, err := filepath.Abs(f) + a, err := filepath.Abs(f) if err != nil { return nil, err } - p.src = abs + abs = a } - p.importStatck.push(p.src) + p.importStatck.push(abs) return p.parse(f, content) } @@ -127,7 +125,7 @@ func (p *Parser) parse(filename, content string) (*Api, error) { apiAstList = append(apiAstList, root) p.storeVerificationInfo(root) p.syntax = root.Syntax - impApiAstList, err := p.invokeImportedApi(root.Import) + impApiAstList, err := p.invokeImportedApi(filename, root.Import) if err != nil { return nil, err } @@ -144,10 +142,10 @@ func (p *Parser) parse(filename, content string) (*Api, error) { return allApi, nil } -func (p *Parser) invokeImportedApi(imports []*ImportExpr) ([]*Api, error) { +func (p *Parser) invokeImportedApi(filename string, imports []*ImportExpr) ([]*Api, error) { var apiAstList []*Api for _, imp := range imports { - dir := filepath.Dir(p.src) + dir := filepath.Dir(filename) impPath := strings.ReplaceAll(imp.Value.Text(), "\"", "") if !filepath.IsAbs(impPath) { impPath = filepath.Join(dir, impPath) @@ -178,7 +176,7 @@ func (p *Parser) invokeImportedApi(imports []*ImportExpr) ([]*Api, error) { } p.storeVerificationInfo(nestedApi) apiAstList = append(apiAstList, nestedApi) - list, err := p.invokeImportedApi(nestedApi.Import) + list, err := p.invokeImportedApi(impPath, nestedApi.Import) p.importStatck.pop() apiAstList = append(apiAstList, list...) diff --git a/tools/goctl/api/tsgen/util.go b/tools/goctl/api/tsgen/util.go index 5d211717..eb737afa 100644 --- a/tools/goctl/api/tsgen/util.go +++ b/tools/goctl/api/tsgen/util.go @@ -114,7 +114,7 @@ func primitiveType(tp string) (string, bool) { switch tp { case "string": return "string", true - case "int", "int8", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64": + case "int", "int8","int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64": return "number", true case "float", "float32", "float64": return "number", true