From c96d3088c506f6af09b095e7b25828fce17985dc Mon Sep 17 00:00:00 2001 From: lucy66hw Date: Tue, 4 Mar 2025 01:18:07 -0800 Subject: [PATCH] [protobuf-schema] Use snake_case for protobuf fields, UPPER_SNAKE_CASE 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 --- .github/workflows/samples-protobuf.yaml | 38 +++++++ bin/configs/protobuf-schema-config.yaml | 9 ++ docs/generators/protobuf-schema.md | 1 + .../languages/ProtobufSchemaCodegen.java | 56 +++++++++- .../resources/protobuf-schema/api.mustache | 2 +- .../resources/protobuf-schema/model.mustache | 2 +- .../protobuf/ProtobufSchemaCodegenTest.java | 2 +- .../resources/3_0/protobuf-schema/pet.proto | 4 +- .../.openapi-generator-ignore | 23 ++++ .../.openapi-generator/FILES | 11 ++ .../.openapi-generator/VERSION | 1 + .../petstore/protobuf-schema-config/README.md | 32 ++++++ .../models/api_response.proto | 24 +++++ .../models/category.proto | 22 ++++ .../protobuf-schema-config/models/order.proto | 38 +++++++ .../models/other_test.proto | 20 ++++ .../protobuf-schema-config/models/pet.proto | 40 +++++++ .../protobuf-schema-config/models/tag.proto | 22 ++++ .../protobuf-schema-config/models/user.proto | 35 ++++++ .../services/pet_service.proto | 102 ++++++++++++++++++ .../services/store_service.proto | 50 +++++++++ .../services/user_service.proto | 86 +++++++++++++++ .../protobuf-schema/models/order.proto | 14 +-- .../petstore/protobuf-schema/models/pet.proto | 12 +-- .../protobuf-schema/models/user.proto | 6 +- .../services/pet_service.proto | 12 +-- .../services/store_service.proto | 4 +- 27 files changed, 637 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/samples-protobuf.yaml create mode 100644 bin/configs/protobuf-schema-config.yaml create mode 100644 samples/config/petstore/protobuf-schema-config/.openapi-generator-ignore create mode 100644 samples/config/petstore/protobuf-schema-config/.openapi-generator/FILES create mode 100644 samples/config/petstore/protobuf-schema-config/.openapi-generator/VERSION create mode 100644 samples/config/petstore/protobuf-schema-config/README.md create mode 100644 samples/config/petstore/protobuf-schema-config/models/api_response.proto create mode 100644 samples/config/petstore/protobuf-schema-config/models/category.proto create mode 100644 samples/config/petstore/protobuf-schema-config/models/order.proto create mode 100644 samples/config/petstore/protobuf-schema-config/models/other_test.proto create mode 100644 samples/config/petstore/protobuf-schema-config/models/pet.proto create mode 100644 samples/config/petstore/protobuf-schema-config/models/tag.proto create mode 100644 samples/config/petstore/protobuf-schema-config/models/user.proto create mode 100644 samples/config/petstore/protobuf-schema-config/services/pet_service.proto create mode 100644 samples/config/petstore/protobuf-schema-config/services/store_service.proto create mode 100644 samples/config/petstore/protobuf-schema-config/services/user_service.proto diff --git a/.github/workflows/samples-protobuf.yaml b/.github/workflows/samples-protobuf.yaml new file mode 100644 index 00000000000..158720d3d6d --- /dev/null +++ b/.github/workflows/samples-protobuf.yaml @@ -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 \ No newline at end of file diff --git a/bin/configs/protobuf-schema-config.yaml b/bin/configs/protobuf-schema-config.yaml new file mode 100644 index 00000000000..309a9aa8bcf --- /dev/null +++ b/bin/configs/protobuf-schema-config.yaml @@ -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 diff --git a/docs/generators/protobuf-schema.md b/docs/generators/protobuf-schema.md index a01b4435f10..7b5033f7931 100644 --- a/docs/generators/protobuf-schema.md +++ b/docs/generators/protobuf-schema.md @@ -18,6 +18,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | Option | Description | Values | Default | | ------ | ----------- | ------ | ------- | +|addJsonNameAnnotation|Append "json_name" annotation to message field when the specification name differs from the protobuf field name| |false| |numberedFieldNumberList|Field numbers in order.| |false| |startEnumsWithUnspecified|Introduces "UNSPECIFIED" as the first element of enumerations.| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java index 8d238a23b90..cb398cd421e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java @@ -38,6 +38,7 @@ import java.io.File; import java.util.*; import java.util.Map.Entry; import java.util.regex.Pattern; +import com.google.common.base.CaseFormat; import static org.openapitools.codegen.utils.StringUtils.camelize; import static org.openapitools.codegen.utils.StringUtils.underscore; @@ -52,6 +53,8 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf public static final String START_ENUMS_WITH_UNSPECIFIED = "startEnumsWithUnspecified"; + public static final String ADD_JSON_NAME_ANNOTATION = "addJsonNameAnnotation"; + private final Logger LOGGER = LoggerFactory.getLogger(ProtobufSchemaCodegen.class); @Setter protected String packageName = "openapitools"; @@ -60,11 +63,18 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf private boolean startEnumsWithUnspecified = false; + private boolean addJsonNameAnnotation = false; + @Override public CodegenType getTag() { return CodegenType.SCHEMA; } + @Override + public String toEnumName(CodegenProperty property) { + return StringUtils.capitalize(property.name); + } + @Override public String getName() { return "protobuf-schema"; @@ -163,6 +173,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf addSwitch(NUMBERED_FIELD_NUMBER_LIST, "Field numbers in order.", numberedFieldNumberList); addSwitch(START_ENUMS_WITH_UNSPECIFIED, "Introduces \"UNSPECIFIED\" as the first element of enumerations.", startEnumsWithUnspecified); + addSwitch(ADD_JSON_NAME_ANNOTATION, "Append \"json_name\" annotation to message field when the specification name differs from the protobuf field name", addJsonNameAnnotation); } @Override @@ -197,6 +208,10 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf this.startEnumsWithUnspecified = convertPropertyToBooleanAndWriteBack(START_ENUMS_WITH_UNSPECIFIED); } + if (additionalProperties.containsKey(this.ADD_JSON_NAME_ANNOTATION)) { + this.addJsonNameAnnotation = convertPropertyToBooleanAndWriteBack(ADD_JSON_NAME_ANNOTATION); + } + supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); } @@ -226,7 +241,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf public void addEnumValuesPrefix(Map allowableValues, String prefix) { if (allowableValues.containsKey("enumVars")) { List> enumVars = (List>) allowableValues.get("enumVars"); - + prefix = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, prefix); for (Map value : enumVars) { String name = (String) value.get("name"); value.put("name", prefix + "_" + name); @@ -338,6 +353,10 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf var.vendorExtensions.putIfAbsent("x-protobuf-index", "Generated field number is in reserved range (19000, 19999)"); } } + + if (addJsonNameAnnotation && !var.baseName.equals(var.name)) { + var.vendorExtensions.put("x-protobuf-json-name", var.baseName); + } } } return objs; @@ -493,10 +512,38 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf } @Override - public String toVarName(final String name) { + public String toVarName(String name) { + if (nameMapping.containsKey(name)) { + return nameMapping.get(name); + } + // sanitize name + name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + + // if it's all upper case, convert to lower case + if (name.matches("^[A-Z_]*$")) { + name = name.toLowerCase(Locale.ROOT); + } + + // underscore the variable name + // petId => pet_id + name = underscore(name); + + // remove leading underscore + name = name.replaceAll("^_*", ""); + + // for reserved word or word starting with number, append _ + if (isReservedWord(name) || name.matches("^\\d.*")) { + name = escapeReservedWord(name); + } + return name; } + @Override + public String toParamName(String name) { + return toVarName(name); + } + @Override public String toModelName(String name) { name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. @@ -571,6 +618,10 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf } } + if (addJsonNameAnnotation && !p.baseName.equals(p.paramName) && !p.isBodyParam) { + p.vendorExtensions.put("x-protobuf-json-name", p.baseName); + } + p.vendorExtensions.putIfAbsent("x-protobuf-index", index); index++; } @@ -646,4 +697,5 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.PROTOBUF; } + } diff --git a/modules/openapi-generator/src/main/resources/protobuf-schema/api.mustache b/modules/openapi-generator/src/main/resources/protobuf-schema/api.mustache index dc4ec5e1c39..4e4518615ac 100644 --- a/modules/openapi-generator/src/main/resources/protobuf-schema/api.mustache +++ b/modules/openapi-generator/src/main/resources/protobuf-schema/api.mustache @@ -30,7 +30,7 @@ message {{operationId}}Request { {{#description}} // {{{.}}} {{/description}} - {{#vendorExtensions.x-protobuf-type}}{{.}} {{/vendorExtensions.x-protobuf-type}}{{vendorExtensions.x-protobuf-data-type}} {{paramName}} = {{vendorExtensions.x-protobuf-index}}; + {{#vendorExtensions.x-protobuf-type}}{{.}} {{/vendorExtensions.x-protobuf-type}}{{vendorExtensions.x-protobuf-data-type}} {{paramName}} = {{vendorExtensions.x-protobuf-index}}{{#vendorExtensions.x-protobuf-json-name}} [json_name="{{vendorExtensions.x-protobuf-json-name}}"]{{/vendorExtensions.x-protobuf-json-name}}; {{/allParams}} } diff --git a/modules/openapi-generator/src/main/resources/protobuf-schema/model.mustache b/modules/openapi-generator/src/main/resources/protobuf-schema/model.mustache index 2aca6336c95..88f1644f592 100644 --- a/modules/openapi-generator/src/main/resources/protobuf-schema/model.mustache +++ b/modules/openapi-generator/src/main/resources/protobuf-schema/model.mustache @@ -18,7 +18,7 @@ import public "{{{modelPackage}}}/{{{import}}}.proto"; // {{{.}}} {{/description}} {{^isEnum}} - {{#vendorExtensions.x-protobuf-type}}{{{.}}} {{/vendorExtensions.x-protobuf-type}}{{{vendorExtensions.x-protobuf-data-type}}} {{{name}}} = {{vendorExtensions.x-protobuf-index}}{{#vendorExtensions.x-protobuf-packed}} [packed=true]{{/vendorExtensions.x-protobuf-packed}}; + {{#vendorExtensions.x-protobuf-type}}{{{.}}} {{/vendorExtensions.x-protobuf-type}}{{{vendorExtensions.x-protobuf-data-type}}} {{{name}}} = {{vendorExtensions.x-protobuf-index}}{{#vendorExtensions.x-protobuf-packed}} [packed=true]{{/vendorExtensions.x-protobuf-packed}}{{#vendorExtensions.x-protobuf-json-name}} [json_name="{{vendorExtensions.x-protobuf-json-name}}"]{{/vendorExtensions.x-protobuf-json-name}}; {{/isEnum}} {{#isEnum}} enum {{enumName}} { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/protobuf/ProtobufSchemaCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/protobuf/ProtobufSchemaCodegenTest.java index 595919720aa..e621703e67d 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/protobuf/ProtobufSchemaCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/protobuf/ProtobufSchemaCodegenTest.java @@ -91,6 +91,6 @@ public class ProtobufSchemaCodegenTest { final CodegenModel simpleName = codegen.fromModel("$DollarModel$", openAPI.getComponents().getSchemas().get("$DollarModel$")); Assert.assertEquals(simpleName.name, "$DollarModel$"); Assert.assertEquals(simpleName.classname, "DollarModel"); - Assert.assertEquals(simpleName.classVarName, "$DollarModel$"); + Assert.assertEquals(simpleName.classVarName, "dollar_model"); } } diff --git a/modules/openapi-generator/src/test/resources/3_0/protobuf-schema/pet.proto b/modules/openapi-generator/src/test/resources/3_0/protobuf-schema/pet.proto index 6b33968ee19..38a86bc063f 100644 --- a/modules/openapi-generator/src/test/resources/3_0/protobuf-schema/pet.proto +++ b/modules/openapi-generator/src/test/resources/3_0/protobuf-schema/pet.proto @@ -14,12 +14,12 @@ package openapitools; message Pet { - string petType = 140636936; + string pet_type = 482112090; string name = 3373707; string bark = 3016376; - bool lovesRocks = 499337491; + bool loves_rocks = 465093427; } diff --git a/samples/config/petstore/protobuf-schema-config/.openapi-generator-ignore b/samples/config/petstore/protobuf-schema-config/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/.openapi-generator-ignore @@ -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 diff --git a/samples/config/petstore/protobuf-schema-config/.openapi-generator/FILES b/samples/config/petstore/protobuf-schema-config/.openapi-generator/FILES new file mode 100644 index 00000000000..c65218a7166 --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/.openapi-generator/FILES @@ -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 diff --git a/samples/config/petstore/protobuf-schema-config/.openapi-generator/VERSION b/samples/config/petstore/protobuf-schema-config/.openapi-generator/VERSION new file mode 100644 index 00000000000..96cfbb19ae2 --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.13.0-SNAPSHOT diff --git a/samples/config/petstore/protobuf-schema-config/README.md b/samples/config/petstore/protobuf-schema-config/README.md new file mode 100644 index 00000000000..8e49113a212 --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/README.md @@ -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/* +``` diff --git a/samples/config/petstore/protobuf-schema-config/models/api_response.proto b/samples/config/petstore/protobuf-schema-config/models/api_response.proto new file mode 100644 index 00000000000..6236264f976 --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/models/api_response.proto @@ -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; + +} diff --git a/samples/config/petstore/protobuf-schema-config/models/category.proto b/samples/config/petstore/protobuf-schema-config/models/category.proto new file mode 100644 index 00000000000..9db08ccdc54 --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/models/category.proto @@ -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; + +} diff --git a/samples/config/petstore/protobuf-schema-config/models/order.proto b/samples/config/petstore/protobuf-schema-config/models/order.proto new file mode 100644 index 00000000000..cc93af2330e --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/models/order.proto @@ -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; + +} diff --git a/samples/config/petstore/protobuf-schema-config/models/other_test.proto b/samples/config/petstore/protobuf-schema-config/models/other_test.proto new file mode 100644 index 00000000000..10c41b2dbdf --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/models/other_test.proto @@ -0,0 +1,20 @@ +/* + 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 OtherTest { + + repeated string set_test = 1; + +} diff --git a/samples/config/petstore/protobuf-schema-config/models/pet.proto b/samples/config/petstore/protobuf-schema-config/models/pet.proto new file mode 100644 index 00000000000..a4238e6a0a0 --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/models/pet.proto @@ -0,0 +1,40 @@ +/* + 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; + +import public "models/category.proto"; +import public "models/tag.proto"; + +message Pet { + + int64 id = 1; + + Category category = 2; + + string name = 3; + + repeated string photo_urls = 4 [json_name="photoUrls"]; + + repeated Tag tags = 5; + + // pet status in the store + enum Status { + STATUS_UNSPECIFIED = 0; + STATUS_AVAILABLE = 1; + STATUS_PENDING = 2; + STATUS_SOLD = 3; + } + + Status status = 6; + +} diff --git a/samples/config/petstore/protobuf-schema-config/models/tag.proto b/samples/config/petstore/protobuf-schema-config/models/tag.proto new file mode 100644 index 00000000000..32c6c8d77aa --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/models/tag.proto @@ -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 Tag { + + int64 id = 1; + + string name = 2; + +} diff --git a/samples/config/petstore/protobuf-schema-config/models/user.proto b/samples/config/petstore/protobuf-schema-config/models/user.proto new file mode 100644 index 00000000000..fe0652f631b --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/models/user.proto @@ -0,0 +1,35 @@ +/* + 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 User { + + int64 id = 1; + + string username = 2; + + string first_name = 3 [json_name="firstName"]; + + string last_name = 4 [json_name="lastName"]; + + string email = 5; + + string password = 6; + + string phone = 7; + + // User Status + int32 user_status = 8 [json_name="userStatus"]; + +} diff --git a/samples/config/petstore/protobuf-schema-config/services/pet_service.proto b/samples/config/petstore/protobuf-schema-config/services/pet_service.proto new file mode 100644 index 00000000000..c080fb02ed0 --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/services/pet_service.proto @@ -0,0 +1,102 @@ +/* + 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.services.petservice; + +import "google/protobuf/empty.proto"; +import public "models/api_response.proto"; +import public "models/pet.proto"; + +service PetService { + rpc AddPet (AddPetRequest) returns (Pet); + + rpc DeletePet (DeletePetRequest) returns (google.protobuf.Empty); + + rpc FindPetsByStatus (FindPetsByStatusRequest) returns (FindPetsByStatusResponse); + + rpc FindPetsByTags (FindPetsByTagsRequest) returns (FindPetsByTagsResponse); + + rpc GetPetById (GetPetByIdRequest) returns (Pet); + + rpc UpdatePet (UpdatePetRequest) returns (Pet); + + rpc UpdatePetWithForm (UpdatePetWithFormRequest) returns (google.protobuf.Empty); + + rpc UploadFile (UploadFileRequest) returns (ApiResponse); + +} + +message AddPetRequest { + // Pet object that needs to be added to the store + Pet pet = 1; + +} + +message DeletePetRequest { + // Pet id to delete + int64 pet_id = 1 [json_name="petId"]; + string api_key = 2; + +} + +message FindPetsByStatusRequest { + // Status values that need to be considered for filter + repeated string status = 1; + +} + +message FindPetsByStatusResponse { + repeated Pet data = 1; +} + +message FindPetsByTagsRequest { + // Tags to filter by + repeated string tags = 1; + +} + +message FindPetsByTagsResponse { + repeated Pet data = 1; +} + +message GetPetByIdRequest { + // ID of pet to return + int64 pet_id = 1 [json_name="petId"]; + +} + +message UpdatePetRequest { + // Pet object that needs to be added to the store + Pet pet = 1; + +} + +message UpdatePetWithFormRequest { + // ID of pet that needs to be updated + int64 pet_id = 1 [json_name="petId"]; + // Updated name of the pet + string name = 2; + // Updated status of the pet + string status = 3; + +} + +message UploadFileRequest { + // ID of pet to update + int64 pet_id = 1 [json_name="petId"]; + // Additional data to pass to server + string additional_metadata = 2 [json_name="additionalMetadata"]; + // file to upload + string file = 3; + +} + diff --git a/samples/config/petstore/protobuf-schema-config/services/store_service.proto b/samples/config/petstore/protobuf-schema-config/services/store_service.proto new file mode 100644 index 00000000000..9efbfd76958 --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/services/store_service.proto @@ -0,0 +1,50 @@ +/* + 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.services.storeservice; + +import "google/protobuf/empty.proto"; +import public "models/order.proto"; + +service StoreService { + rpc DeleteOrder (DeleteOrderRequest) returns (google.protobuf.Empty); + + rpc GetInventory (google.protobuf.Empty) returns (GetInventoryResponse); + + rpc GetOrderById (GetOrderByIdRequest) returns (Order); + + rpc PlaceOrder (PlaceOrderRequest) returns (Order); + +} + +message DeleteOrderRequest { + // ID of the order that needs to be deleted + string order_id = 1 [json_name="orderId"]; + +} + +message GetInventoryResponse { + int32 data = 1; +} + +message GetOrderByIdRequest { + // ID of pet that needs to be fetched + int64 order_id = 1 [json_name="orderId"]; + +} + +message PlaceOrderRequest { + // order placed for purchasing the pet + Order order = 1; + +} + diff --git a/samples/config/petstore/protobuf-schema-config/services/user_service.proto b/samples/config/petstore/protobuf-schema-config/services/user_service.proto new file mode 100644 index 00000000000..119219d6fc8 --- /dev/null +++ b/samples/config/petstore/protobuf-schema-config/services/user_service.proto @@ -0,0 +1,86 @@ +/* + 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.services.userservice; + +import "google/protobuf/empty.proto"; +import public "models/user.proto"; + +service UserService { + rpc CreateUser (CreateUserRequest) returns (google.protobuf.Empty); + + rpc CreateUsersWithArrayInput (CreateUsersWithArrayInputRequest) returns (google.protobuf.Empty); + + rpc CreateUsersWithListInput (CreateUsersWithListInputRequest) returns (google.protobuf.Empty); + + rpc DeleteUser (DeleteUserRequest) returns (google.protobuf.Empty); + + rpc GetUserByName (GetUserByNameRequest) returns (User); + + rpc LoginUser (LoginUserRequest) returns (LoginUserResponse); + + rpc LogoutUser (google.protobuf.Empty) returns (google.protobuf.Empty); + + rpc UpdateUser (UpdateUserRequest) returns (google.protobuf.Empty); + +} + +message CreateUserRequest { + // Created user object + User user = 1; + +} + +message CreateUsersWithArrayInputRequest { + // List of user object + repeated User user = 1; + +} + +message CreateUsersWithListInputRequest { + // List of user object + repeated User user = 1; + +} + +message DeleteUserRequest { + // The name that needs to be deleted + string username = 1; + +} + +message GetUserByNameRequest { + // The name that needs to be fetched. Use user1 for testing. + string username = 1; + +} + +message LoginUserRequest { + // The user name for login + string username = 1; + // The password for login in clear text + string password = 2; + +} + +message LoginUserResponse { + string data = 1; +} + +message UpdateUserRequest { + // name that need to be deleted + string username = 1; + // Updated user object + User user = 2; + +} + diff --git a/samples/config/petstore/protobuf-schema/models/order.proto b/samples/config/petstore/protobuf-schema/models/order.proto index 4ca4bff35d4..cdd08cc15f3 100644 --- a/samples/config/petstore/protobuf-schema/models/order.proto +++ b/samples/config/petstore/protobuf-schema/models/order.proto @@ -17,20 +17,20 @@ message Order { int64 id = 3355; - int64 petId = 106557082; + int64 pet_id = 454805446; int32 quantity = 211262327; - string shipDate = 517554166; + string ship_date = 86954963; // Order Status - enum StatusEnum { - StatusEnum_PLACED = 0; - StatusEnum_APPROVED = 1; - StatusEnum_DELIVERED = 2; + enum Status { + STATUS_PLACED = 0; + STATUS_APPROVED = 1; + STATUS_DELIVERED = 2; } - StatusEnum status = 355610639; + Status status = 355610639; bool complete = 62574280; diff --git a/samples/config/petstore/protobuf-schema/models/pet.proto b/samples/config/petstore/protobuf-schema/models/pet.proto index e92a0ca33d6..6b92c3d61f4 100644 --- a/samples/config/petstore/protobuf-schema/models/pet.proto +++ b/samples/config/petstore/protobuf-schema/models/pet.proto @@ -23,17 +23,17 @@ message Pet { string name = 3373707; - repeated string photoUrls = 311086539; + repeated string photo_urls = 507546927; repeated Tag tags = 3552281; // pet status in the store - enum StatusEnum { - StatusEnum_AVAILABLE = 0; - StatusEnum_PENDING = 1; - StatusEnum_SOLD = 2; + enum Status { + STATUS_AVAILABLE = 0; + STATUS_PENDING = 1; + STATUS_SOLD = 2; } - StatusEnum status = 355610639; + Status status = 355610639; } diff --git a/samples/config/petstore/protobuf-schema/models/user.proto b/samples/config/petstore/protobuf-schema/models/user.proto index eb6f727b876..4d3f68b1c4e 100644 --- a/samples/config/petstore/protobuf-schema/models/user.proto +++ b/samples/config/petstore/protobuf-schema/models/user.proto @@ -19,9 +19,9 @@ message User { string username = 265713450; - string firstName = 132835675; + string first_name = 160985414; - string lastName = 385857985; + string last_name = 402509463; string email = 96619420; @@ -30,6 +30,6 @@ message User { string phone = 106642798; // User Status - int32 userStatus = 517890975; + int32 user_status = 150530330; } diff --git a/samples/config/petstore/protobuf-schema/services/pet_service.proto b/samples/config/petstore/protobuf-schema/services/pet_service.proto index ba8b4c18e31..f8938c757d0 100644 --- a/samples/config/petstore/protobuf-schema/services/pet_service.proto +++ b/samples/config/petstore/protobuf-schema/services/pet_service.proto @@ -43,8 +43,8 @@ message AddPetRequest { message DeletePetRequest { // Pet id to delete - int64 petId = 1; - string apiKey = 2; + int64 pet_id = 1; + string api_key = 2; } @@ -70,7 +70,7 @@ message FindPetsByTagsResponse { message GetPetByIdRequest { // ID of pet to return - int64 petId = 1; + int64 pet_id = 1; } @@ -82,7 +82,7 @@ message UpdatePetRequest { message UpdatePetWithFormRequest { // ID of pet that needs to be updated - int64 petId = 1; + int64 pet_id = 1; // Updated name of the pet string name = 2; // Updated status of the pet @@ -92,9 +92,9 @@ message UpdatePetWithFormRequest { message UploadFileRequest { // ID of pet to update - int64 petId = 1; + int64 pet_id = 1; // Additional data to pass to server - string additionalMetadata = 2; + string additional_metadata = 2; // file to upload string file = 3; diff --git a/samples/config/petstore/protobuf-schema/services/store_service.proto b/samples/config/petstore/protobuf-schema/services/store_service.proto index 05ebe84e1f4..4fc08377623 100644 --- a/samples/config/petstore/protobuf-schema/services/store_service.proto +++ b/samples/config/petstore/protobuf-schema/services/store_service.proto @@ -28,7 +28,7 @@ service StoreService { message DeleteOrderRequest { // ID of the order that needs to be deleted - string orderId = 1; + string order_id = 1; } @@ -38,7 +38,7 @@ message GetInventoryResponse { message GetOrderByIdRequest { // ID of pet that needs to be fetched - int64 orderId = 1; + int64 order_id = 1; }