Better example code for google protos (#542)
* Better example code for google protos * Try fix windows build * Try fix windows build * Remove generated code in repo
This commit is contained in:
+8
-1
@@ -6,5 +6,12 @@ fn main() {
|
||||
|
||||
tonic_build::compile_protos("proto/helloworld/helloworld.proto").unwrap();
|
||||
tonic_build::compile_protos("proto/echo/echo.proto").unwrap();
|
||||
tonic_build::compile_protos("proto/google/pubsub/pubsub.proto").unwrap();
|
||||
|
||||
tonic_build::configure()
|
||||
.build_server(false)
|
||||
.compile(
|
||||
&["proto/googleapis/google/pubsub/v1/pubsub.proto"],
|
||||
&["proto/googleapis"],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ syntax = "proto3";
|
||||
|
||||
package google.api;
|
||||
|
||||
import "http.proto";
|
||||
import "google/api/http.proto";
|
||||
import "google/protobuf/descriptor.proto";
|
||||
|
||||
option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
|
||||
@@ -28,4 +28,4 @@ option objc_class_prefix = "GAPI";
|
||||
extend google.protobuf.MethodOptions {
|
||||
// See `HttpRule`.
|
||||
HttpRule http = 72295728;
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -11,7 +11,6 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package google.api;
|
||||
|
||||
import "google/protobuf/descriptor.proto";
|
||||
|
||||
option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "FieldBehaviorProto";
|
||||
option java_package = "com.google.api";
|
||||
option objc_class_prefix = "GAPI";
|
||||
|
||||
extend google.protobuf.FieldOptions {
|
||||
// A designation of a specific field behavior (required, output only, etc.)
|
||||
// in protobuf messages.
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// string name = 1 [(google.api.field_behavior) = REQUIRED];
|
||||
// State state = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
|
||||
// google.protobuf.Duration ttl = 1
|
||||
// [(google.api.field_behavior) = INPUT_ONLY];
|
||||
// google.protobuf.Timestamp expire_time = 1
|
||||
// [(google.api.field_behavior) = OUTPUT_ONLY,
|
||||
// (google.api.field_behavior) = IMMUTABLE];
|
||||
repeated google.api.FieldBehavior field_behavior = 1052;
|
||||
}
|
||||
|
||||
// An indicator of the behavior of a given field (for example, that a field
|
||||
// is required in requests, or given as output but ignored as input).
|
||||
// This **does not** change the behavior in protocol buffers itself; it only
|
||||
// denotes the behavior and may affect how API tooling handles the field.
|
||||
//
|
||||
// Note: This enum **may** receive new values in the future.
|
||||
enum FieldBehavior {
|
||||
// Conventional default for enums. Do not use this.
|
||||
FIELD_BEHAVIOR_UNSPECIFIED = 0;
|
||||
|
||||
// Specifically denotes a field as optional.
|
||||
// While all fields in protocol buffers are optional, this may be specified
|
||||
// for emphasis if appropriate.
|
||||
OPTIONAL = 1;
|
||||
|
||||
// Denotes a field as required.
|
||||
// This indicates that the field **must** be provided as part of the request,
|
||||
// and failure to do so will cause an error (usually `INVALID_ARGUMENT`).
|
||||
REQUIRED = 2;
|
||||
|
||||
// Denotes a field as output only.
|
||||
// This indicates that the field is provided in responses, but including the
|
||||
// field in a request does nothing (the server *must* ignore it and
|
||||
// *must not* throw an error as a result of the field's presence).
|
||||
OUTPUT_ONLY = 3;
|
||||
|
||||
// Denotes a field as input only.
|
||||
// This indicates that the field is provided in requests, and the
|
||||
// corresponding field is not included in output.
|
||||
INPUT_ONLY = 4;
|
||||
|
||||
// Denotes a field as immutable.
|
||||
// This indicates that the field may be set once in a request to create a
|
||||
// resource, but may not be changed thereafter.
|
||||
IMMUTABLE = 5;
|
||||
|
||||
// Denotes that a (repeated) field is an unordered list.
|
||||
// This indicates that the service may provide the elements of the list
|
||||
// in any arbitrary order, rather than the order the user originally
|
||||
// provided. Additionally, the list's order may or may not be stable.
|
||||
UNORDERED_LIST = 6;
|
||||
}
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -11,7 +11,6 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package google.api;
|
||||
|
||||
import "google/protobuf/descriptor.proto";
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "ResourceProto";
|
||||
option java_package = "com.google.api";
|
||||
option objc_class_prefix = "GAPI";
|
||||
|
||||
extend google.protobuf.FieldOptions {
|
||||
// An annotation that describes a resource reference, see
|
||||
// [ResourceReference][].
|
||||
google.api.ResourceReference resource_reference = 1055;
|
||||
}
|
||||
|
||||
extend google.protobuf.FileOptions {
|
||||
// An annotation that describes a resource definition without a corresponding
|
||||
// message; see [ResourceDescriptor][].
|
||||
repeated google.api.ResourceDescriptor resource_definition = 1053;
|
||||
}
|
||||
|
||||
extend google.protobuf.MessageOptions {
|
||||
// An annotation that describes a resource definition, see
|
||||
// [ResourceDescriptor][].
|
||||
google.api.ResourceDescriptor resource = 1053;
|
||||
}
|
||||
|
||||
// A simple descriptor of a resource type.
|
||||
//
|
||||
// ResourceDescriptor annotates a resource message (either by means of a
|
||||
// protobuf annotation or use in the service config), and associates the
|
||||
// resource's schema, the resource type, and the pattern of the resource name.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// message Topic {
|
||||
// // Indicates this message defines a resource schema.
|
||||
// // Declares the resource type in the format of {service}/{kind}.
|
||||
// // For Kubernetes resources, the format is {api group}/{kind}.
|
||||
// option (google.api.resource) = {
|
||||
// type: "pubsub.googleapis.com/Topic"
|
||||
// name_descriptor: {
|
||||
// pattern: "projects/{project}/topics/{topic}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Project"
|
||||
// parent_name_extractor: "projects/{project}"
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// The ResourceDescriptor Yaml config will look like:
|
||||
//
|
||||
// resources:
|
||||
// - type: "pubsub.googleapis.com/Topic"
|
||||
// name_descriptor:
|
||||
// - pattern: "projects/{project}/topics/{topic}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Project"
|
||||
// parent_name_extractor: "projects/{project}"
|
||||
//
|
||||
// Sometimes, resources have multiple patterns, typically because they can
|
||||
// live under multiple parents.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// message LogEntry {
|
||||
// option (google.api.resource) = {
|
||||
// type: "logging.googleapis.com/LogEntry"
|
||||
// name_descriptor: {
|
||||
// pattern: "projects/{project}/logs/{log}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Project"
|
||||
// parent_name_extractor: "projects/{project}"
|
||||
// }
|
||||
// name_descriptor: {
|
||||
// pattern: "folders/{folder}/logs/{log}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Folder"
|
||||
// parent_name_extractor: "folders/{folder}"
|
||||
// }
|
||||
// name_descriptor: {
|
||||
// pattern: "organizations/{organization}/logs/{log}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Organization"
|
||||
// parent_name_extractor: "organizations/{organization}"
|
||||
// }
|
||||
// name_descriptor: {
|
||||
// pattern: "billingAccounts/{billing_account}/logs/{log}"
|
||||
// parent_type: "billing.googleapis.com/BillingAccount"
|
||||
// parent_name_extractor: "billingAccounts/{billing_account}"
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// The ResourceDescriptor Yaml config will look like:
|
||||
//
|
||||
// resources:
|
||||
// - type: 'logging.googleapis.com/LogEntry'
|
||||
// name_descriptor:
|
||||
// - pattern: "projects/{project}/logs/{log}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Project"
|
||||
// parent_name_extractor: "projects/{project}"
|
||||
// - pattern: "folders/{folder}/logs/{log}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Folder"
|
||||
// parent_name_extractor: "folders/{folder}"
|
||||
// - pattern: "organizations/{organization}/logs/{log}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Organization"
|
||||
// parent_name_extractor: "organizations/{organization}"
|
||||
// - pattern: "billingAccounts/{billing_account}/logs/{log}"
|
||||
// parent_type: "billing.googleapis.com/BillingAccount"
|
||||
// parent_name_extractor: "billingAccounts/{billing_account}"
|
||||
//
|
||||
// For flexible resources, the resource name doesn't contain parent names, but
|
||||
// the resource itself has parents for policy evaluation.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// message Shelf {
|
||||
// option (google.api.resource) = {
|
||||
// type: "library.googleapis.com/Shelf"
|
||||
// name_descriptor: {
|
||||
// pattern: "shelves/{shelf}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Project"
|
||||
// }
|
||||
// name_descriptor: {
|
||||
// pattern: "shelves/{shelf}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Folder"
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// The ResourceDescriptor Yaml config will look like:
|
||||
//
|
||||
// resources:
|
||||
// - type: 'library.googleapis.com/Shelf'
|
||||
// name_descriptor:
|
||||
// - pattern: "shelves/{shelf}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Project"
|
||||
// - pattern: "shelves/{shelf}"
|
||||
// parent_type: "cloudresourcemanager.googleapis.com/Folder"
|
||||
message ResourceDescriptor {
|
||||
// A description of the historical or future-looking state of the
|
||||
// resource pattern.
|
||||
enum History {
|
||||
// The "unset" value.
|
||||
HISTORY_UNSPECIFIED = 0;
|
||||
|
||||
// The resource originally had one pattern and launched as such, and
|
||||
// additional patterns were added later.
|
||||
ORIGINALLY_SINGLE_PATTERN = 1;
|
||||
|
||||
// The resource has one pattern, but the API owner expects to add more
|
||||
// later. (This is the inverse of ORIGINALLY_SINGLE_PATTERN, and prevents
|
||||
// that from being necessary once there are multiple patterns.)
|
||||
FUTURE_MULTI_PATTERN = 2;
|
||||
}
|
||||
|
||||
// A flag representing a specific style that a resource claims to conform to.
|
||||
enum Style {
|
||||
// The unspecified value. Do not use.
|
||||
STYLE_UNSPECIFIED = 0;
|
||||
|
||||
// This resource is intended to be "declarative-friendly".
|
||||
//
|
||||
// Declarative-friendly resources must be more strictly consistent, and
|
||||
// setting this to true communicates to tools that this resource should
|
||||
// adhere to declarative-friendly expectations.
|
||||
//
|
||||
// Note: This is used by the API linter (linter.aip.dev) to enable
|
||||
// additional checks.
|
||||
DECLARATIVE_FRIENDLY = 1;
|
||||
}
|
||||
|
||||
// The resource type. It must be in the format of
|
||||
// {service_name}/{resource_type_kind}. The `resource_type_kind` must be
|
||||
// singular and must not include version numbers.
|
||||
//
|
||||
// Example: `storage.googleapis.com/Bucket`
|
||||
//
|
||||
// The value of the resource_type_kind must follow the regular expression
|
||||
// /[A-Za-z][a-zA-Z0-9]+/. It should start with an upper case character and
|
||||
// should use PascalCase (UpperCamelCase). The maximum number of
|
||||
// characters allowed for the `resource_type_kind` is 100.
|
||||
string type = 1;
|
||||
|
||||
// Optional. The relative resource name pattern associated with this resource
|
||||
// type. The DNS prefix of the full resource name shouldn't be specified here.
|
||||
//
|
||||
// The path pattern must follow the syntax, which aligns with HTTP binding
|
||||
// syntax:
|
||||
//
|
||||
// Template = Segment { "/" Segment } ;
|
||||
// Segment = LITERAL | Variable ;
|
||||
// Variable = "{" LITERAL "}" ;
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// - "projects/{project}/topics/{topic}"
|
||||
// - "projects/{project}/knowledgeBases/{knowledge_base}"
|
||||
//
|
||||
// The components in braces correspond to the IDs for each resource in the
|
||||
// hierarchy. It is expected that, if multiple patterns are provided,
|
||||
// the same component name (e.g. "project") refers to IDs of the same
|
||||
// type of resource.
|
||||
repeated string pattern = 2;
|
||||
|
||||
// Optional. The field on the resource that designates the resource name
|
||||
// field. If omitted, this is assumed to be "name".
|
||||
string name_field = 3;
|
||||
|
||||
// Optional. The historical or future-looking state of the resource pattern.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// // The InspectTemplate message originally only supported resource
|
||||
// // names with organization, and project was added later.
|
||||
// message InspectTemplate {
|
||||
// option (google.api.resource) = {
|
||||
// type: "dlp.googleapis.com/InspectTemplate"
|
||||
// pattern:
|
||||
// "organizations/{organization}/inspectTemplates/{inspect_template}"
|
||||
// pattern: "projects/{project}/inspectTemplates/{inspect_template}"
|
||||
// history: ORIGINALLY_SINGLE_PATTERN
|
||||
// };
|
||||
// }
|
||||
History history = 4;
|
||||
|
||||
// The plural name used in the resource name and permission names, such as
|
||||
// 'projects' for the resource name of 'projects/{project}' and the permission
|
||||
// name of 'cloudresourcemanager.googleapis.com/projects.get'. It is the same
|
||||
// concept of the `plural` field in k8s CRD spec
|
||||
// https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/
|
||||
//
|
||||
// Note: The plural form is required even for singleton resources. See
|
||||
// https://aip.dev/156
|
||||
string plural = 5;
|
||||
|
||||
// The same concept of the `singular` field in k8s CRD spec
|
||||
// https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/
|
||||
// Such as "project" for the `resourcemanager.googleapis.com/Project` type.
|
||||
string singular = 6;
|
||||
|
||||
// Style flag(s) for this resource.
|
||||
// These indicate that a resource is expected to conform to a given
|
||||
// style. See the specific style flags for additional information.
|
||||
repeated Style style = 10;
|
||||
}
|
||||
|
||||
// Defines a proto annotation that describes a string field that refers to
|
||||
// an API resource.
|
||||
message ResourceReference {
|
||||
// The resource type that the annotated field references.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// message Subscription {
|
||||
// string topic = 2 [(google.api.resource_reference) = {
|
||||
// type: "pubsub.googleapis.com/Topic"
|
||||
// }];
|
||||
// }
|
||||
//
|
||||
// Occasionally, a field may reference an arbitrary resource. In this case,
|
||||
// APIs use the special value * in their resource reference.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// message GetIamPolicyRequest {
|
||||
// string resource = 2 [(google.api.resource_reference) = {
|
||||
// type: "*"
|
||||
// }];
|
||||
// }
|
||||
string type = 1;
|
||||
|
||||
// The resource type of a child collection that the annotated field
|
||||
// references. This is useful for annotating the `parent` field that
|
||||
// doesn't have a fixed resource type.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// message ListLogEntriesRequest {
|
||||
// string parent = 1 [(google.api.resource_reference) = {
|
||||
// child_type: "logging.googleapis.com/LogEntry"
|
||||
// };
|
||||
// }
|
||||
string child_type = 2;
|
||||
}
|
||||
+439
-190
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,289 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package google.pubsub.v1;
|
||||
|
||||
import "google/api/annotations.proto";
|
||||
import "google/api/client.proto";
|
||||
import "google/api/field_behavior.proto";
|
||||
import "google/api/resource.proto";
|
||||
import "google/protobuf/empty.proto";
|
||||
|
||||
option cc_enable_arenas = true;
|
||||
option csharp_namespace = "Google.Cloud.PubSub.V1";
|
||||
option go_package = "google.golang.org/genproto/googleapis/pubsub/v1;pubsub";
|
||||
option java_multiple_files = true;
|
||||
option java_outer_classname = "SchemaProto";
|
||||
option java_package = "com.google.pubsub.v1";
|
||||
option php_namespace = "Google\\Cloud\\PubSub\\V1";
|
||||
option ruby_package = "Google::Cloud::PubSub::V1";
|
||||
|
||||
// Service for doing schema-related operations.
|
||||
//
|
||||
// EXPERIMENTAL: The Schema service is in development and may not work yet.
|
||||
|
||||
service SchemaService {
|
||||
option (google.api.default_host) = "pubsub.googleapis.com";
|
||||
option (google.api.oauth_scopes) =
|
||||
"https://www.googleapis.com/auth/cloud-platform,"
|
||||
"https://www.googleapis.com/auth/pubsub";
|
||||
|
||||
// Creates a schema.
|
||||
rpc CreateSchema(CreateSchemaRequest) returns (Schema) {
|
||||
option (google.api.http) = {
|
||||
post: "/v1/{parent=projects/*}/schemas"
|
||||
body: "schema"
|
||||
};
|
||||
option (google.api.method_signature) = "parent,schema,schema_id";
|
||||
}
|
||||
|
||||
// Gets a schema.
|
||||
rpc GetSchema(GetSchemaRequest) returns (Schema) {
|
||||
option (google.api.http) = {
|
||||
get: "/v1/{name=projects/*/schemas/*}"
|
||||
};
|
||||
option (google.api.method_signature) = "name";
|
||||
}
|
||||
|
||||
// Lists schemas in a project.
|
||||
rpc ListSchemas(ListSchemasRequest) returns (ListSchemasResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/v1/{parent=projects/*}/schemas"
|
||||
};
|
||||
option (google.api.method_signature) = "parent";
|
||||
}
|
||||
|
||||
// Deletes a schema.
|
||||
rpc DeleteSchema(DeleteSchemaRequest) returns (google.protobuf.Empty) {
|
||||
option (google.api.http) = {
|
||||
delete: "/v1/{name=projects/*/schemas/*}"
|
||||
};
|
||||
option (google.api.method_signature) = "name";
|
||||
}
|
||||
|
||||
// Validates a schema.
|
||||
rpc ValidateSchema(ValidateSchemaRequest) returns (ValidateSchemaResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v1/{parent=projects/*}/schemas:validate"
|
||||
body: "*"
|
||||
};
|
||||
option (google.api.method_signature) = "parent,schema";
|
||||
}
|
||||
|
||||
// Validates a message against a schema.
|
||||
rpc ValidateMessage(ValidateMessageRequest)
|
||||
returns (ValidateMessageResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/v1/{parent=projects/*}/schemas:validateMessage"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// A schema resource.
|
||||
message Schema {
|
||||
option (google.api.resource) = {
|
||||
type: "pubsub.googleapis.com/Schema"
|
||||
pattern: "projects/{project}/schemas/{schema}"
|
||||
};
|
||||
|
||||
// Possible schema definition types.
|
||||
enum Type {
|
||||
// Default value. This value is unused.
|
||||
TYPE_UNSPECIFIED = 0;
|
||||
|
||||
// A Protocol Buffer schema definition.
|
||||
PROTOCOL_BUFFER = 1;
|
||||
|
||||
// An Avro schema definition.
|
||||
AVRO = 2;
|
||||
}
|
||||
|
||||
// Required. Name of the schema.
|
||||
// Format is `projects/{project}/schemas/{schema}`.
|
||||
string name = 1 [(google.api.field_behavior) = REQUIRED];
|
||||
|
||||
// The type of the schema definition.
|
||||
Type type = 2;
|
||||
|
||||
// The definition of the schema. This should contain a string representing
|
||||
// the full definition of the schema that is a valid schema definition of
|
||||
// the type specified in `type`.
|
||||
string definition = 3;
|
||||
}
|
||||
|
||||
// Request for the CreateSchema method.
|
||||
message CreateSchemaRequest {
|
||||
// Required. The name of the project in which to create the schema.
|
||||
// Format is `projects/{project-id}`.
|
||||
string parent = 1 [
|
||||
(google.api.field_behavior) = REQUIRED,
|
||||
(google.api.resource_reference) = {
|
||||
child_type: "pubsub.googleapis.com/Schema"
|
||||
}
|
||||
];
|
||||
|
||||
// Required. The schema object to create.
|
||||
//
|
||||
// This schema's `name` parameter is ignored. The schema object returned
|
||||
// by CreateSchema will have a `name` made using the given `parent` and
|
||||
// `schema_id`.
|
||||
Schema schema = 2 [(google.api.field_behavior) = REQUIRED];
|
||||
|
||||
// The ID to use for the schema, which will become the final component of
|
||||
// the schema's resource name.
|
||||
//
|
||||
// See https://cloud.google.com/pubsub/docs/admin#resource_names for resource
|
||||
// name constraints.
|
||||
string schema_id = 3;
|
||||
}
|
||||
|
||||
// View of Schema object fields to be returned by GetSchema and ListSchemas.
|
||||
enum SchemaView {
|
||||
// The default / unset value.
|
||||
// The API will default to the BASIC view.
|
||||
SCHEMA_VIEW_UNSPECIFIED = 0;
|
||||
|
||||
// Include the name and type of the schema, but not the definition.
|
||||
BASIC = 1;
|
||||
|
||||
// Include all Schema object fields.
|
||||
FULL = 2;
|
||||
}
|
||||
|
||||
// Request for the GetSchema method.
|
||||
message GetSchemaRequest {
|
||||
// Required. The name of the schema to get.
|
||||
// Format is `projects/{project}/schemas/{schema}`.
|
||||
string name = 1 [
|
||||
(google.api.field_behavior) = REQUIRED,
|
||||
(google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
|
||||
];
|
||||
|
||||
// The set of fields to return in the response. If not set, returns a Schema
|
||||
// with `name` and `type`, but not `definition`. Set to `FULL` to retrieve all
|
||||
// fields.
|
||||
SchemaView view = 2;
|
||||
}
|
||||
|
||||
// Request for the `ListSchemas` method.
|
||||
message ListSchemasRequest {
|
||||
// Required. The name of the project in which to list schemas.
|
||||
// Format is `projects/{project-id}`.
|
||||
string parent = 1 [
|
||||
(google.api.field_behavior) = REQUIRED,
|
||||
(google.api.resource_reference) = {
|
||||
type: "cloudresourcemanager.googleapis.com/Project"
|
||||
}
|
||||
];
|
||||
|
||||
// The set of Schema fields to return in the response. If not set, returns
|
||||
// Schemas with `name` and `type`, but not `definition`. Set to `FULL` to
|
||||
// retrieve all fields.
|
||||
SchemaView view = 2;
|
||||
|
||||
// Maximum number of schemas to return.
|
||||
int32 page_size = 3;
|
||||
|
||||
// The value returned by the last `ListSchemasResponse`; indicates that
|
||||
// this is a continuation of a prior `ListSchemas` call, and that the
|
||||
// system should return the next page of data.
|
||||
string page_token = 4;
|
||||
}
|
||||
|
||||
// Response for the `ListSchemas` method.
|
||||
message ListSchemasResponse {
|
||||
// The resulting schemas.
|
||||
repeated Schema schemas = 1;
|
||||
|
||||
// If not empty, indicates that there may be more schemas that match the
|
||||
// request; this value should be passed in a new `ListSchemasRequest`.
|
||||
string next_page_token = 2;
|
||||
}
|
||||
|
||||
// Request for the `DeleteSchema` method.
|
||||
message DeleteSchemaRequest {
|
||||
// Required. Name of the schema to delete.
|
||||
// Format is `projects/{project}/schemas/{schema}`.
|
||||
string name = 1 [
|
||||
(google.api.field_behavior) = REQUIRED,
|
||||
(google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
|
||||
];
|
||||
}
|
||||
|
||||
// Request for the `ValidateSchema` method.
|
||||
message ValidateSchemaRequest {
|
||||
// Required. The name of the project in which to validate schemas.
|
||||
// Format is `projects/{project-id}`.
|
||||
string parent = 1 [
|
||||
(google.api.field_behavior) = REQUIRED,
|
||||
(google.api.resource_reference) = {
|
||||
type: "cloudresourcemanager.googleapis.com/Project"
|
||||
}
|
||||
];
|
||||
|
||||
// Required. The schema object to validate.
|
||||
Schema schema = 2 [(google.api.field_behavior) = REQUIRED];
|
||||
}
|
||||
|
||||
// Response for the `ValidateSchema` method.
|
||||
message ValidateSchemaResponse {}
|
||||
|
||||
// Request for the `ValidateMessage` method.
|
||||
message ValidateMessageRequest {
|
||||
// Required. The name of the project in which to validate schemas.
|
||||
// Format is `projects/{project-id}`.
|
||||
string parent = 1 [
|
||||
(google.api.field_behavior) = REQUIRED,
|
||||
(google.api.resource_reference) = {
|
||||
type: "cloudresourcemanager.googleapis.com/Project"
|
||||
}
|
||||
];
|
||||
|
||||
oneof schema_spec {
|
||||
// Name of the schema against which to validate.
|
||||
//
|
||||
// Format is `projects/{project}/schemas/{schema}`.
|
||||
string name = 2 [
|
||||
(google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
|
||||
];
|
||||
|
||||
// Ad-hoc schema against which to validate
|
||||
Schema schema = 3;
|
||||
}
|
||||
|
||||
// Message to validate against the provided `schema_spec`.
|
||||
bytes message = 4;
|
||||
|
||||
// The encoding expected for messages
|
||||
Encoding encoding = 5;
|
||||
}
|
||||
|
||||
// Response for the `ValidateMessage` method.
|
||||
message ValidateMessageResponse {}
|
||||
|
||||
// Possible encoding types for messages.
|
||||
enum Encoding {
|
||||
// Unspecified
|
||||
ENCODING_UNSPECIFIED = 0;
|
||||
|
||||
// JSON encoding
|
||||
JSON = 1;
|
||||
|
||||
// Binary encoding, as defined by the schema type. For some schema types,
|
||||
// binary encoding may not be available.
|
||||
BINARY = 2;
|
||||
}
|
||||
@@ -21,6 +21,7 @@ tonic-build = <tonic-version>
|
||||
|
||||
### Simple
|
||||
|
||||
In `build.rs`:
|
||||
```rust
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tonic_build::compile_protos("proto/service.proto")?;
|
||||
@@ -41,3 +42,63 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
See [more examples here](https://github.com/hyperium/tonic/tree/master/examples)
|
||||
|
||||
### Google APIs example
|
||||
A good way to use Google API is probably using git submodules.
|
||||
|
||||
So suppose in our `proto` folder we do:
|
||||
```
|
||||
git submodule add https://github.com/googleapis/googleapis
|
||||
```
|
||||
|
||||
And a bunch of Google proto files in structure will be like this:
|
||||
```
|
||||
├── googleapis
|
||||
│ └── google
|
||||
│ ├── api
|
||||
│ │ ├── annotations.proto
|
||||
│ │ ├── client.proto
|
||||
│ │ ├── field_behavior.proto
|
||||
│ │ ├── http.proto
|
||||
│ │ └── resource.proto
|
||||
│ └── pubsub
|
||||
│ └── v1
|
||||
│ ├── pubsub.proto
|
||||
│ └── schema.proto
|
||||
```
|
||||
|
||||
Then we can generate Rust code via this setup in our `build.rs`
|
||||
```rust
|
||||
fn main() {
|
||||
tonic_build::configure()
|
||||
.build_server(false)
|
||||
//.out_dir("src/google") // you can change the generated code's location
|
||||
.compile(
|
||||
&["proto/googleapis/google/pubsub/v1/pubsub.proto"],
|
||||
&["proto/googleapis"], // specify the root location to search proto dependencies
|
||||
).unwrap();
|
||||
}
|
||||
```
|
||||
|
||||
Then you can reference the generated Rust like this this in your code:
|
||||
```rust
|
||||
pub mod api {
|
||||
tonic::include_proto!("google.pubsub.v1");
|
||||
}
|
||||
use api::{publisher_client::PublisherClient, ListTopicsRequest};
|
||||
```
|
||||
|
||||
Or if you want to save the generated code in your own code base,
|
||||
you can uncomment the line `.out_dir(...)` above, and in your lib file
|
||||
config a mod like this:
|
||||
```rust
|
||||
pub mod google {
|
||||
#[path = ""]
|
||||
pub mod pubsub {
|
||||
#[path = "google.pubsub.v1.rs"]
|
||||
pub mod v1;
|
||||
}
|
||||
}
|
||||
```
|
||||
See [the example here](https://github.com/hyperium/tonic/tree/master/examples/src/gcp)
|
||||
Reference in New Issue
Block a user