Skip to content

Commit

Permalink
Merge pull request #93 from Teamwork/chore/update-dependencies
Browse files Browse the repository at this point in the history
Chore: Update dependencies
  • Loading branch information
rafaeljusto authored Apr 27, 2023
2 parents ebbbc5b + a9e2866 commit 70a113f
Show file tree
Hide file tree
Showing 154 changed files with 82,049 additions and 390 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.17.x
- 1.20.x
go_import_path: github.com/teamwork/kommentaar
notifications:
email: false
Expand Down
15 changes: 8 additions & 7 deletions docparse/docparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"strconv"
"strings"

"github.com/teamwork/utils/goutil"
"github.com/teamwork/utils/sliceutil"
"github.com/teamwork/utils/stringutil"
"github.com/teamwork/utils/v2/goutil"
"github.com/teamwork/utils/v2/sliceutil"
"github.com/teamwork/utils/v2/stringutil"
)

// Program is the entire program: all collected endpoints and all collected
Expand Down Expand Up @@ -260,7 +260,7 @@ func parseComment(prog *Program, comment, pkgPath, filePath string) ([]*Endpoint
name = p.Name
}

if !sliceutil.InStringSlice(pp, name) {
if !sliceutil.Contains(pp, name) {
return nil, i, fmt.Errorf("parameter %q is not in the path %q",
name, e.Path)
}
Expand Down Expand Up @@ -460,12 +460,13 @@ var allMethods = []string{http.MethodGet, http.MethodHead, http.MethodPost,
http.MethodOptions, http.MethodTrace}

// Get the first "start line" of a documentation block:
// POST /path tag1 tag2
//
// POST /path tag1 tag2
//
// The tags are optional, and the method is case-sensitive.
func parseStartLine(line string) (string, string, []string) {
words := strings.Fields(line)
if len(words) < 2 || !sliceutil.InStringSlice(allMethods, words[0]) {
if len(words) < 2 || !sliceutil.Contains(allMethods, words[0]) {
return "", "", nil
}

Expand All @@ -489,7 +490,7 @@ func parseRefValue(prog *Program, context, value, filePath string) (*Ref, error)

// {keyword}
if value[0] == '{' && value[len(value)-1] == '}' {
if !sliceutil.InStringSlice(allRefs, value) {
if !sliceutil.Contains(allRefs, value) {
return nil, fmt.Errorf("invalid keyword: %q", value)
}

Expand Down
2 changes: 1 addition & 1 deletion docparse/docparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestParseComments(t *testing.T) {
stdResp := map[int]Response{200: Response{
stdResp := map[int]Response{200: {
ContentType: "application/json",
Body: &Ref{Description: "200 OK (no data)"},
}}
Expand Down
96 changes: 45 additions & 51 deletions docparse/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,62 @@ import (
"sort"
"strings"

"github.com/teamwork/utils/goutil"
"github.com/teamwork/utils/sliceutil"
"github.com/teamwork/utils/v2/goutil"
"github.com/teamwork/utils/v2/sliceutil"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"golang.org/x/tools/go/packages"
)

// FindComments finds all comments in the given paths or packages.
func FindComments(w io.Writer, prog *Program) error {
pkgPaths, err := goutil.Expand(prog.Config.Packages, build.FindOnly)
pkgs, err := goutil.Expand(prog.Config.Packages, packages.NeedName|packages.NeedFiles)
if err != nil {
return err
}

allErr := []error{}
for _, p := range pkgPaths {
fset := token.NewFileSet()
pkgs, err := parser.ParseDir(fset, p.Dir, nil, parser.ParseComments)
if err != nil {
return err

for _, pkg := range pkgs {
// Ignore test package.
if strings.HasSuffix(pkg.Name, "_test") {
continue
}

for _, pkg := range pkgs {
// Ignore test package.
if strings.HasSuffix(pkg.Name, "_test") {
for _, fullPath := range pkg.GoFiles {
// Print as just <pkgname>/<file> in errors instead of full path.
relPath := pkg.PkgPath + "/" + filepath.Base(fullPath)
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, fullPath, nil, parser.ParseComments)
if err != nil {
allErr = append(allErr, err)
continue
}

for fullPath, f := range pkg.Files {
// Print as just <pkgname>/<file> in errors instead of full path.
relPath := fullPath
if p.ImportPath == "." {
x := strings.Split(relPath, "/")
relPath = x[len(x)-2] + "/" + x[len(x)-1]
} else {
if i := strings.Index(relPath, p.ImportPath); i > -1 {
relPath = relPath[i:]
}
for _, c := range f.Comments {
e, relLine, err := parseComment(prog, c.Text(), pkg.PkgPath, fullPath)
if err != nil {
p := fset.Position(c.Pos())
allErr = append(allErr, fmt.Errorf("%v:%v %v",
relPath, p.Line+relLine, err))
continue
}

for _, c := range f.Comments {
e, relLine, err := parseComment(prog, c.Text(), p.ImportPath, fullPath)
if err != nil {
p := fset.Position(c.Pos())
allErr = append(allErr, fmt.Errorf("%v:%v %v",
relPath, p.Line+relLine, err))
continue
}
if e == nil || e[0] == nil {
continue
}
e[0].Pos = fset.Position(c.Pos())
e[0].End = fset.Position(c.End())

// Copy info from main endpoint to aliases.
for i, a := range e[1:] {
s := *e[0]
e[i+1] = &s
e[i+1].Path = a.Path
e[i+1].Method = a.Method
e[i+1].Tags = a.Tags
}

prog.Endpoints = append(prog.Endpoints, e...)
if e == nil || e[0] == nil {
continue
}
e[0].Pos = fset.Position(c.Pos())
e[0].End = fset.Position(c.End())

// Copy info from main endpoint to aliases.
for i, a := range e[1:] {
s := *e[0]
e[i+1] = &s
e[i+1].Path = a.Path
e[i+1].Method = a.Method
e[i+1].Tags = a.Tags
}

prog.Endpoints = append(prog.Endpoints, e...)
}
}
}
Expand Down Expand Up @@ -289,9 +283,9 @@ func (err ErrNotStruct) Error() string {
// References are stored in prog.References. This also finds and stores all
// nested references, so for:
//
// type Foo struct {
// Field Bar
// }
// type Foo struct {
// Field Bar
// }
//
// A GetReference("Foo", "") call will add two entries to prog.References: Foo
// and Bar (but only Foo is returned).
Expand Down Expand Up @@ -474,7 +468,7 @@ func GetReference(prog *Program, context string, isEmbed bool, lookup, filePath

// Add in embedded structs with a tag.
for _, n := range nestedTagged {
ename := strings.Title(goutil.TagName(n, tagName))
ename := cases.Title(language.English).String(goutil.TagName(n, tagName))
n.Names = []*ast.Ident{{
Name: ename,
}}
Expand Down Expand Up @@ -521,7 +515,7 @@ func GetReference(prog *Program, context string, isEmbed bool, lookup, filePath

fields := []*ast.Field{}
for _, field := range reference.Fields {
if sliceutil.InStringSlice(p.FieldWhitelist, strings.ToLower(field.Name)) {
if sliceutil.Contains(p.FieldWhitelist, strings.ToLower(field.Name)) {
fields = append(fields, field.KindField)
}
}
Expand Down
16 changes: 8 additions & 8 deletions docparse/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"encoding/json"
"fmt"
"go/ast"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/teamwork/utils/goutil"
"github.com/teamwork/utils/sliceutil"
"github.com/teamwork/utils/v2/goutil"
"github.com/teamwork/utils/v2/sliceutil"
yaml "gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -74,7 +74,7 @@ func structToSchema(prog *Program, name, tagName string, ref Reference) (*Schema
return nil, fmt.Errorf("cannot parse %v: %v", ref.Lookup, err)
}

if !sliceutil.InStringSlice([]string{"path", "query", "form"}, ref.Context) {
if !sliceutil.Contains([]string{"path", "query", "form"}, ref.Context) {
fixRequired(schema, prop)
}

Expand Down Expand Up @@ -587,9 +587,9 @@ arrayStart:
}

func isPrimitive(n string) bool {
//"null", "boolean", "object", "array", "number", "string", "integer",
return sliceutil.InStringSlice([]string{
"null", "boolean", "number", "string", "integer",
//"null", "boolean", "object", "array", "number", "string", "integer", "any"
return sliceutil.Contains([]string{
"null", "boolean", "number", "string", "integer", "any",
}, n)
}

Expand Down Expand Up @@ -670,7 +670,7 @@ func canonicalType(currentFile, pkgPath string, typ *ast.Ident) (ast.Expr, error
}

func readAndUnmarshalSchemaFile(path string, target interface{}) error {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("could not read file %q: %v", path, err)
}
Expand Down
18 changes: 13 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
module github.com/teamwork/kommentaar

go 1.12
go 1.20

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/imdario/mergo v0.3.13
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/teamwork/test v0.0.0-20181126061546-2ff8918eb6a4
github.com/teamwork/utils v0.0.0-20190114034940-d6a1f27ce92c
github.com/teamwork/test v0.0.0-20200108114543-02621bae84ad
github.com/teamwork/utils/v2 v2.0.1
golang.org/x/text v0.9.0
golang.org/x/tools v0.8.0
gopkg.in/yaml.v3 v3.0.1
zgo.at/sconfig v1.2.2-0.20211017232425-870f818a71b7
)

require (
github.com/Strum355/go-difflib v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/teamwork/utils v1.0.1-0.20230426101410-71bb0b003654 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.7.0 // indirect
)
23 changes: 17 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
github.com/Strum355/go-difflib v1.1.0 h1:+rR2X3UuvIbe1Jmhx8WA7gkgjMNRscFWbHchk2RB8I4=
github.com/Strum355/go-difflib v1.1.0/go.mod h1:r1cVg1JkGsTWkaR7At56v7hfuMgiUL8meTLwxFzOmvE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/teamwork/test v0.0.0-20181126061546-2ff8918eb6a4 h1:/ujiGN1Gf1yBNvRoXSn/c24mbyjQN+r3nXOKLXfUt+A=
github.com/teamwork/test v0.0.0-20181126061546-2ff8918eb6a4/go.mod h1:TIbx7tx6WHBjQeLRM4eWQZBL7kmBZ7/KI4x4v7Y5YmA=
github.com/teamwork/utils v0.0.0-20190114034940-d6a1f27ce92c h1:5/hkqtufOyLP25taIlo7BX9kLhw21unfjjdrOlwvFJk=
github.com/teamwork/utils v0.0.0-20190114034940-d6a1f27ce92c/go.mod h1:rmPaJUVv426LGg3QR31m1N0bfpCdCVyh3dCWsJTQeDA=
github.com/teamwork/test v0.0.0-20200108114543-02621bae84ad h1:25sEr0awm0ZPancg5W5H5VvN7PWsJloUBpii10a9isw=
github.com/teamwork/test v0.0.0-20200108114543-02621bae84ad/go.mod h1:TIbx7tx6WHBjQeLRM4eWQZBL7kmBZ7/KI4x4v7Y5YmA=
github.com/teamwork/utils v1.0.1-0.20230426101410-71bb0b003654 h1:5wExUHbkpsRWC1BiavI1nlvc12KFrF/EIn1d7WEbLO8=
github.com/teamwork/utils v1.0.1-0.20230426101410-71bb0b003654/go.mod h1:9GJXyhNsP6vGDt1oNW1Rt/Aj4+pWeT8BuUHFOF7lyrw=
github.com/teamwork/utils/v2 v2.0.1 h1:+tSO+Ll4XBMVzeTzmAtM5dswzSF0kb/d9dFdRXVMsFg=
github.com/teamwork/utils/v2 v2.0.1/go.mod h1:a2xpeXNKXYgxY/3UMMXhBy5SJ03dT7xRC0cNjwtkkc4=
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=
golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
2 changes: 1 addition & 1 deletion kconfig/kconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/teamwork/kommentaar/docparse"
"github.com/teamwork/kommentaar/html"
"github.com/teamwork/kommentaar/openapi2"
"github.com/teamwork/utils/goutil"
"github.com/teamwork/utils/v2/goutil"
"zgo.at/sconfig"
_ "zgo.at/sconfig/handlers/html/template" // template.HTML handler
)
Expand Down
2 changes: 1 addition & 1 deletion openapi2/openapi2.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/imdario/mergo"
"github.com/teamwork/kommentaar/docparse"
"github.com/teamwork/utils/goutil"
"github.com/teamwork/utils/v2/goutil"
yaml "gopkg.in/yaml.v3"
)

Expand Down
Loading

0 comments on commit 70a113f

Please sign in to comment.