Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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),
}
}
4 changes: 2 additions & 2 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 2 additions & 0 deletions app/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"

"github.com/spaceavocado/apidoc/extract"
"github.com/snezhana-dorogova/apidoc/extract"
)

// ExtractResult of the documentation extraction
Expand Down
2 changes: 1 addition & 1 deletion app/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

"github.com/spaceavocado/apidoc/extract"
"github.com/snezhana-dorogova/apidoc/extract"
)

type mockExtractor struct {
Expand Down
2 changes: 1 addition & 1 deletion app/subrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app
import (
"errors"

"github.com/spaceavocado/apidoc/token"
"github.com/snezhana-dorogova/apidoc/token"
)

type subrouter struct {
Expand Down
2 changes: 1 addition & 1 deletion app/subrouter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app
import (
"testing"

"github.com/spaceavocado/apidoc/token"
"github.com/snezhana-dorogova/apidoc/token"
)

func TestResolveSubrouters(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion app/tokenize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/tokenize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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")
Expand All @@ -25,6 +26,7 @@ func RootCmd() *cobra.Command {
}

app := app.New(app.Configuration{
DirPath: dirPath,
MainFile: mainFile,
EndsRoot: endsRoot,
Output: output,
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"fmt"

"github.com/spaceavocado/apidoc/app"
"github.com/snezhana-dorogova/apidoc/app"
"github.com/spf13/cobra"
)

Expand Down
6 changes: 3 additions & 3 deletions example/handler/person/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion output/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions output/openapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion output/openapi/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

// ...

Expand Down Expand Up @@ -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")
Expand Down
20 changes: 16 additions & 4 deletions reference/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion reference/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion token/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion token/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down