github.skymusic.top/operator-framework/operator-sdk@v0.8.2/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  func newGenerateOpenAPICmd() *cobra.Command {
    25  	return &cobra.Command{
    26  		Use:   "openapi",
    27  		Short: "Generates OpenAPI specs for API's",
    28  		Long: `generate openapi generates OpenAPI validation specs in Go from tagged types
    29  in all pkg/apis/<group>/<version> directories. Go code is generated under
    30  pkg/apis/<group>/<version>/zz_generated.openapi.go. CRD's are generated, or
    31  updated if they exist for a particular group + version + kind, under
    32  deploy/crds/<group>_<version>_<kind>_crd.yaml; OpenAPI V3 validation YAML
    33  is generated as a 'validation' object.
    34  
    35  Example:
    36  	$ operator-sdk generate openapi
    37  	$ tree pkg/apis
    38  	pkg/apis/
    39  	└── app
    40  		└── v1alpha1
    41  			├── zz_generated.openapi.go
    42  	$ tree deploy/crds
    43  	├── deploy/crds/app_v1alpha1_appservice_cr.yaml
    44  	├── deploy/crds/app_v1alpha1_appservice_crd.yaml
    45  `,
    46  		RunE: openAPIFunc,
    47  	}
    48  }
    49  
    50  func openAPIFunc(cmd *cobra.Command, args []string) error {
    51  	if len(args) != 0 {
    52  		return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath())
    53  	}
    54  
    55  	return genutil.OpenAPIGen()
    56  }