diff --git a/tools/goctl/api/gogen/gen_test.go b/tools/goctl/api/gogen/gen_test.go index 4241e117..927fa075 100644 --- a/tools/goctl/api/gogen/gen_test.go +++ b/tools/goctl/api/gogen/gen_test.go @@ -185,6 +185,25 @@ service A-api { } ` +const apiRouteTest = ` +type Request struct { + Name string ` + "`" + `path:"name,options=you|me"` + "`" + ` +} +type Response struct { + Message string ` + "`" + `json:"message"` + "`" + ` +} +service A-api { + @handler NormalHandler + get /greet/from/:name(Request) returns (Response) + @handler NoResponseHandler + get /greet/from/:sex(Request) + @handler NoRequestHandler + get /greet/from/request returns (Response) + @handler NoRequestNoResponseHandler + get /greet/from +} +` + func TestParser(t *testing.T) { filename := "greet.api" err := ioutil.WriteFile(filename, []byte(testApiTemplate), os.ModePerm) @@ -333,6 +352,21 @@ func TestApiHasNoRequestBody(t *testing.T) { validate(t, filename) } +func TestApiRoutes(t *testing.T) { + filename := "greet.api" + err := ioutil.WriteFile(filename, []byte(apiRouteTest), os.ModePerm) + assert.Nil(t, err) + defer os.Remove(filename) + + parser, err := parser.NewParser(filename) + assert.Nil(t, err) + + _, err = parser.Parse() + assert.Nil(t, err) + + validate(t, filename) +} + func validate(t *testing.T, api string) { dir := "_go" err := DoGenProject(api, dir, true) diff --git a/tools/goctl/api/gogen/util.go b/tools/goctl/api/gogen/util.go index 6068bcee..6550f297 100644 --- a/tools/goctl/api/gogen/util.go +++ b/tools/goctl/api/gogen/util.go @@ -28,6 +28,7 @@ func getParentPackage(dir string) (string, error) { } parent := filepath.Clean(goctlutil.JoinPackages(p.GoMod.Module, absPath[len(goModePath):])) parent = strings.ReplaceAll(parent, "\\", "/") + parent = strings.ReplaceAll(parent, `\`, "/") return parent, nil } diff --git a/tools/goctl/api/parser/servicestate.go b/tools/goctl/api/parser/servicestate.go index 59f5cdcc..025dcea4 100644 --- a/tools/goctl/api/parser/servicestate.go +++ b/tools/goctl/api/parser/servicestate.go @@ -70,6 +70,12 @@ func (p *serviceEntityParser) parseLine(line string, api *spec.ApiSpec, annos [] ch, _, err := reader.ReadRune() if err != nil { if err == io.EOF { + if builder.Len() > 0 { + token := strings.TrimSpace(builder.String()) + if len(token) > 0 && token != returnsTag { + fields = append(fields, token) + } + } break } return err diff --git a/tools/goctl/util/project/project.go b/tools/goctl/util/project/project.go index 82f91e0e..0ebb61b8 100644 --- a/tools/goctl/util/project/project.go +++ b/tools/goctl/util/project/project.go @@ -118,7 +118,7 @@ func Prepare(projectDir string, checkGrpcEnv bool) (*Project, error) { return &Project{ Name: name, Path: path, - Package: pkg, + Package: strings.ReplaceAll(pkg, `\`, "/"), IsInGoEnv: isInGoEnv, GoMod: GoMod{ Module: module,