Using the UI only, you can add an API spec at the same time you create a version. You
can either provide the URL to a specification that you can access or upload a specification file
directly from your system.
Console
To add a spec to a new version:
Follow the steps listed in Create an API version to get started. When you
reach the Add a new version page, you can optionally add a specification file to the version:
Enter a display name for the specification file. You can use any name you wish.
Select the specification file type. Specification type is a configurable system
attribute. See also System attributes.
Provide either a URI that points to a valid API specification file to which you have access,
or browse to an API spec file on your system.
Complete filling out the Add a new version page, and click Create when you are done.
Add a spec to an existing version
You can use the UI or REST API to add an API specification to an existing version.
Console
To add a spec directly to a version:
In the Google Cloud console, go to the API hub page.
Locate the API with the version you wish to modify. Use Filter to specify keywords to filter the list of APIs.
If needed, use Search to locate an API.
Select an API.
Click Add specification file.
Enter a display name for the specification file. You can use any name you wish.
Select the specification file type. Specification type is a configurable system
attribute. See also System attributes.
Provide either a URI that points to a valid API specification file to which you have access,
or browse to an API spec file on your system.
Select the version to add the specification file to.
Click Create.
REST
To add an API spec to a version, use the Add API spec API:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
'https://apihub.googleapis.com/v1/projects/API_PROJECT/locations/API_LOCATION/apis/API_ID/versions/VERSION_ID/specs?spec_id=SPEC_ID' \
-d "DATA_FILE or URI"
Replace the following:
API_PROJECT: The name of your API hub host project. The host project was selected
when API hub was provisioned.
API_LOCATION: The location of the host project. The location was chosen when API
hub was provisioned.
API_ID: The unique ID of an API resource.
VERSION_ID: The ID of a version attached to the API resource.
SPEC_ID: (Optional) The identifier of the spec. If not provided, a system-generated
ID will be used. The name must be a string of 4-63 characters, where valid characters are /[a-z][0-9]-/.
DATA_FILE or URI: Either a Base64-encoded file containing a valid API spec or a
link to a spec. See the REST example.
REST example
In this example, create a new spec in API hub with a Base64-encoded
OpenAPI spec. Upon upload, API hub parses the spec and creates a new spec entity that includes
descriptive metadata plus sets of operation and definition entities.
{
"name": "projects/common-dev-1/locations/us-central1/apis/streetcarts/versions/streetcartsv1/specs/dstreetcarts-spec",
"displayName": "Test Spec 1",
"specType": {},
"contents": {
"contents": [Base64-encoded contents of an OpenAPI 3.0.2 file] },
"details": {
"description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification.\nYou can find out more about Swagger at [https://swagger.io](https://swagger.io).",
"openApiSpecDetails": {
"format": "OPEN_API_SPEC_3_0",
"version": "1.0.11"
}
},
"createTime": "2024-04-04T22:39:05.674986Z",
"updateTime": "2024-04-04T22:39:05.674986Z"
}
Locate the API with the version containing the specification you wish to inspect. Use Filter to specify keywords to filter the list of APIs.
If needed, use Search to locate an API.
Click an API to view its details.
Under the Versions tab, locate the version you wish to inspect.
Select a version.
In the Specification file section, select a specification to view its details.
HUB_PROJECT: The name of your API hub host project. The host project was selected
when API hub was provisioned.
HUB_LOCATION: The location of the host project. The location was chosen when API
hub was provisioned.
API_ID: The unique ID of the API resource.
VERSION_ID: The unique ID of the version.
SPEC_ID: The unique ID of the specification.
Sample output:
{
"name": "projects/myproject/locations/us-central1/apis/streetcarts/versions/streetcartsv1/specs/dstreetcarts-spec",
"displayName": "Test Spec 1",
"details": {
"description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification.\nYou can find out more about Swagger at [https://swagger.io](https://swagger.io).",
"openApiSpecDetails": {
"format": "OPEN_API_SPEC_3_0",
"version": "1.0.11"
}
},
"createTime": "2024-04-04T22:39:05.098508600Z",
"updateTime": "2024-04-04T22:39:06.661264958Z"
}
Delete an API specification
This section explains how to delete an API specification from a version.
Deleting a spec will also delete the associated operations from the version.
Console
To delete API resources with the UI:
In the Google Cloud console, go to the API hub page.
Locate the API with the version that contains the spec you wish to delete. Use Filter to specify keywords to filter the list of APIs.
If needed, use Search to locate an API.
Click an API to view its details.
Under the Versions tab, locate the version that contains the specification you wish to delete.
Select the version.
In the Specification file section, select Delete from the Actions menu
in the row of the specification you wish to delete.
Locate the API with the version that contains the spec you wish to inspect. Use Filter to specify keywords to filter the list of APIs.
If needed, use Search to locate an API.
Click an API to view its details.
Under the Versions tab, locate the version that contains the specification you wish to inspect.
Click Results in the Lint column to view lint results.
Get specification contents
This feature lets you review the contents of a specification that was uploaded to API hub.
Console
To view details of a specification using the UI:
In the Google Cloud console, go to the API hub page.
Locate the API with the version that contains the spec you wish to delete. Use Filter to specify keywords to filter the list of APIs.
If needed, use Search to locate an API.
Click an API to view its details.
Under the Versions tab, locate the version that contains the specification you wish to inspect.
Click the spec name to view its contents.
REST
The API retrieves the raw, Base64-encoded contents of an API spec that was uploaded to API hub. Use the Get specification contents API: