-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[protobuf-schema] Use snake_case for protobuf fields, UPPER_SNAKE_CAS…
…E for enums. (#20696) * protobuf enum prefix use upper underscore Add json name parameters and change parameter field name to snake case * rerun generate-samples.sh * Add CI test * rebase master --------- Co-authored-by: xil <[email protected]>
- Loading branch information
1 parent
90de8dc
commit c96d308
Showing
27 changed files
with
637 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Samples Protobuf | ||
on: | ||
push: | ||
paths: | ||
- .github/workflows/samples-protobuf.yaml | ||
- samples/config/petstore/protobuf-schema/** | ||
- samples/config/petstore/protobuf-schema-config/** | ||
pull_request: | ||
paths: | ||
- .github/workflows/samples-protobuf.yaml | ||
- samples/config/petstore/protobuf-schema/** | ||
- samples/config/petstore/protobuf-schema-config/** | ||
jobs: | ||
build: | ||
name: Build Protobuf Client | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
sample: | ||
- 'samples/config/petstore/protobuf-schema/' | ||
- 'samples/config/petstore/protobuf-schema-config/' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Protocol Buffers Compiler | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y protobuf-compiler | ||
- name: Generate Protobuf Schema | ||
working-directory: ${{ matrix.sample }} | ||
run: | | ||
mkdir out | ||
protoc --proto_path=. --cpp_out=out models/*.proto services/*.proto | ||
- name: Verify Generated Files | ||
working-directory: ${{ matrix.sample }} | ||
run: | | ||
ls -l out/models | ||
ls -l out/services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
generatorName: protobuf-schema | ||
outputDir: samples/config/petstore/protobuf-schema-config | ||
inputSpec: modules/openapi-generator/src/test/resources/3_0/protobuf/petstore.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/protobuf-schema | ||
additionalProperties: | ||
packageName: petstore | ||
addJsonNameAnnotation: true | ||
numberedFieldNumberList: true | ||
startEnumsWithUnspecified: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
samples/config/petstore/protobuf-schema-config/.openapi-generator-ignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
11 changes: 11 additions & 0 deletions
11
samples/config/petstore/protobuf-schema-config/.openapi-generator/FILES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
README.md | ||
models/api_response.proto | ||
models/category.proto | ||
models/order.proto | ||
models/other_test.proto | ||
models/pet.proto | ||
models/tag.proto | ||
models/user.proto | ||
services/pet_service.proto | ||
services/store_service.proto | ||
services/user_service.proto |
1 change: 1 addition & 0 deletions
1
samples/config/petstore/protobuf-schema-config/.openapi-generator/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.13.0-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# gPRC for petstore | ||
|
||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. | ||
|
||
## Overview | ||
These files were generated by the [OpenAPI Generator](https://openapi-generator.tech) project. | ||
|
||
- API version: 1.0.0 | ||
- Package version: | ||
- Generator version: 7.13.0-SNAPSHOT | ||
- Build package: org.openapitools.codegen.languages.ProtobufSchemaCodegen | ||
|
||
## Usage | ||
|
||
Below are some usage examples for Go and Ruby. For other languages, please refer to https://grpc.io/docs/quickstart/. | ||
|
||
### Go | ||
``` | ||
# assuming `protoc-gen-go` has been installed with `go get -u github.com/golang/protobuf/protoc-gen-go` | ||
mkdir /var/tmp/go/petstore | ||
protoc --go_out=/var/tmp/go/petstore services/* | ||
protoc --go_out=/var/tmp/go/petstore models/* | ||
``` | ||
|
||
### Ruby | ||
``` | ||
# assuming `grpc_tools_ruby_protoc` has been installed via `gem install grpc-tools` | ||
RUBY_OUTPUT_DIR="/var/tmp/ruby/petstore" | ||
mkdir $RUBY_OUTPUT_DIR | ||
grpc_tools_ruby_protoc --ruby_out=$RUBY_OUTPUT_DIR --grpc_out=$RUBY_OUTPUT_DIR/lib services/* | ||
grpc_tools_ruby_protoc --ruby_out=$RUBY_OUTPUT_DIR --grpc_out=$RUBY_OUTPUT_DIR/lib models/* | ||
``` |
24 changes: 24 additions & 0 deletions
24
samples/config/petstore/protobuf-schema-config/models/api_response.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
OpenAPI Petstore | ||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. | ||
The version of the OpenAPI document: 1.0.0 | ||
Generated by OpenAPI Generator: https://openapi-generator.tech | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
package petstore; | ||
|
||
|
||
message ApiResponse { | ||
|
||
int32 code = 1; | ||
|
||
string type = 2; | ||
|
||
string message = 3; | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
samples/config/petstore/protobuf-schema-config/models/category.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
OpenAPI Petstore | ||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. | ||
The version of the OpenAPI document: 1.0.0 | ||
Generated by OpenAPI Generator: https://openapi-generator.tech | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
package petstore; | ||
|
||
|
||
message Category { | ||
|
||
int64 id = 1; | ||
|
||
string name = 2; | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
samples/config/petstore/protobuf-schema-config/models/order.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
OpenAPI Petstore | ||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. | ||
The version of the OpenAPI document: 1.0.0 | ||
Generated by OpenAPI Generator: https://openapi-generator.tech | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
package petstore; | ||
|
||
|
||
message Order { | ||
|
||
int64 id = 1; | ||
|
||
int64 pet_id = 2 [json_name="petId"]; | ||
|
||
int32 quantity = 3; | ||
|
||
string ship_date = 4 [json_name="shipDate"]; | ||
|
||
// Order Status | ||
enum Status { | ||
STATUS_UNSPECIFIED = 0; | ||
STATUS_PLACED = 1; | ||
STATUS_APPROVED = 2; | ||
STATUS_DELIVERED = 3; | ||
} | ||
|
||
Status status = 5; | ||
|
||
bool complete = 6; | ||
|
||
} |
Oops, something went wrong.