-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (43 loc) · 2.44 KB
/
main.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
package main
import (
"flag"
"github.com/go-leo/gors/cmd/protoc-gen-gors/generator"
openapigenerator "github.com/go-leo/gors/cmd/protoc-gen-gors/protoc-gen-openapi/generator"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/pluginpb"
)
var flags flag.FlagSet
func main() {
conf := openapigenerator.Configuration{
Version: flags.String("version", "0.0.1", "version number text, e.g. 1.2.3"),
Title: flags.String("title", "", "name of the API"),
Description: flags.String("description", "", "description of the API"),
Naming: flags.String("naming", "json", `naming convention. Use "proto" for passing names directly from the proto files`),
FQSchemaNaming: flags.Bool("fq_schema_naming", false, `schema naming convention. If "true", generates fully-qualified schema names by prefixing them with the proto message package name`),
EnumType: flags.String("enum_type", "integer", `type for enum serialization. Use "string" for string-based serialization`),
CircularDepth: flags.Int("depth", 2, "depth of recursion for circular messages"),
DefaultResponse: flags.Bool("default_response", true, `add default response. If "true", automatically adds a default response to operations which use the google.rpc.Status message. Useful if you use envoy or grpc-gateway to transcode as they use this type for their default error responses.`),
OutputMode: flags.String("output_mode", "merged", `output generation mode. By default, a single openapi.yaml is generated at the out folder. Use "source_relative' to generate a separate '[inputfile].openapi.yaml' next to each '[inputfile].proto'.`),
}
generator.GrpcServer = flags.Bool("grpc_server", false, `add grpc server.`)
generator.GrpcClient = flags.Bool("grpc_client", false, `add grpc client.`)
opts := protogen.Options{
ParamFunc: flags.Set,
}
opts.Run(func(plugin *protogen.Plugin) error {
plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
for _, file := range plugin.Files {
if !file.Generate {
continue
}
filename := file.GeneratedFilenamePrefix + "_gors.pb.go"
outputFile := plugin.NewGeneratedFile(filename, file.GoImportPath)
openapiGenerator := openapigenerator.NewOpenAPIv3Generator(plugin, conf, []*protogen.File{file})
gen := generator.NewGenerator(plugin, file, outputFile, openapiGenerator)
if err := gen.Run(); err != nil {
return err
}
}
return nil
})
}