Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: generate openapi from grpc #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
version: v1

plugins:
# core apis
- name: go
out: rpc/flipt
opt:
- paths=source_relative
- Mgnostic/openapi/v3/annotations.proto=github.com/google/gnostic-models/openapiv3
strategy: all
- name: go-grpc
out: rpc/flipt
Expand All @@ -23,3 +25,12 @@ plugins:
- paths=source_relative
- grpc_api_configuration=rpc/flipt/flipt.yaml
strategy: all
- plugin: buf.build/community/google-gnostic-openapi
out: sdk
opt:
- version=1.47.0
- fq_schema_naming=false
- default_response=false
- title=api
- description=

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/flatbuffers v24.3.25+incompatible // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/pprof v0.0.0-20240509144519-723abb6459b7 // indirect
github.com/google/s2a-go v0.1.7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/flatbuffers v24.3.25+incompatible h1:CX395cjN9Kke9mmalRoL3d81AtFUxJM+yDthflgJGkI=
github.com/google/flatbuffers v24.3.25+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 h1:0VpGH+cDhbDtdcweoyCVsF3fhN8kejK6rFe/2FFX2nU=
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49/go.mod h1:BkkQ4L1KS1xMt2aWSPStnn55ChGC0DPOn2FQYj+f25M=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand Down
17 changes: 16 additions & 1 deletion internal/cmd/protoc-gen-go-flipt-sdk/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"google.golang.org/genproto/googleapis/api/serviceconfig"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"sigs.k8s.io/yaml"
)
Expand All @@ -32,6 +33,21 @@ func generateHTTP(gen *protogen.Plugin, grpcAPIConfig string) {
}

m := mappings{}

for _, f := range gen.Files {
if !f.Generate {
continue
}
for _, s := range f.Services {
for _, m := range s.Methods {
if rule := proto.GetExtension(m.Desc.Options(), annotations.E_Http).(*annotations.HttpRule); rule != nil {
rule.Selector = string(m.Desc.FullName())
config.Http.Rules = append(config.Http.Rules, rule)
}
}
}
}

for _, r := range config.Http.Rules {
rule := rule{
body: r.Body == "*",
Expand All @@ -53,7 +69,6 @@ func generateHTTP(gen *protogen.Plugin, grpcAPIConfig string) {
default:
fmt.Fprintf(os.Stderr, "unsupported pattern: %T\n", r.Pattern)
}

m[r.Selector] = rule
}

Expand Down
3 changes: 2 additions & 1 deletion rpc/flipt/analytics/analytics.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions rpc/flipt/analytics/analytics_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading