Skip to content

Commit 1550ae2

Browse files
authored
Upgrade protobuf and Generate OpenAPI v3 responseBody content examples (#242)
* Generate OpenAPI v3 responseBody content examples * Add google protobuf files * Fix protoc-gen-openapi plugin tests * Upgrade to newest protobuf versions * Upgrade github.com/golang/protobuf v1.5.1 -> v1.5.2 * Remove unnecessary path.Clean * Enable generation of properties name value of type Any This reverts the manual edit of OpenAPIv3.go and ensures that it is automatically generated. It also adds Value for NamedAny. * Add newly generated files The new formatting in .proto files is done by a generator * Move Google .proto files dir into "third_party" From ./google -> ./third_party/google Also add include path for protoc calls in: COMPILE-PROTOS.sh apps/protoc-gen-openapi/plugin_test.go * Manually patch OpenAPI v3 proto file and re-generate pb file This is needed to keep the original field numbers to maintain compatibility
1 parent ed30884 commit 1550ae2

37 files changed

Lines changed: 2715 additions & 262 deletions

COMPILE-PROTOS.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
go get github.com/golang/protobuf/protoc-gen-go
1919

20-
protoc --go_out=. openapiv2/OpenAPIv2.proto
21-
protoc --go_out=. openapiv3/OpenAPIv3.proto
22-
protoc --go_out=. discovery/discovery.proto
23-
protoc --go_out=. plugins/plugin.proto
24-
protoc --go_out=. extensions/extension.proto
25-
protoc --go_out=. surface/surface.proto
26-
protoc --go_out=. metrics/vocabulary.proto
27-
protoc --go_out=. metrics/complexity.proto
20+
protoc -I . -I ./third_party --go_out=. openapiv2/OpenAPIv2.proto
21+
protoc -I . -I ./third_party --go_out=. openapiv3/OpenAPIv3.proto
22+
protoc -I . -I ./third_party --go_out=. discovery/discovery.proto
23+
protoc -I . -I ./third_party --go_out=. plugins/plugin.proto
24+
protoc -I . -I ./third_party --go_out=. extensions/extension.proto
25+
protoc -I . -I ./third_party --go_out=. surface/surface.proto
26+
protoc -I . -I ./third_party --go_out=. metrics/vocabulary.proto
27+
protoc -I . -I ./third_party --go_out=. metrics/complexity.proto

apps/protoc-gen-openapi/plugin_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ func TestLibraryOpenAPI(t *testing.T) {
2424
var err error
2525
// Run protoc and the protoc-gen-openapi plugin to generate an OpenAPI spec.
2626
err = exec.Command("protoc",
27+
"-I", "../../",
28+
"-I", "../../third_party",
2729
"-I", "examples",
2830
"examples/google/example/library/v1/library.proto",
2931
"--openapi_out=.").Run()
@@ -45,6 +47,8 @@ func TestBodyMappingOpenAPI(t *testing.T) {
4547
var err error
4648
// Run protoc and the protoc-gen-openapi plugin to generate an OpenAPI spec.
4749
err = exec.Command("protoc",
50+
"-I", "../../",
51+
"-I", "../../third_party",
4852
"-I", "examples",
4953
"examples/tests/bodymapping/message.proto",
5054
"--openapi_out=.").Run()

discovery/discovery.pb.go

Lines changed: 11 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

discovery/discovery.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ option java_package = "org.discovery_v1";
4242
option objc_class_prefix = "OAS";
4343

4444
// The Go package name.
45-
option go_package = "discovery;discovery_v1";
45+
option go_package = "./discovery;discovery_v1";
4646

4747
message Annotations {
4848
repeated string required = 1;

extensions/extension.pb.go

Lines changed: 11 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/extension.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ option java_package = "org.gnostic.v1";
3838
// hopefully unique enough to not conflict with things that may come along in
3939
// the future. 'GPB' is reserved for the protocol buffer implementation itself.
4040
//
41-
option objc_class_prefix = "GNX"; // "Gnostic Extension"
41+
// "Gnostic Extension"
42+
option objc_class_prefix = "GNX";
4243

4344
// The Go package name.
44-
option go_package = "extensions;gnostic_extension_v1";
45+
option go_package = "./extensions;gnostic_extension_v1";
4546

4647
// The version number of Gnostic.
4748
message Version {

generate-gnostic/generate-compiler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ func (domain *Domain) generateToRawInfoMethodForType(code *printer.Code, typeNam
812812
}
813813
default:
814814
propertyName := propertyModel.Name
815-
if propertyName == "value" {
815+
if propertyName == "value" && propertyModel.Type != "Any" {
816816
code.Print("// %+v", propertyModel)
817817
} else if !propertyModel.Repeated {
818818
code.PrintIf(isRequired, "// always include this required field.")

generate-gnostic/generate-extension.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func generateExtension(schemaFile string, outDir string) error {
254254
},
255255
ProtoOption{
256256
Name: "go_package",
257-
Value: ".;" + strings.ToLower(protoPackage),
257+
Value: "./;" + strings.ToLower(protoPackage),
258258
Comment: "// The Go package path.",
259259
},
260260
)

generate-gnostic/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func protoOptions(directoryName string, packageName string) []ProtoOption {
8484

8585
ProtoOption{
8686
Name: "go_package",
87-
Value: directoryName + ";" + packageName,
87+
Value: "./" + directoryName + ";" + packageName,
8888
Comment: "// The Go package name.",
8989
},
9090
}

go.mod

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ module github.com/googleapis/gnostic
33
go 1.12
44

55
require (
6+
github.com/davecgh/go-spew v1.1.1
67
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
7-
github.com/gogo/protobuf v1.3.1
8-
github.com/golang/protobuf v1.4.3
8+
github.com/golang/protobuf v1.5.2
99
github.com/kr/pretty v0.2.0 // indirect
1010
github.com/stoewer/go-strcase v1.2.0
1111
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154
12-
google.golang.org/protobuf v1.24.0
12+
google.golang.org/protobuf v1.26.0
1313
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15
14-
gopkg.in/yaml.v2 v2.2.2
1514
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
1615
)

0 commit comments

Comments
 (0)