GitHub Enterprise Server Sync

This guide is for self-hosted GitHub Enterprise Servers. If you use, see GitHub Sync.

You can integrate SwaggerHub with GitHub Enterprise Server. This allows you to synchronize your API definition, auto-generated server code, or client SDK with an existing GitHub repository. You can fully control which files will be added, updated, or ignored in the target repository.

Supported OpenAPI versions

GitHub Enterprise Server integration supports OpenAPI 2.0 and OpenAPI 3.0. If you use SwaggerHub On-Premise, note that syncing OpenAPI 3.0 definitions requires v. 1.19.1 or later.


SwaggerHub SaaS

  • Your GitHub Enterprise Server must be accessible from the public Internet and allow connections from our IP addresses. If this is not possible, use SwaggerHub On-Premise which you can deploy in your own network.

  • If your GitHub Enterprise Server uses an SSL certificate, it must be issued by a publicly-trusted certificate authority (CA), such as VeriSign, DigiCert, or others.

    Self-signed certificates and private CAs are not supported in SwaggerHub SaaS, but are supported in SwaggerHub On-Premise.

SwaggerHub On-Premise

  • Your GitHub Enterprise Server must be accessible from the SwaggerHub On-Premise server, either directly or via proxy.

  • Before using the integration, specify the target GitHub Enterprise Server in the Admin Console. See Configuring GitHub Integration.

  • If your GitHub Enterprise Server uses a self-signed SSL certificate or a certificate issued by a private CA, you need to add it to the trusted certificates on your SwaggerHub On-Premise instance.


  • To configure the integration, you must be the API owner or a collaborator with Edit permissions.

  • The integration is bound to a specific version of the API and is not automatically copied to new versions. When you add a new version, you need to configure the integration for the new version manually.

Prepare the repository

The target Git repository must not be empty. If it is empty, add at least one file to it, for example, a README or .gitignore file.

Configure GitHub Enterprise Sync

GitHub Enterprise Sync can be configured by the API owner or collaborators with the Editor role.

  1. Open the API page in SwaggerHub.

  2. If the API has several versions, select the version whose code you want to store on GitHub.

    Selecting an API version
  3. Click the API name, switch to the Integrations tab, and click Add New Integrations:

    Add New Integration menu command
  4. Select the GitHub Enterprise Sync integration (or GitHub Sync if you use SwaggerHub On-Premise).

  5. In the subsequent dialog, specify the integration parameters:

    • Name – Required. A display name for the integration.

    • GitHub Enterprise Host – The URL of your GitHub Enterprise Server, for example, Make sure to include http:// or https:// at the beginning.


      This option is only used in SwaggerHub SaaS. In SwaggerHub On-Premise, the target GitHub Enterprise Server for integrations is specified in the Admin Console.

    • GitHub Enterprise Token (or GitHub Token) – A personal access token to authenticate with GitHub. You can create this token on the https://<github-host>/settings/tokens page. The token must have the public_repo scope if the target repository is public, or the repo scope if it is private. For detailed instructions, see Creating a personal access token for the command line.

    • Click Next in the GitHub Token edit box to continue. SwaggerHub will validate the token and then display other parameters.

    • Repository Owner – Select the GitHub user or organization that owns the desired repository. The list displays only those accounts your GitHub token has access to.

    • Repository – Select the repository to push the code to. This repository must not be empty. It must contain at least one commit, for example, a README or .gitignore file.

    • Sync Method – Select the synchronization type:

      Sync method


      Basic Sync

      SwaggerHub will manage all files in the specified branch and folder: new files will be added, existing files will be overwritten, and unused files will be deleted.

      Note: In SwaggerHub On-Premise versions up to 1.23.1, Basic Sync always pushes to the branch named SWAGGERHUB. To use a different branch, select Advanced Sync or upgrade your SwaggerHub On-Premise instance to the latest version.

      Advanced Sync

      Similar to Basic Sync, but you can specify which files will be overwritten or ignored. Use this method if the output folder contains existing files that you want to keep.

    • Branch – Required. The repository branch to push the code to. If this branch does not exist, it will be created based on the repository’s default branch.

    • Generated API Code – Required. Select what you want to generate: server code, client SDK, API documentation, or the OpenAPI definition itself as YAML or JSON. See here for a list of supported languages and frameworks.


      To customize code generation options, such as package names, use the Export > Codegen Options menu in the SwaggerHub editor. See Code Generation Options for details.

    • Output Folder – The output folder for the generated code, relative to the repository root. For example, server or sdk/android. If this folder does not exist, it will be created. If the output folder is not specified, SwaggerHub will create files and folders in the repository root.


      Use forward slashes (/) as path separators:

      folder/subfolder1/subfolder2 – Correct

      folder\subfolder1\subfolder2 – Incorrect

    • Paths – Available only if you selected Advanced Sync. Use these options to control which files and folders will be created, updated, deleted, or ignored during synchronization. All the paths are relative to the Output Folder. You need to specify either Partially Managed Paths or Fully Managed Paths.

      • Partially Managed Paths – These files and folders will be created if they do not exist, but the existing files and folders will not be modified. The wildcard * indicates all files and folders in the Output Folder.

      • Fully Managed Paths – These files and folders will be completely managed by the integration: new files will be added, the existing files will be overwritten, and the files that are no longer used will be deleted. You can use * as a wildcard for all files.

      • Ignored Paths – These files and folders will remain as is and will not be changed in any way.


      Use forward slashes (/) as path separators, for example, sdk/android/

    • Output file – Only used if Generated API Code is JSON or YAML, that is, the OpenAPI definition itself. Specifies the name of the .json or .yaml file to create, for example, swagger.yaml or petstore.json. This file will be created in the Output Folder.

    • Enabled – Select or clear this check box to enable or disable the integration.

  6. Click Create, then Done.

Push to GitHub

When you are ready to push your changes, click Sync on the editor toolbar, enter a commit message and click Push. SwaggerHub will generate the specified target (server code, client code, API documentation or an OpenAPI JSON or YAML file) and push it to the configured repository and branch.

Pushing to source control from SwaggerHub

Commits are made on behalf of the user associated with the access token. If synchronization fails (for example, due to a permission problem), you will see an integration error at the top of the SwaggerHub Editor.

Disable GitHub Enterprise Sync

If you no longer want to sync with GitHub, you can disable or delete the GitHub Enterprise Sync integration. The existing files will remain in your GitHub repository, but SwaggerHub will not update them anymore.


If the integration fails with an error, check the access token expiration date. If it is about to expire, generate a new token and update the token in the integration settings. If the token has expired, generate a new one and create the integration anew.

See Also

Publication date: