From 2c21881cd78ac23adf83242219db1ad592ea9363 Mon Sep 17 00:00:00 2001 From: Franz Wilhelm von der Lippe Date: Fri, 19 Oct 2018 14:47:54 +0200 Subject: [PATCH] Enable doc generation outside of gopath --- generate/swaggergen/g_docs.go | 17 +++++++++++++---- main.go | 4 +--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index 71c13bd..18cc840 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -418,6 +418,11 @@ func analyseNSInclude(baseurl string, ce *ast.CallExpr) string { return cname } +// +func trimGithubPrefix(fullpath string) string { + return strings.Join(strings.Split(fullpath, "/")[3:], "/") +} + func analyseControllerPkg(vendorPath, localName, pkgpath string) { pkgpath = strings.Trim(pkgpath, "\"") if isSystemPackage(pkgpath) { @@ -433,12 +438,9 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) { importlist[pps[len(pps)-1]] = pkgpath } gopaths := bu.GetGOPATHs() - if len(gopaths) == 0 { - beeLogger.Log.Fatal("GOPATH environment variable is not set or empty") - } pkgRealpath := "" - wg, _ := filepath.EvalSymlinks(filepath.Join(vendorPath, pkgpath)) + wd, _ := os.Getwd() if utils.FileExists(wg) { pkgRealpath = wg } else { @@ -448,6 +450,13 @@ func analyseControllerPkg(vendorPath, localName, pkgpath string) { if utils.FileExists(wg) { pkgRealpath = wg break + } else { + trimmed := trimGithubPrefix(pkgpath) + wg, _ = filepath.EvalSymlinks(filepath.Join(wd, trimmed)) + if utils.FileExists(wg) { + pkgRealpath = wg + break + } } } } diff --git a/main.go b/main.go index ef51e0d..f2adf4d 100644 --- a/main.go +++ b/main.go @@ -67,9 +67,7 @@ func main() { config.LoadConfig() - // Check if current directory is inside the GOPATH, - // if so parse the packages inside it. - if utils.IsInGOPATH(currentpath) && cmd.IfGenerateDocs(c.Name(), args) { + if cmd.IfGenerateDocs(c.Name(), args) { swaggergen.ParsePackagesFromDir(currentpath) } os.Exit(c.Run(c, args))