From df3ca113a05d017cd143f1c84933219b1fdcd566 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Mon, 26 Feb 2024 15:40:40 -0800 Subject: [PATCH 1/2] Use `path` instead of `filepath` Go package names always use '/', so does `path` --- pkg/generators/config.go | 4 ++-- pkg/generators/openapi.go | 5 +++-- pkg/generators/openapi_test.go | 7 ++++--- test/integration/integration_suite_test.go | 20 +++++++++++--------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pkg/generators/config.go b/pkg/generators/config.go index 098d400a6..1fbd77598 100644 --- a/pkg/generators/config.go +++ b/pkg/generators/config.go @@ -17,7 +17,7 @@ limitations under the License. package generators import ( - "path/filepath" + "path" "k8s.io/gengo/v2" "k8s.io/gengo/v2/generator" @@ -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, diff --git a/pkg/generators/openapi.go b/pkg/generators/openapi.go index f70b6748d..743f5b8b2 100644 --- a/pkg/generators/openapi.go +++ b/pkg/generators/openapi.go @@ -21,7 +21,7 @@ import ( "encoding/json" "fmt" "io" - "path/filepath" + "path" "reflect" "regexp" "sort" @@ -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) { diff --git a/pkg/generators/openapi_test.go b/pkg/generators/openapi_test.go index 82b321969..3fa753d14 100644 --- a/pkg/generators/openapi_test.go +++ b/pkg/generators/openapi_test.go @@ -20,7 +20,7 @@ import ( "bytes" "fmt" "go/format" - "path/filepath" + "path" "strings" "testing" @@ -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{ diff --git a/test/integration/integration_suite_test.go b/test/integration/integration_suite_test.go index a49b0765a..3285c4c99 100644 --- a/test/integration/integration_suite_test.go +++ b/test/integration/integration_suite_test.go @@ -19,6 +19,7 @@ package integration import ( "os" "os/exec" + "path" "path/filepath" "testing" @@ -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"), } ) From cfb2b85231d629611994953b70459b7303ce2849 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Mon, 26 Feb 2024 15:44:36 -0800 Subject: [PATCH 2/2] xref already defaulted field vs. a literal --- cmd/openapi-gen/args/args.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/openapi-gen/args/args.go b/cmd/openapi-gen/args/args.go index d53282b7a..153784ed9 100644 --- a/cmd/openapi-gen/args/args.go +++ b/cmd/openapi-gen/args/args.go @@ -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.") }