mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Move openapi output to a flag rather than tag
This commit is contained in:
parent
d3e3a5a929
commit
bd9c04cf5d
@ -296,6 +296,7 @@ $(DEEPCOPY_GEN):
|
|||||||
# The result file, in each pkg, of open-api generation.
|
# The result file, in each pkg, of open-api generation.
|
||||||
OPENAPI_BASENAME := $(GENERATED_FILE_PREFIX)openapi
|
OPENAPI_BASENAME := $(GENERATED_FILE_PREFIX)openapi
|
||||||
OPENAPI_FILENAME := $(OPENAPI_BASENAME).go
|
OPENAPI_FILENAME := $(OPENAPI_BASENAME).go
|
||||||
|
OPENAPI_OUTPUT_PKG := pkg/generated/openapi
|
||||||
|
|
||||||
# The tool used to generate open apis.
|
# The tool used to generate open apis.
|
||||||
OPENAPI_GEN := $(BIN_DIR)/openapi-gen
|
OPENAPI_GEN := $(BIN_DIR)/openapi-gen
|
||||||
@ -321,6 +322,7 @@ gen_openapi: $(OPENAPI_FILES)
|
|||||||
--v $(KUBE_VERBOSE) \
|
--v $(KUBE_VERBOSE) \
|
||||||
--logtostderr \
|
--logtostderr \
|
||||||
-i $$(cat $(META_DIR)/$(OPENAPI_GEN).todo | paste -sd, -) \
|
-i $$(cat $(META_DIR)/$(OPENAPI_GEN).todo | paste -sd, -) \
|
||||||
|
-p $(PRJ_SRC_PATH)/$(OPENAPI_OUTPUT_PKG) \
|
||||||
-O $(OPENAPI_BASENAME); \
|
-O $(OPENAPI_BASENAME); \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
"k8s.io/gengo/namer"
|
"k8s.io/gengo/namer"
|
||||||
"k8s.io/gengo/types"
|
"k8s.io/gengo/types"
|
||||||
"k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
|
"k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
|
||||||
"k8s.io/kubernetes/pkg/util/sets"
|
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
@ -42,8 +41,6 @@ const tagName = "k8s:openapi-gen"
|
|||||||
const (
|
const (
|
||||||
tagValueTrue = "true"
|
tagValueTrue = "true"
|
||||||
tagValueFalse = "false"
|
tagValueFalse = "false"
|
||||||
// Should only be used only for test
|
|
||||||
tagTargetType = "target"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func hasOpenAPITagValue(comments []string, value string) bool {
|
func hasOpenAPITagValue(comments []string, value string) bool {
|
||||||
@ -77,7 +74,6 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed loading boilerplate: %v", err)
|
glog.Fatalf("Failed loading boilerplate: %v", err)
|
||||||
}
|
}
|
||||||
inputs := sets.NewString(context.Inputs...)
|
|
||||||
header := append([]byte(fmt.Sprintf("// +build !%s\n\n", arguments.GeneratedBuildTag)), boilerplate...)
|
header := append([]byte(fmt.Sprintf("// +build !%s\n\n", arguments.GeneratedBuildTag)), boilerplate...)
|
||||||
header = append(header, []byte(
|
header = append(header, []byte(
|
||||||
`
|
`
|
||||||
@ -85,32 +81,20 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
|
|
||||||
`)...)
|
`)...)
|
||||||
|
|
||||||
targets := []*types.Package{}
|
if err := context.AddDir(arguments.OutputPackagePath); err != nil {
|
||||||
for i := range inputs {
|
glog.Fatalf("Failed to load output package: %v", err)
|
||||||
glog.V(5).Infof("considering pkg %q", i)
|
|
||||||
pkg, ok := context.Universe[i]
|
|
||||||
if !ok {
|
|
||||||
// If the input had no Go files, for example.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if hasOpenAPITagValue(pkg.Comments, tagTargetType) || hasOpenAPITagValue(pkg.DocComments, tagTargetType) {
|
|
||||||
glog.V(5).Infof("target package : %q", pkg)
|
|
||||||
targets = append(targets, pkg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch len(targets) {
|
pkg := context.Universe[arguments.OutputPackagePath]
|
||||||
case 0:
|
if pkg == nil {
|
||||||
// If no target package found, that means the generated file in target package is up to date
|
glog.Fatalf("Got nil output package: %v", err)
|
||||||
// and build excluded the target package.
|
}
|
||||||
return generator.Packages{}
|
return generator.Packages{
|
||||||
case 1:
|
&generator.DefaultPackage{
|
||||||
pkg := targets[0]
|
|
||||||
return generator.Packages{&generator.DefaultPackage{
|
|
||||||
PackageName: strings.Split(filepath.Base(pkg.Path), ".")[0],
|
PackageName: strings.Split(filepath.Base(pkg.Path), ".")[0],
|
||||||
PackagePath: pkg.Path,
|
PackagePath: pkg.Path,
|
||||||
HeaderText: header,
|
HeaderText: header,
|
||||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||||
return []generator.Generator{NewOpenAPIGen(arguments.OutputFileBaseName, targets[0], context)}
|
return []generator.Generator{NewOpenAPIGen(arguments.OutputFileBaseName, pkg, context)}
|
||||||
},
|
},
|
||||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||||
// There is a conflict between this codegen and codecgen, we should avoid types generated for codecgen
|
// There is a conflict between this codegen and codecgen, we should avoid types generated for codecgen
|
||||||
@ -127,9 +111,6 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
|
||||||
default:
|
|
||||||
glog.Fatalf("Duplicate target type found: %v", targets)
|
|
||||||
}
|
}
|
||||||
return generator.Packages{}
|
return generator.Packages{}
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,4 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// openapi generated definitions.
|
// openapi generated definitions.
|
||||||
// +k8s:openapi-gen=target
|
|
||||||
package openapi
|
package openapi
|
||||||
|
Loading…
Reference in New Issue
Block a user