blob: 0f7563b10bf0ee9855f536f4151bfa4051a3ca05 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2018 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations 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
21package main
22
23import (
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
33func 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}