Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix feedback from previous PR #459

Merged
merged 2 commits into from
Feb 27, 2024
Merged
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
2 changes: 1 addition & 1 deletion cmd/openapi-gen/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (args *Args) AddFlags(fs *pflag.FlagSet) {
"the name of the file to be generated")
fs.StringVar(&args.GoHeaderFile, "go-header-file", "",
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
fs.StringVarP(&args.ReportFilename, "report-filename", "r", "-",
fs.StringVarP(&args.ReportFilename, "report-filename", "r", args.ReportFilename,
"Name of report file used by API linter to print API violations. Default \"-\" stands for standard output. NOTE that if valid filename other than \"-\" is specified, API linter won't return error on detected API violations. This allows further check of existing API violations without stopping the OpenAPI generation toolchain.")
}

Expand Down
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
Loading