Skip to content

Commit 41d8fbf

Browse files
Google APIscopybara-github
authored andcommitted
feat: add schema service
PiperOrigin-RevId: 348038736
1 parent be40b52 commit 41d8fbf

4 files changed

Lines changed: 328 additions & 5 deletions

File tree

google/pubsub/v1/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ load("@com_google_googleapis_imports//:imports.bzl", "proto_library_with_info")
1010

1111
proto_library(
1212
name = "pubsub_proto",
13-
srcs = ["pubsub.proto"],
13+
srcs = [
14+
"pubsub.proto",
15+
"schema.proto",
16+
],
1417
deps = [
1518
"//google/api:annotations_proto",
1619
"//google/api:client_proto",

google/pubsub/v1/pubsub.proto

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import "google/protobuf/duration.proto";
2424
import "google/protobuf/empty.proto";
2525
import "google/protobuf/field_mask.proto";
2626
import "google/protobuf/timestamp.proto";
27+
import "google/pubsub/v1/schema.proto";
2728

2829
option cc_enable_arenas = true;
2930
option csharp_namespace = "Google.Cloud.PubSub.V1";
@@ -42,8 +43,8 @@ service Publisher {
4243
"https://www.googleapis.com/auth/cloud-platform,"
4344
"https://www.googleapis.com/auth/pubsub";
4445

45-
// Creates the given topic with the given name. See the [resource name rules](
46-
// https://cloud.google.com/pubsub/docs/admin#resource_names).
46+
// Creates the given topic with the given name. See the [resource name rules]
47+
// (https://cloud.google.com/pubsub/docs/admin#resource_names).
4748
rpc CreateTopic(Topic) returns (Topic) {
4849
option (google.api.http) = {
4950
put: "/v1/{name=projects/*/topics/*}"
@@ -143,6 +144,21 @@ message MessageStoragePolicy {
143144
repeated string allowed_persistence_regions = 1;
144145
}
145146

147+
// Settings for validating messages published against a schema.
148+
message SchemaSettings {
149+
// Required. The name of the schema that messages published should be
150+
// validated against. Format is `projects/{project}/schemas/{schema}`. The
151+
// value of this field will be `_deleted-schema_` if the schema has been
152+
// deleted.
153+
string schema = 1 [
154+
(google.api.field_behavior) = REQUIRED,
155+
(google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
156+
];
157+
158+
// The encoding of messages validated against `schema`.
159+
Encoding encoding = 2;
160+
}
161+
146162
// A topic resource.
147163
message Topic {
148164
option (google.api.resource) = {
@@ -173,6 +189,15 @@ message Topic {
173189
//
174190
// The expected format is `projects/*/locations/*/keyRings/*/cryptoKeys/*`.
175191
string kms_key_name = 5;
192+
193+
// Settings for validating messages published against a schema.
194+
//
195+
// EXPERIMENTAL: Schema support is in development and may not work yet.
196+
SchemaSettings schema_settings = 6;
197+
198+
// Reserved for future use. This field is set only in responses from the
199+
// server; it is ignored if it is set in any requests.
200+
bool satisfies_pzs = 7;
176201
}
177202

178203
// A message that is published by publishers and consumed by subscribers. The
@@ -587,8 +612,8 @@ service Subscriber {
587612
}
588613

589614
// Seeks an existing subscription to a point in time or to a given snapshot,
590-
// whichever is provided in the request. Snapshots are used in [Seek](
591-
// https://cloud.google.com/pubsub/docs/replay-overview) operations, which
615+
// whichever is provided in the request. Snapshots are used in [Seek]
616+
// (https://cloud.google.com/pubsub/docs/replay-overview) operations, which
592617
// allow you to manage message acknowledgments in bulk. That is, you can set
593618
// the acknowledgment state of messages in an existing subscription to the
594619
// state captured by a snapshot. Note that both the subscription and the

google/pubsub/v1/pubsub_v1.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ title: Cloud Pub/Sub API
55

66
apis:
77
- name: google.pubsub.v1.Publisher
8+
- name: google.pubsub.v1.SchemaService
89
- name: google.pubsub.v1.Subscriber
910

1011
documentation:
@@ -80,6 +81,11 @@ authentication:
8081
canonical_scopes: |-
8182
https://www.googleapis.com/auth/cloud-platform,
8283
https://www.googleapis.com/auth/pubsub
84+
- selector: 'google.pubsub.v1.SchemaService.*'
85+
oauth:
86+
canonical_scopes: |-
87+
https://www.googleapis.com/auth/cloud-platform,
88+
https://www.googleapis.com/auth/pubsub
8389
- selector: 'google.pubsub.v1.Subscriber.*'
8490
oauth:
8591
canonical_scopes: |-

google/pubsub/v1/schema.proto

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
package google.pubsub.v1;
18+
19+
import "google/api/annotations.proto";
20+
import "google/api/client.proto";
21+
import "google/api/field_behavior.proto";
22+
import "google/api/resource.proto";
23+
import "google/protobuf/empty.proto";
24+
25+
option cc_enable_arenas = true;
26+
option csharp_namespace = "Google.Cloud.PubSub.V1";
27+
option go_package = "google.golang.org/genproto/googleapis/pubsub/v1;pubsub";
28+
option java_multiple_files = true;
29+
option java_outer_classname = "SchemaProto";
30+
option java_package = "com.google.pubsub.v1";
31+
option php_namespace = "Google\\Cloud\\PubSub\\V1";
32+
option ruby_package = "Google::Cloud::PubSub::V1";
33+
34+
// Service for doing schema-related operations.
35+
//
36+
// EXPERIMENTAL: The Schema service is in development and may not work yet.
37+
38+
service SchemaService {
39+
option (google.api.default_host) = "pubsub.googleapis.com";
40+
option (google.api.oauth_scopes) =
41+
"https://www.googleapis.com/auth/cloud-platform,"
42+
"https://www.googleapis.com/auth/pubsub";
43+
44+
// Creates a schema.
45+
rpc CreateSchema(CreateSchemaRequest) returns (Schema) {
46+
option (google.api.http) = {
47+
post: "/v1/{parent=projects/*}/schemas"
48+
body: "schema"
49+
};
50+
option (google.api.method_signature) = "parent,schema,schema_id";
51+
}
52+
53+
// Gets a schema.
54+
rpc GetSchema(GetSchemaRequest) returns (Schema) {
55+
option (google.api.http) = {
56+
get: "/v1/{name=projects/*/schemas/*}"
57+
};
58+
option (google.api.method_signature) = "name";
59+
}
60+
61+
// Lists schemas in a project.
62+
rpc ListSchemas(ListSchemasRequest) returns (ListSchemasResponse) {
63+
option (google.api.http) = {
64+
get: "/v1/{parent=projects/*}/schemas"
65+
};
66+
option (google.api.method_signature) = "parent";
67+
}
68+
69+
// Deletes a schema.
70+
rpc DeleteSchema(DeleteSchemaRequest) returns (google.protobuf.Empty) {
71+
option (google.api.http) = {
72+
delete: "/v1/{name=projects/*/schemas/*}"
73+
};
74+
option (google.api.method_signature) = "name";
75+
}
76+
77+
// Validates a schema.
78+
rpc ValidateSchema(ValidateSchemaRequest) returns (ValidateSchemaResponse) {
79+
option (google.api.http) = {
80+
post: "/v1/{parent=projects/*}/schemas:validate"
81+
body: "*"
82+
};
83+
option (google.api.method_signature) = "parent,schema";
84+
}
85+
86+
// Validates a message against a schema.
87+
rpc ValidateMessage(ValidateMessageRequest)
88+
returns (ValidateMessageResponse) {
89+
option (google.api.http) = {
90+
post: "/v1/{parent=projects/*}/schemas:validateMessage"
91+
body: "*"
92+
};
93+
}
94+
}
95+
96+
// A schema resource.
97+
message Schema {
98+
option (google.api.resource) = {
99+
type: "pubsub.googleapis.com/Schema"
100+
pattern: "projects/{project}/schemas/{schema}"
101+
};
102+
103+
// Possible schema definition types.
104+
enum Type {
105+
// Default value. This value is unused.
106+
TYPE_UNSPECIFIED = 0;
107+
108+
// A Protocol Buffer schema definition.
109+
PROTOCOL_BUFFER = 1;
110+
111+
// An Avro schema definition.
112+
AVRO = 2;
113+
}
114+
115+
// Required. Name of the schema.
116+
// Format is `projects/{project}/schemas/{schema}`.
117+
string name = 1 [(google.api.field_behavior) = REQUIRED];
118+
119+
// The type of the schema definition.
120+
Type type = 2;
121+
122+
// The definition of the schema. This should contain a string representing
123+
// the full definition of the schema that is a valid schema definition of
124+
// the type specified in `type`.
125+
string definition = 3;
126+
}
127+
128+
// Request for the CreateSchema method.
129+
message CreateSchemaRequest {
130+
// Required. The name of the project in which to create the schema.
131+
// Format is `projects/{project-id}`.
132+
string parent = 1 [
133+
(google.api.field_behavior) = REQUIRED,
134+
(google.api.resource_reference) = {
135+
child_type: "pubsub.googleapis.com/Schema"
136+
}
137+
];
138+
139+
// Required. The schema object to create.
140+
//
141+
// This schema's `name` parameter is ignored. The schema object returned
142+
// by CreateSchema will have a `name` made using the given `parent` and
143+
// `schema_id`.
144+
Schema schema = 2 [(google.api.field_behavior) = REQUIRED];
145+
146+
// The ID to use for the schema, which will become the final component of
147+
// the schema's resource name.
148+
//
149+
// See https://cloud.google.com/pubsub/docs/admin#resource_names for resource
150+
// name constraints.
151+
string schema_id = 3;
152+
}
153+
154+
// View of Schema object fields to be returned by GetSchema and ListSchemas.
155+
enum SchemaView {
156+
// The default / unset value.
157+
// The API will default to the BASIC view.
158+
SCHEMA_VIEW_UNSPECIFIED = 0;
159+
160+
// Include the name and type of the schema, but not the definition.
161+
BASIC = 1;
162+
163+
// Include all Schema object fields.
164+
FULL = 2;
165+
}
166+
167+
// Request for the GetSchema method.
168+
message GetSchemaRequest {
169+
// Required. The name of the schema to get.
170+
// Format is `projects/{project}/schemas/{schema}`.
171+
string name = 1 [
172+
(google.api.field_behavior) = REQUIRED,
173+
(google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
174+
];
175+
176+
// The set of fields to return in the response. If not set, returns a Schema
177+
// with `name` and `type`, but not `definition`. Set to `FULL` to retrieve all
178+
// fields.
179+
SchemaView view = 2;
180+
}
181+
182+
// Request for the `ListSchemas` method.
183+
message ListSchemasRequest {
184+
// Required. The name of the project in which to list schemas.
185+
// Format is `projects/{project-id}`.
186+
string parent = 1 [
187+
(google.api.field_behavior) = REQUIRED,
188+
(google.api.resource_reference) = {
189+
type: "cloudresourcemanager.googleapis.com/Project"
190+
}
191+
];
192+
193+
// The set of Schema fields to return in the response. If not set, returns
194+
// Schemas with `name` and `type`, but not `definition`. Set to `FULL` to
195+
// retrieve all fields.
196+
SchemaView view = 2;
197+
198+
// Maximum number of schemas to return.
199+
int32 page_size = 3;
200+
201+
// The value returned by the last `ListSchemasResponse`; indicates that
202+
// this is a continuation of a prior `ListSchemas` call, and that the
203+
// system should return the next page of data.
204+
string page_token = 4;
205+
}
206+
207+
// Response for the `ListSchemas` method.
208+
message ListSchemasResponse {
209+
// The resulting schemas.
210+
repeated Schema schemas = 1;
211+
212+
// If not empty, indicates that there may be more schemas that match the
213+
// request; this value should be passed in a new `ListSchemasRequest`.
214+
string next_page_token = 2;
215+
}
216+
217+
// Request for the `DeleteSchema` method.
218+
message DeleteSchemaRequest {
219+
// Required. Name of the schema to delete.
220+
// Format is `projects/{project}/schemas/{schema}`.
221+
string name = 1 [
222+
(google.api.field_behavior) = REQUIRED,
223+
(google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
224+
];
225+
}
226+
227+
// Request for the `ValidateSchema` method.
228+
message ValidateSchemaRequest {
229+
// Required. The name of the project in which to validate schemas.
230+
// Format is `projects/{project-id}`.
231+
string parent = 1 [
232+
(google.api.field_behavior) = REQUIRED,
233+
(google.api.resource_reference) = {
234+
type: "cloudresourcemanager.googleapis.com/Project"
235+
}
236+
];
237+
238+
// Required. The schema object to validate.
239+
Schema schema = 2 [(google.api.field_behavior) = REQUIRED];
240+
}
241+
242+
// Response for the `ValidateSchema` method.
243+
message ValidateSchemaResponse {}
244+
245+
// Request for the `ValidateMessage` method.
246+
message ValidateMessageRequest {
247+
// Required. The name of the project in which to validate schemas.
248+
// Format is `projects/{project-id}`.
249+
string parent = 1 [
250+
(google.api.field_behavior) = REQUIRED,
251+
(google.api.resource_reference) = {
252+
type: "cloudresourcemanager.googleapis.com/Project"
253+
}
254+
];
255+
256+
oneof schema_spec {
257+
// Name of the schema against which to validate.
258+
//
259+
// Format is `projects/{project}/schemas/{schema}`.
260+
string name = 2 [
261+
(google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
262+
];
263+
264+
// Ad-hoc schema against which to validate
265+
Schema schema = 3;
266+
}
267+
268+
// Message to validate against the provided `schema_spec`.
269+
bytes message = 4;
270+
271+
// The encoding expected for messages
272+
Encoding encoding = 5;
273+
}
274+
275+
// Response for the `ValidateMessage` method.
276+
message ValidateMessageResponse {}
277+
278+
// Possible encoding types for messages.
279+
enum Encoding {
280+
// Unspecified
281+
ENCODING_UNSPECIFIED = 0;
282+
283+
// JSON encoding
284+
JSON = 1;
285+
286+
// Binary encoding, as defined by the schema type. For some schema types,
287+
// binary encoding may not be available.
288+
BINARY = 2;
289+
}

0 commit comments

Comments
 (0)