This document shows you how to view schema details for Pub/Sub topics.
Before you begin
- Understand how Pub/Sub schemas work .
- Create a schema .
Required roles and permissions
To get the permissions that
you need to view schema details and manage them,
ask your administrator to grant you the Pub/Sub Editor
( roles/pubsub.editor
)
IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations
.
This predefined role contains the permissions required to view schema details and manage them. To see the exact permissions that are required, expand the Required permissionssection:
Required permissions
The following permissions are required to view schema details and manage them:
- Create schema:
pubsub.schemas.create
- Attach schema to topic:
pubsub.schemas.attach
- Commit a schema revision:
pubsub.schemas.commit
- Delete a schema or a schema revision:
pubsub.schemas.delete
- Get a schema or schema revisions:
pubsub.schemas.get
- List schemas:
pubsub.schemas.list
- List schema revisions:
pubsub.schemas.listRevisions
- Rollback a schema:
pubsub.schemas.rollback
- Validate a message:
pubsub.schemas.validate
- Get the IAM policy for a schema:
pubsub.schemas.getIamPolicy
- Configure the IAM policy
for a schema:
pubsub.schemas.setIamPolicy
You might also be able to get these permissions with custom roles or other predefined roles .
You can grant roles and permissions to principals such as users, groups, domains, or service accounts. You can create a schema in one project and attach it to a topic located in a different project. Ensure that you have the required permissions for each project.
View schema details
You can get the details of a schema using the Google Cloud console, the gcloud CLI, the Pub/Sub API, or the Cloud Client Libraries. The results return the details for the latest revision ID.
Console
-
In the Google Cloud console, go to the Pub/Sub schemaspage.
-
Click the name of the schema that you want to view.
The Schema detailspage for the schema opens.
gcloud
To view the latest revision for a schema:
gcloud pubsub schemas describe SCHEMA_NAME
To view a specific revision for a schema:
gcloud pubsub schemas describe SCHEMA_ID@REVISION_ID
Where:
- REVISION_ID is the revision to which you want to roll back.
REST
To get the details of the latest revision of a schema, send a GET request like the following:
GET https://pubsub.googleapis.com/v1/projects/PROJECT_ID/schemas/SCHEMA_ID
For example, for a schema with schema ID schema-inventory
, send the
following request: https://pubsub.googleapis.com/v1/projects/PROJECT_ID/schemas/schema-inventory
To get the details of a specific revision of a schema, send a GET request like the following:
GET https://pubsub.googleapis.com/v1/projects/PROJECT_ID/schemas/SCHEMA_ID@REVISION_ID
For example, for a schema with schema ID schema-inventory
and revision ID fa567a3e
, send the following request: https://pubsub.googleapis.com/v1/projects/PROJECT_ID/schemas/schema-inventory@fa567a3e
Where:
- PROJECT_ID is your project ID.
- SCHEMA_ID is your schema ID.
- REVISION_ID is the ID of the revision of the specific schema.
If successful, the response body contains an instance of the Schema class .
C++
Before trying this sample, follow the C++ setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub C++ API reference documentation .
C#
Before trying this sample, follow the C# setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub C# API reference documentation .
Go
The following sample uses the major version of the Go Pub/Sub client library (v2). If you are still using the v1 library, see the migration guide to v2 . To see a list of v1 code samples, see the deprecated code samples .
Before trying this sample, follow the Go setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Go API reference documentation .
Java
Before trying this sample, follow the Java setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Java API reference documentation .
Node.js
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Node.js API reference documentation .
Node.js
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Node.js API reference documentation .
PHP
Before trying this sample, follow the PHP setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub PHP API reference documentation .
Python
Before trying this sample, follow the Python setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Python API reference documentation .
Ruby
The following sample uses Ruby Pub/Sub client library v3. If you are still using the v2 library, see the migration guide to v3 . To see a list of Ruby v2 code samples, see the deprecated code samples .
Before trying this sample, follow the Ruby setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Ruby API reference documentation .