openapi-gen.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // This package generates openAPI definition file to be used in open API spec generation on API servers. To generate
  14. // definition for a specific type or package add "+k8s:openapi-gen=true" tag to the type/package comment lines. To
  15. // exclude a type from a tagged package, add "+k8s:openapi-gen=false" tag to the type comment lines.
  16. package main
  17. import (
  18. "flag"
  19. "log"
  20. generatorargs "k8s.io/kube-openapi/cmd/openapi-gen/args"
  21. "k8s.io/kube-openapi/pkg/generators"
  22. "github.com/spf13/pflag"
  23. "k8s.io/klog"
  24. )
  25. func main() {
  26. klog.InitFlags(nil)
  27. genericArgs, customArgs := generatorargs.NewDefaults()
  28. genericArgs.AddFlags(pflag.CommandLine)
  29. customArgs.AddFlags(pflag.CommandLine)
  30. flag.Set("logtostderr", "true")
  31. pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
  32. pflag.Parse()
  33. if err := generatorargs.Validate(genericArgs); err != nil {
  34. log.Fatalf("Arguments validation error: %v", err)
  35. }
  36. // Generates the code for the OpenAPIDefinitions.
  37. if err := genericArgs.Execute(
  38. generators.NameSystems(),
  39. generators.DefaultNameSystem(),
  40. generators.Packages,
  41. ); err != nil {
  42. log.Fatalf("OpenAPI code generation error: %v", err)
  43. }
  44. }