github.com/cbroglie/openapi2proto@v0.0.0-20171004221549-76b8501da882/cmd/openapi2proto/main.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"log"
     6  	"os"
     7  
     8  	"github.com/NYTimes/openapi2proto"
     9  )
    10  
    11  func main() {
    12  	specPath := flag.String("spec", "../../spec.yaml", "location of the swagger spec file")
    13  	annotate := flag.Bool("options", false, "include (google.api.http) options for grpc-gateway")
    14  	flag.Parse()
    15  
    16  	api, err := openapi2proto.LoadDefinition(*specPath)
    17  	if err != nil {
    18  		log.Fatal("unable to load spec: ", err)
    19  	}
    20  
    21  	out, err := openapi2proto.GenerateProto(api, *annotate)
    22  	if err != nil {
    23  		log.Fatal("unable to generate protobuf: ", err)
    24  	}
    25  
    26  	_, err = os.Stdout.Write(out)
    27  	if err != nil {
    28  		log.Fatal("unable to write output to stdout: ", err)
    29  	}
    30  }