github.com/mkimuram/operator-sdk@v0.7.1-0.20190410172100-52ad33a4bda0/cmd/operator-sdk/generate/openapi.go (about) 1 // Copyright 2019 The Operator-SDK Authors 2 // 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 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package generate 16 17 import ( 18 "fmt" 19 20 "github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil" 21 "github.com/spf13/cobra" 22 ) 23 24 var headerFile string 25 26 func newGenerateOpenAPICmd() *cobra.Command { 27 openAPICmd := &cobra.Command{ 28 Use: "openapi", 29 Short: "Generates OpenAPI specs for API's", 30 Long: `generate openapi generates OpenAPI validation specs in Go from tagged types 31 in all pkg/apis/<group>/<version> directories. Go code is generated under 32 pkg/apis/<group>/<version>/zz_generated.openapi.go. CRD's are generated, or 33 updated if they exist for a particular group + version + kind, under 34 deploy/crds/<group>_<version>_<kind>_crd.yaml; OpenAPI V3 validation YAML 35 is generated as a 'validation' object. 36 37 Example: 38 $ operator-sdk generate openapi 39 $ tree pkg/apis 40 pkg/apis/ 41 └── app 42 └── v1alpha1 43 ├── zz_generated.openapi.go 44 $ tree deploy/crds 45 ├── deploy/crds/app_v1alpha1_appservice_cr.yaml 46 ├── deploy/crds/app_v1alpha1_appservice_crd.yaml 47 `, 48 RunE: openAPIFunc, 49 } 50 51 openAPICmd.Flags().StringVar(&headerFile, "header-file", "", "Path to file containing headers for generated files.") 52 53 return openAPICmd 54 } 55 56 func openAPIFunc(cmd *cobra.Command, args []string) error { 57 if len(args) != 0 { 58 return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath()) 59 } 60 61 return genutil.OpenAPIGen(headerFile) 62 }