-
Notifications
You must be signed in to change notification settings - Fork 580
/
openapi.go
52 lines (43 loc) · 1.82 KB
/
openapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"github.com/openshift/api/tools/codegen/pkg/generation"
"github.com/openshift/api/tools/codegen/pkg/openapi"
"github.com/spf13/cobra"
)
var (
openapiHeaderFilePath string
openapiOutputFileBaseName string
openapiOutputPackagePath string
)
// openapiCmd represents the openapi command
var openapiCmd = &cobra.Command{
Use: "openapi",
Short: "openapi generates openapi schema for API types",
RunE: func(cmd *cobra.Command, args []string) error {
genCtx, err := generation.NewContext(generation.Options{
BaseDir: baseDir,
APIGroupVersions: apiGroupVersions,
})
if err != nil {
return fmt.Errorf("could not build generation context: %w", err)
}
gen := newOpenAPIGenerator()
return executeMultiGroupGenerators(genCtx, gen)
},
}
func init() {
rootCmd.AddCommand(openapiCmd)
rootCmd.PersistentFlags().StringVar(&openapiHeaderFilePath, "openapi:header-file-path", "", "Path to file containing boilerplate header text. The string YEAR will be replaced with the current 4-digit year. When omitted, no header is added to the generated files.")
rootCmd.PersistentFlags().StringVar(&openapiOutputFileBaseName, "openapi:output-file-base-name", openapi.DefaultOutputFileBaseName, "Base name of the output file. When omitted, zz_generated.openapi is used.")
rootCmd.PersistentFlags().StringVar(&openapiOutputPackagePath, "openapi:output-package-path", openapi.DefaultOutputPackagePath, "Package path where the generated golang files will be written.")
}
// newOpenAPIGenerator builds a new openapi generator.
func newOpenAPIGenerator() generation.MultiGroupGenerator {
return openapi.NewGenerator(openapi.Options{
HeaderFilePath: openapiHeaderFilePath,
OutputFileBaseName: openapiOutputFileBaseName,
OutputPackagePath: openapiOutputPackagePath,
Verify: verify,
})
}