xref: /aosp_15_r20/external/googleapis/google/pubsub/v1/schema.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2023 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
15syntax = "proto3";
16
17package google.pubsub.v1;
18
19import "google/api/annotations.proto";
20import "google/api/client.proto";
21import "google/api/field_behavior.proto";
22import "google/api/resource.proto";
23import "google/protobuf/empty.proto";
24import "google/protobuf/timestamp.proto";
25
26option cc_enable_arenas = true;
27option csharp_namespace = "Google.Cloud.PubSub.V1";
28option go_package = "cloud.google.com/go/pubsub/apiv1/pubsubpb;pubsubpb";
29option java_multiple_files = true;
30option java_outer_classname = "SchemaProto";
31option java_package = "com.google.pubsub.v1";
32option php_namespace = "Google\\Cloud\\PubSub\\V1";
33option ruby_package = "Google::Cloud::PubSub::V1";
34
35// Service for doing schema-related operations.
36service SchemaService {
37  option (google.api.default_host) = "pubsub.googleapis.com";
38  option (google.api.oauth_scopes) =
39      "https://www.googleapis.com/auth/cloud-platform,"
40      "https://www.googleapis.com/auth/pubsub";
41
42  // Creates a schema.
43  rpc CreateSchema(CreateSchemaRequest) returns (Schema) {
44    option (google.api.http) = {
45      post: "/v1/{parent=projects/*}/schemas"
46      body: "schema"
47    };
48    option (google.api.method_signature) = "parent,schema,schema_id";
49  }
50
51  // Gets a schema.
52  rpc GetSchema(GetSchemaRequest) returns (Schema) {
53    option (google.api.http) = {
54      get: "/v1/{name=projects/*/schemas/*}"
55    };
56    option (google.api.method_signature) = "name";
57  }
58
59  // Lists schemas in a project.
60  rpc ListSchemas(ListSchemasRequest) returns (ListSchemasResponse) {
61    option (google.api.http) = {
62      get: "/v1/{parent=projects/*}/schemas"
63    };
64    option (google.api.method_signature) = "parent";
65  }
66
67  // Lists all schema revisions for the named schema.
68  rpc ListSchemaRevisions(ListSchemaRevisionsRequest)
69      returns (ListSchemaRevisionsResponse) {
70    option (google.api.http) = {
71      get: "/v1/{name=projects/*/schemas/*}:listRevisions"
72    };
73    option (google.api.method_signature) = "name";
74  }
75
76  // Commits a new schema revision to an existing schema.
77  rpc CommitSchema(CommitSchemaRequest) returns (Schema) {
78    option (google.api.http) = {
79      post: "/v1/{name=projects/*/schemas/*}:commit"
80      body: "*"
81    };
82    option (google.api.method_signature) = "name,schema";
83  }
84
85  // Creates a new schema revision that is a copy of the provided revision_id.
86  rpc RollbackSchema(RollbackSchemaRequest) returns (Schema) {
87    option (google.api.http) = {
88      post: "/v1/{name=projects/*/schemas/*}:rollback"
89      body: "*"
90    };
91    option (google.api.method_signature) = "name,revision_id";
92  }
93
94  // Deletes a specific schema revision.
95  rpc DeleteSchemaRevision(DeleteSchemaRevisionRequest) returns (Schema) {
96    option (google.api.http) = {
97      delete: "/v1/{name=projects/*/schemas/*}:deleteRevision"
98    };
99    option (google.api.method_signature) = "name,revision_id";
100  }
101
102  // Deletes a schema.
103  rpc DeleteSchema(DeleteSchemaRequest) returns (google.protobuf.Empty) {
104    option (google.api.http) = {
105      delete: "/v1/{name=projects/*/schemas/*}"
106    };
107    option (google.api.method_signature) = "name";
108  }
109
110  // Validates a schema.
111  rpc ValidateSchema(ValidateSchemaRequest) returns (ValidateSchemaResponse) {
112    option (google.api.http) = {
113      post: "/v1/{parent=projects/*}/schemas:validate"
114      body: "*"
115    };
116    option (google.api.method_signature) = "parent,schema";
117  }
118
119  // Validates a message against a schema.
120  rpc ValidateMessage(ValidateMessageRequest)
121      returns (ValidateMessageResponse) {
122    option (google.api.http) = {
123      post: "/v1/{parent=projects/*}/schemas:validateMessage"
124      body: "*"
125    };
126  }
127}
128
129// A schema resource.
130message Schema {
131  option (google.api.resource) = {
132    type: "pubsub.googleapis.com/Schema"
133    pattern: "projects/{project}/schemas/{schema}"
134  };
135
136  // Possible schema definition types.
137  enum Type {
138    // Default value. This value is unused.
139    TYPE_UNSPECIFIED = 0;
140
141    // A Protocol Buffer schema definition.
142    PROTOCOL_BUFFER = 1;
143
144    // An Avro schema definition.
145    AVRO = 2;
146  }
147
148  // Required. Name of the schema.
149  // Format is `projects/{project}/schemas/{schema}`.
150  string name = 1 [(google.api.field_behavior) = REQUIRED];
151
152  // The type of the schema definition.
153  Type type = 2;
154
155  // The definition of the schema. This should contain a string representing
156  // the full definition of the schema that is a valid schema definition of
157  // the type specified in `type`.
158  string definition = 3;
159
160  // Output only. Immutable. The revision ID of the schema.
161  string revision_id = 4 [
162    (google.api.field_behavior) = IMMUTABLE,
163    (google.api.field_behavior) = OUTPUT_ONLY
164  ];
165
166  // Output only. The timestamp that the revision was created.
167  google.protobuf.Timestamp revision_create_time = 6
168      [(google.api.field_behavior) = OUTPUT_ONLY];
169}
170
171// View of Schema object fields to be returned by GetSchema and ListSchemas.
172enum SchemaView {
173  // The default / unset value.
174  // The API will default to the BASIC view.
175  SCHEMA_VIEW_UNSPECIFIED = 0;
176
177  // Include the name and type of the schema, but not the definition.
178  BASIC = 1;
179
180  // Include all Schema object fields.
181  FULL = 2;
182}
183
184// Request for the CreateSchema method.
185message CreateSchemaRequest {
186  // Required. The name of the project in which to create the schema.
187  // Format is `projects/{project-id}`.
188  string parent = 1 [
189    (google.api.field_behavior) = REQUIRED,
190    (google.api.resource_reference) = {
191      child_type: "pubsub.googleapis.com/Schema"
192    }
193  ];
194
195  // Required. The schema object to create.
196  //
197  // This schema's `name` parameter is ignored. The schema object returned
198  // by CreateSchema will have a `name` made using the given `parent` and
199  // `schema_id`.
200  Schema schema = 2 [(google.api.field_behavior) = REQUIRED];
201
202  // The ID to use for the schema, which will become the final component of
203  // the schema's resource name.
204  //
205  // See https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names for
206  // resource name constraints.
207  string schema_id = 3;
208}
209
210// Request for the GetSchema method.
211message GetSchemaRequest {
212  // Required. The name of the schema to get.
213  // Format is `projects/{project}/schemas/{schema}`.
214  string name = 1 [
215    (google.api.field_behavior) = REQUIRED,
216    (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
217  ];
218
219  // The set of fields to return in the response. If not set, returns a Schema
220  // with all fields filled out. Set to `BASIC` to omit the `definition`.
221  SchemaView view = 2;
222}
223
224// Request for the `ListSchemas` method.
225message ListSchemasRequest {
226  // Required. The name of the project in which to list schemas.
227  // Format is `projects/{project-id}`.
228  string parent = 1 [
229    (google.api.field_behavior) = REQUIRED,
230    (google.api.resource_reference) = {
231      type: "cloudresourcemanager.googleapis.com/Project"
232    }
233  ];
234
235  // The set of Schema fields to return in the response. If not set, returns
236  // Schemas with `name` and `type`, but not `definition`. Set to `FULL` to
237  // retrieve all fields.
238  SchemaView view = 2;
239
240  // Maximum number of schemas to return.
241  int32 page_size = 3;
242
243  // The value returned by the last `ListSchemasResponse`; indicates that
244  // this is a continuation of a prior `ListSchemas` call, and that the
245  // system should return the next page of data.
246  string page_token = 4;
247}
248
249// Response for the `ListSchemas` method.
250message ListSchemasResponse {
251  // The resulting schemas.
252  repeated Schema schemas = 1;
253
254  // If not empty, indicates that there may be more schemas that match the
255  // request; this value should be passed in a new `ListSchemasRequest`.
256  string next_page_token = 2;
257}
258
259// Request for the `ListSchemaRevisions` method.
260message ListSchemaRevisionsRequest {
261  // Required. The name of the schema to list revisions for.
262  string name = 1 [
263    (google.api.field_behavior) = REQUIRED,
264    (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
265  ];
266
267  // The set of Schema fields to return in the response. If not set, returns
268  // Schemas with `name` and `type`, but not `definition`. Set to `FULL` to
269  // retrieve all fields.
270  SchemaView view = 2;
271
272  // The maximum number of revisions to return per page.
273  int32 page_size = 3;
274
275  // The page token, received from a previous ListSchemaRevisions call.
276  // Provide this to retrieve the subsequent page.
277  string page_token = 4;
278}
279
280// Response for the `ListSchemaRevisions` method.
281message ListSchemaRevisionsResponse {
282  // The revisions of the schema.
283  repeated Schema schemas = 1;
284
285  // A token that can be sent as `page_token` to retrieve the next page.
286  // If this field is empty, there are no subsequent pages.
287  string next_page_token = 2;
288}
289
290// Request for CommitSchema method.
291message CommitSchemaRequest {
292  // Required. The name of the schema we are revising.
293  // Format is `projects/{project}/schemas/{schema}`.
294  string name = 1 [
295    (google.api.field_behavior) = REQUIRED,
296    (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
297  ];
298
299  // Required. The schema revision to commit.
300  Schema schema = 2 [(google.api.field_behavior) = REQUIRED];
301}
302
303// Request for the `RollbackSchema` method.
304message RollbackSchemaRequest {
305  // Required. The schema being rolled back with revision id.
306  string name = 1 [
307    (google.api.field_behavior) = REQUIRED,
308    (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
309  ];
310
311  // Required. The revision ID to roll back to.
312  // It must be a revision of the same schema.
313  //
314  //   Example: c7cfa2a8
315  string revision_id = 2 [(google.api.field_behavior) = REQUIRED];
316}
317
318// Request for the `DeleteSchemaRevision` method.
319message DeleteSchemaRevisionRequest {
320  // Required. The name of the schema revision to be deleted, with a revision ID
321  // explicitly included.
322  //
323  // Example: `projects/123/schemas/my-schema@c7cfa2a8`
324  string name = 1 [
325    (google.api.field_behavior) = REQUIRED,
326    (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
327  ];
328
329  // Optional. This field is deprecated and should not be used for specifying
330  // the revision ID. The revision ID should be specified via the `name`
331  // parameter.
332  string revision_id = 2
333      [deprecated = true, (google.api.field_behavior) = OPTIONAL];
334}
335
336// Request for the `DeleteSchema` method.
337message DeleteSchemaRequest {
338  // Required. Name of the schema to delete.
339  // Format is `projects/{project}/schemas/{schema}`.
340  string name = 1 [
341    (google.api.field_behavior) = REQUIRED,
342    (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
343  ];
344}
345
346// Request for the `ValidateSchema` method.
347message ValidateSchemaRequest {
348  // Required. The name of the project in which to validate schemas.
349  // Format is `projects/{project-id}`.
350  string parent = 1 [
351    (google.api.field_behavior) = REQUIRED,
352    (google.api.resource_reference) = {
353      type: "cloudresourcemanager.googleapis.com/Project"
354    }
355  ];
356
357  // Required. The schema object to validate.
358  Schema schema = 2 [(google.api.field_behavior) = REQUIRED];
359}
360
361// Response for the `ValidateSchema` method.
362// Empty for now.
363message ValidateSchemaResponse {}
364
365// Request for the `ValidateMessage` method.
366message ValidateMessageRequest {
367  // Required. The name of the project in which to validate schemas.
368  // Format is `projects/{project-id}`.
369  string parent = 1 [
370    (google.api.field_behavior) = REQUIRED,
371    (google.api.resource_reference) = {
372      type: "cloudresourcemanager.googleapis.com/Project"
373    }
374  ];
375
376  oneof schema_spec {
377    // Name of the schema against which to validate.
378    //
379    // Format is `projects/{project}/schemas/{schema}`.
380    string name = 2 [
381      (google.api.resource_reference) = { type: "pubsub.googleapis.com/Schema" }
382    ];
383
384    // Ad-hoc schema against which to validate
385    Schema schema = 3;
386  }
387
388  // Message to validate against the provided `schema_spec`.
389  bytes message = 4;
390
391  // The encoding expected for messages
392  Encoding encoding = 5;
393}
394
395// Response for the `ValidateMessage` method.
396// Empty for now.
397message ValidateMessageResponse {}
398
399// Possible encoding types for messages.
400enum Encoding {
401  // Unspecified
402  ENCODING_UNSPECIFIED = 0;
403
404  // JSON encoding
405  JSON = 1;
406
407  // Binary encoding, as defined by the schema type. For some schema types,
408  // binary encoding may not be available.
409  BINARY = 2;
410}
411