Sync API Definitions Between Source Control and API Hub for Design
API Hub for Design integrates with many source control systems allowing you to synchronize your API definitions with an external repository. This integration is bi-directional: you can push changes from API Hub for Design to source control and pull changes from source control to API Hub for Design. This way, your API definitions can be kept in sync regardless of where the changes were made.
Considerations for API Hub for Design users
Pulling changes from source control is supported only for APIs created in organizations on the Enterprise plan.
If you use a self-hosted source control system, such as GitHub Enterprise Server or Bitbucket Server:
It must be accessible from the public Internet. You may need to allow connections from our IP addresses in your firewall rules.
Its SSL certificate must be issued by a public Certificate Authority (CA). Self-signed and privately signed SSL certificates are not supported.
Configure integration with source control
To use bi-directional sync, you need to configure a source control integration and specify the repository and branch to synchronize with. For SCM Pull to be enabled, the integration target must be an unresolved JSON or YAML file.
Open the API in API Hub for Design Editor.
If the API has several versions, select the version that you want to sync with source control.
Click the API name, switch to the Integrations tab, and click Add New Integrations:
Select your source control type – GitHub, GitHub Enterprise Server, GitLab, Bitbucket Cloud, Bitbucket Server, orAzure DevOps Services.
Specify the following parameters for the integration. For other available parameters, see the documentation on the GitHub, GitLab, Bitbucket Cloud, Bitbucket Server and Azure DevOps Services integrations.
Repository Owner, Repository, and Branch – the repository and branch to synchronize to.
Sync Method – select Basic Sync.
Generated API Code – select JSON (Unresolved) or YAML (Unresolved). This option specifies the format of the API definition file in source control.
Important
Make sure to use the Unresolved option and not Resolved.
Output Folder – the repository folder that contains the API definition file, relative to the repository root. For example,
src/spec
. If omitted, API Hub for Design will push to and pull from the repository’s root folder.The folder path is case-sensitive. Use forward slashes
/
as path separators. Do not add leading and trailing slashes.folder/subfolder1/subfolder2
– Correct\folder\subfolder1\subfolder2\
– IncorrectOutput File – The file name, relative to the Output Folder. For example,
openapi.yaml
ormyapi.json
. Case-sensitive.
Click Create, then click Done.
After the integration is set up, you can use the Sync button on the editor toolbar to push to and pull from the connected repository branch.
Push to source control
When you are ready to push your changes, click Sync, enter a commit message, and click Push. API Hub for Design will commit and push the API definition to the connected repository branch. This will completely overwrite the existing file in that branch.
Pull from source control
Any user with Edit permissions on the current API can pull the changes from source control. The API in API Hub for Design must be unpublished (that is, not read-only) in order for pull to work.
To pull the changes, click Sync, then click Pull. The content in the editor will be replaced with the file content from the connected repository branch, with JSON automatically converted to YAML. $ref values are kept as is; external $refs are not resolved.
The changes are pulled as an unsaved draft. Click Save to save the changes, or use the Revert to Last Saved command to undo the pulled changes.
Notes
If the pulled file contains a different
info.version
value, API Hub for Design Editor will show the Create New Version button instead of Save. When creating a new API version in API Hub for Design, you can carry over existing source control integrations to the new version. Integrations that were carried over use an auto-generated branch name, so review and update the branch name afterwards if needed.If the API in API Hub for Design is in the OpenAPI 2.0 format and the pulled file is OpenAPI 3.0, API Hub for Design will prompt you to convert the API to OpenAPI 3.0.
To automate the pulling of changes from source control, you can set up a CI/CD process that would upload your API definition to API Hub for Design every time a commit is made in the repository. To upload the file programmatically, you can use the API Hub for Design CLI or Registry API to upload the updated file to API Hub for Design.