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