diff --git a/app/app.go b/app/app.go index 2649126..e56048e 100644 --- a/app/app.go +++ b/app/app.go @@ -5,11 +5,11 @@ import ( "path/filepath" log "github.com/sirupsen/logrus" - "github.com/spaceavocado/apidoc/extract" - "github.com/spaceavocado/apidoc/output" - "github.com/spaceavocado/apidoc/output/openapi" - "github.com/spaceavocado/apidoc/reference" - "github.com/spaceavocado/apidoc/token" + "github.com/snezhana-dorogova/apidoc/extract" + "github.com/snezhana-dorogova/apidoc/output" + "github.com/snezhana-dorogova/apidoc/output/openapi" + "github.com/snezhana-dorogova/apidoc/reference" + "github.com/snezhana-dorogova/apidoc/token" ) const ( @@ -76,7 +76,7 @@ func New(c Configuration) App { conf: &c, extractor: extract.NewExtractor(c.Verbose), tokenParser: token.NewParser(c.Verbose), - refResolver: reference.NewResolver(c.Verbose), + refResolver: reference.NewResolver(c.Verbose, c.DirPath), generator: openapi.NewGenerator(c.Verbose), } } diff --git a/app/app_test.go b/app/app_test.go index d87b077..38de031 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -10,8 +10,8 @@ import ( log "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" - "github.com/spaceavocado/apidoc/extract" - "github.com/spaceavocado/apidoc/token" + "github.com/snezhana-dorogova/apidoc/extract" + "github.com/snezhana-dorogova/apidoc/token" ) type errorResolver struct{} diff --git a/app/conf.go b/app/conf.go index 4924709..ed49729 100644 --- a/app/conf.go +++ b/app/conf.go @@ -2,6 +2,8 @@ package app // Configuration of the app type Configuration struct { + // Project directory + DirPath string // Main documentation file MainFile string // Endpoints root folder diff --git a/app/extract.go b/app/extract.go index e4d1b71..dcfdcd4 100644 --- a/app/extract.go +++ b/app/extract.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/spaceavocado/apidoc/extract" + "github.com/snezhana-dorogova/apidoc/extract" ) // ExtractResult of the documentation extraction diff --git a/app/extract_test.go b/app/extract_test.go index a41e7ee..27597dc 100644 --- a/app/extract_test.go +++ b/app/extract_test.go @@ -6,7 +6,7 @@ import ( "os" "testing" - "github.com/spaceavocado/apidoc/extract" + "github.com/snezhana-dorogova/apidoc/extract" ) type mockExtractor struct { diff --git a/app/subrouter.go b/app/subrouter.go index 6fb06da..4db701b 100644 --- a/app/subrouter.go +++ b/app/subrouter.go @@ -3,7 +3,7 @@ package app import ( "errors" - "github.com/spaceavocado/apidoc/token" + "github.com/snezhana-dorogova/apidoc/token" ) type subrouter struct { diff --git a/app/subrouter_test.go b/app/subrouter_test.go index 6a90459..4f833d8 100644 --- a/app/subrouter_test.go +++ b/app/subrouter_test.go @@ -3,7 +3,7 @@ package app import ( "testing" - "github.com/spaceavocado/apidoc/token" + "github.com/snezhana-dorogova/apidoc/token" ) func TestResolveSubrouters(t *testing.T) { diff --git a/app/tokenize.go b/app/tokenize.go index 55a4247..ed2b9fd 100644 --- a/app/tokenize.go +++ b/app/tokenize.go @@ -4,7 +4,7 @@ import ( "fmt" log "github.com/sirupsen/logrus" - "github.com/spaceavocado/apidoc/token" + "github.com/snezhana-dorogova/apidoc/token" ) // RequiredMainTokens to be present in the main block diff --git a/app/tokenize_test.go b/app/tokenize_test.go index 43a1d15..34516fa 100644 --- a/app/tokenize_test.go +++ b/app/tokenize_test.go @@ -7,8 +7,8 @@ import ( log "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" - "github.com/spaceavocado/apidoc/extract" - "github.com/spaceavocado/apidoc/token" + "github.com/snezhana-dorogova/apidoc/extract" + "github.com/snezhana-dorogova/apidoc/token" ) type mockParser struct { diff --git a/cmd/root.go b/cmd/root.go index 1d8b666..c92e0cc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,7 +4,7 @@ package cmd import ( log "github.com/sirupsen/logrus" - "github.com/spaceavocado/apidoc/app" + "github.com/snezhana-dorogova/apidoc/app" "github.com/spf13/cobra" ) @@ -15,6 +15,7 @@ func RootCmd() *cobra.Command { Long: "API Documentation Generator", Run: func(c *cobra.Command, args []string) { log.Infof("%s (%s)", c.Long, app.Version) + dirPath, err := c.PersistentFlags().GetString("dir") mainFile, err := c.PersistentFlags().GetString("main") endsRoot, err := c.PersistentFlags().GetString("endpoints") output, err := c.PersistentFlags().GetString("output") @@ -25,6 +26,7 @@ func RootCmd() *cobra.Command { } app := app.New(app.Configuration{ + DirPath: dirPath, MainFile: mainFile, EndsRoot: endsRoot, Output: output, @@ -35,6 +37,7 @@ func RootCmd() *cobra.Command { } // Flags + rootCmd.PersistentFlags().StringP("dir", "d", "./", "") rootCmd.PersistentFlags().StringP("main", "m", "main.go", "Main API documentation file") rootCmd.PersistentFlags().StringP("endpoints", "e", "./", "Root endpoints folder") rootCmd.PersistentFlags().StringP("output", "o", "docs/api", "Documentation output folder") diff --git a/cmd/version.go b/cmd/version.go index 85616a2..f75f705 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -3,7 +3,7 @@ package cmd import ( "fmt" - "github.com/spaceavocado/apidoc/app" + "github.com/snezhana-dorogova/apidoc/app" "github.com/spf13/cobra" ) diff --git a/example/handler/person/person.go b/example/handler/person/person.go index 8295a04..02c62b6 100644 --- a/example/handler/person/person.go +++ b/example/handler/person/person.go @@ -5,10 +5,10 @@ import ( "net/http" "github.com/gorilla/mux" - "github.com/spaceavocado/apidoc/example/request" - "github.com/spaceavocado/apidoc/example/response" + "github.com/snezhana-dorogova/apidoc/example/request" + "github.com/snezhana-dorogova/apidoc/example/response" // Common respose, structs referenced in the API documentation - _ "github.com/spaceavocado/apidoc/example/common" + _ "github.com/snezhana-dorogova/apidoc/example/common" ) // Person response model diff --git a/example/main.go b/example/main.go index 3b48edd..fb2991e 100644 --- a/example/main.go +++ b/example/main.go @@ -6,7 +6,7 @@ import ( "time" "github.com/gorilla/mux" - "github.com/spaceavocado/apidoc/example/handler/person" + "github.com/snezhana-dorogova/apidoc/example/handler/person" ) // @title Example API diff --git a/main.go b/main.go index 643453b..a34ca4f 100644 --- a/main.go +++ b/main.go @@ -9,8 +9,8 @@ package main import ( log "github.com/sirupsen/logrus" - "github.com/spaceavocado/apidoc/cmd" - "github.com/spaceavocado/apidoc/misc" + "github.com/snezhana-dorogova/apidoc/cmd" + "github.com/snezhana-dorogova/apidoc/misc" ) func main() { diff --git a/output/generator.go b/output/generator.go index 5a12a59..77fb743 100644 --- a/output/generator.go +++ b/output/generator.go @@ -2,7 +2,7 @@ // from the tokenized outcome. package output -import "github.com/spaceavocado/apidoc/token" +import "github.com/snezhana-dorogova/apidoc/token" // Generator of the documentation type Generator interface { diff --git a/output/openapi/generator.go b/output/openapi/generator.go index 39ef3c8..3d2ebfc 100644 --- a/output/openapi/generator.go +++ b/output/openapi/generator.go @@ -10,9 +10,9 @@ import ( "strings" log "github.com/sirupsen/logrus" - "github.com/spaceavocado/apidoc/misc" - "github.com/spaceavocado/apidoc/output" - "github.com/spaceavocado/apidoc/token" + "github.com/snezhana-dorogova/apidoc/misc" + "github.com/snezhana-dorogova/apidoc/output" + "github.com/snezhana-dorogova/apidoc/token" ) type generator struct { diff --git a/output/openapi/generator_test.go b/output/openapi/generator_test.go index 6784805..f922bb2 100644 --- a/output/openapi/generator_test.go +++ b/output/openapi/generator_test.go @@ -9,7 +9,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" - "github.com/spaceavocado/apidoc/token" + "github.com/snezhana-dorogova/apidoc/token" ) func TestGenerate(t *testing.T) { diff --git a/readme.md b/readme.md index 407860f..71a3f03 100644 --- a/readme.md +++ b/readme.md @@ -481,7 +481,7 @@ An endpoint, with the same URL could be declared separately with different metho // @param id path {int} true User ID // @produce text // @success 200 {string} OK -// @router /user/{id} [post] +// @router /user/{id} [get] // ... @@ -542,6 +542,7 @@ Available Commands: version Show the APIDoc version Flags: + -d, --dir string Vendor directory path (default "./") -e, --endpoints string Root endpoints folder (default "./") -h, --help Help for this command -m, --main string Main API documentation file (default "main.go") diff --git a/reference/resolver.go b/reference/resolver.go index 5bddf2f..e7389f1 100644 --- a/reference/resolver.go +++ b/reference/resolver.go @@ -12,7 +12,7 @@ import ( "strings" log "github.com/sirupsen/logrus" - "github.com/spaceavocado/apidoc/extract" + "github.com/snezhana-dorogova/apidoc/extract" ) // Resolver of references @@ -154,11 +154,23 @@ func (r *resolver) Resolve(endpoints []extract.Block) error { } // Updated the lines with the resolved enriched lines - endpoints[i].Lines = resolved + endpoints[i].Lines = unique(resolved) } return nil } +func unique(inputSlice []string) []string { + keys := make(map[string]bool) + res := []string{} + for _, entry := range inputSlice { + if _, value := keys[entry]; !value { + keys[entry] = true + res = append(res, entry) + } + } + return res +} + // HasExpectedPrefix returns the detected // expected prefix it the form of its output mapping func (r *resolver) HasExpectedPrefix(line string) mappingType { @@ -511,10 +523,10 @@ func (r *resolver) ParseFile(pkg, file string) error { } // NewResolver instance -func NewResolver(verbose bool) Resolver { +func NewResolver(verbose bool, dir string) Resolver { return &resolver{ verbose: verbose, - gopath: filepath.Join(os.Getenv("GOPATH"), "src"), + gopath: filepath.Join(dir, "vendor"), builtinTypes: []string{"bool", "string", "int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64", "uintptr", "byte", "rune", "float32", "float64", "complex64", "complex128", "object"}, packages: make(map[string]map[string]resolvedFile, 0), types: make(map[string][]string, 0), diff --git a/reference/resolver_test.go b/reference/resolver_test.go index d775641..12cad51 100644 --- a/reference/resolver_test.go +++ b/reference/resolver_test.go @@ -10,7 +10,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" - "github.com/spaceavocado/apidoc/extract" + "github.com/snezhana-dorogova/apidoc/extract" ) func TestResolve(t *testing.T) { diff --git a/token/parser.go b/token/parser.go index aa0df1e..6c9355a 100644 --- a/token/parser.go +++ b/token/parser.go @@ -8,7 +8,7 @@ import ( "strings" log "github.com/sirupsen/logrus" - "github.com/spaceavocado/apidoc/extract" + "github.com/snezhana-dorogova/apidoc/extract" ) // ErrParsing is soft error not causing the failure diff --git a/token/parser_test.go b/token/parser_test.go index f547330..2b5dcba 100644 --- a/token/parser_test.go +++ b/token/parser_test.go @@ -8,7 +8,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/test" - "github.com/spaceavocado/apidoc/extract" + "github.com/snezhana-dorogova/apidoc/extract" ) func TestParse(t *testing.T) {