Skip to content

Commit

Permalink
Use path instead of filepath
Browse files Browse the repository at this point in the history
Go package names always use '/', so does `path`
  • Loading branch information
thockin committed Feb 26, 2024
1 parent ee7ae60 commit df3ca11
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pkg/generators/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package generators

import (
"path/filepath"
"path"

"k8s.io/gengo/v2"
"k8s.io/gengo/v2/generator"
Expand Down Expand Up @@ -65,7 +65,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target

return []generator.Target{
&generator.SimpleTarget{
PkgName: filepath.Base(args.OutputPkg),
PkgName: path.Base(args.OutputPkg), // `path` vs. `filepath` because packages use '/'
PkgPath: args.OutputPkg,
PkgDir: args.OutputDir,
HeaderComment: boilerplate,
Expand Down
5 changes: 3 additions & 2 deletions pkg/generators/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"encoding/json"
"fmt"
"io"
"path/filepath"
"path"
"reflect"
"regexp"
"sort"
Expand Down Expand Up @@ -297,7 +297,8 @@ func hasOpenAPIV3OneOfMethod(t *types.Type) bool {

// typeShortName returns short package name (e.g. the name x appears in package x definition) dot type name.
func typeShortName(t *types.Type) string {
return filepath.Base(t.Name.Package) + "." + t.Name.Name
// `path` vs. `filepath` because packages use '/'
return path.Base(t.Name.Package) + "." + t.Name.Name
}

func (g openAPITypeWriter) generateMembers(t *types.Type, required []string) ([]string, error) {
Expand Down
7 changes: 4 additions & 3 deletions pkg/generators/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"bytes"
"fmt"
"go/format"
"path/filepath"
"path"
"strings"
"testing"

Expand All @@ -47,8 +47,9 @@ func construct(t *testing.T, cfg *packages.Config, nameSystems namer.NameSystems

func testOpenAPITypeWriter(t *testing.T, cfg *packages.Config) (error, error, *bytes.Buffer, *bytes.Buffer, []string) {
pkgBase := "example.com/base"
inputPkg := filepath.Join(pkgBase, "foo")
outputPkg := filepath.Join(pkgBase, "output")
// `path` vs. `filepath` because packages use '/'
inputPkg := path.Join(pkgBase, "foo")
outputPkg := path.Join(pkgBase, "output")
imports := generator.NewImportTrackerForPackage(outputPkg)
rawNamer := namer.NewRawNamer(outputPkg, imports)
namers := namer.NameSystems{
Expand Down
20 changes: 11 additions & 9 deletions test/integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package integration
import (
"os"
"os/exec"
"path"
"path/filepath"
"testing"

Expand Down Expand Up @@ -51,15 +52,16 @@ var (
openAPIGenPath string

inputDirs = []string{
filepath.Join(testPkgRoot, "listtype"),
filepath.Join(testPkgRoot, "maptype"),
filepath.Join(testPkgRoot, "structtype"),
filepath.Join(testPkgRoot, "dummytype"),
filepath.Join(testPkgRoot, "uniontype"),
filepath.Join(testPkgRoot, "enumtype"),
filepath.Join(testPkgRoot, "custom"),
filepath.Join(testPkgRoot, "valuevalidation"),
filepath.Join(testPkgRoot, "defaults"),
// `path` vs. `filepath` because packages use '/'
path.Join(testPkgRoot, "listtype"),
path.Join(testPkgRoot, "maptype"),
path.Join(testPkgRoot, "structtype"),
path.Join(testPkgRoot, "dummytype"),
path.Join(testPkgRoot, "uniontype"),
path.Join(testPkgRoot, "enumtype"),
path.Join(testPkgRoot, "custom"),
path.Join(testPkgRoot, "valuevalidation"),
path.Join(testPkgRoot, "defaults"),
}
)

Expand Down

0 comments on commit df3ca11

Please sign in to comment.