Using private templates

Found an error? Have a suggestion?Edit this page on GitHub

Generator allows fetching the template from private repositories like Verdaccio, Nexus, npm, etc.
By default, the generator fetches the template from the public npm registry configured in the npm configuration.
To fetch the template from a private registry, you need to provide the registry URL and authentication details in the .npmrc. For more information read the docs.
However, you can override the default behavior by providing the registry URL and authentication details as arguments of the commandline.

Private registry using .npmrc:

1npm config set registry http://verdaccio:4873
2npm config set //verdaccio:4873/:_auth=$(echo -n 'username:password' | base64)
  • npm config set registry : Provide the registry URL that points to the registry URL.
  • npm config set _auth : Provide the base64 encoded value that represents the username and password for basic auth.
  • npm config set _authToken : Provide the access token generated by the registry.

Private registry overriding arguments:

  • registry.url: The URL of the registry where the private template is located. Defaults to registry.npmjs.org.
  • registry.auth: An optional parameter to pass the npm registry username and password encoded with base64, formatted as username:password. For example, if the username and password are admin and nimda, you need to encode them with the base64 value like admin:nimda which results in YWRtaW46bmltZGE=.
  • registry.token: An optional parameter to pass to the npm registry authentication token. To get the token, you can first authenticate with the registry using npm login and then grab the generated token from the .npmrc file.

Pulling private template using library:

1const generator = new Generator('@asyncapi/html-template', 'output',
2      { 
3        debug: true,
4        registry: {
5          url: 'http://verdaccio:4873',  
6          auth: 'YWRtaW46bmltZGE=' 
7            // base64 encoded username and password 
8            // represented as admin:nimda
9          
10        }
11      });

Assuming you host @asyncapi/html-template in a private package registry like Verdaccio. To pull this template, you need to provide registry.url option that points to the registry URL and registry.auth as a base64 encoded value that represents the username and password. Instead of username and password, you can also pass registry.token.

Using templates from private Git repositories

Generator can also use templates hosted in Git repositories, including private repositories on providers such as GitHub and GitLab.
In this case the template is referenced using a git-compatible specifier, and authentication is handled by your existing Git configuration (SSH keys, HTTPS with personal access tokens, etc.).

CLI example

1asyncapi generate fromTemplate asyncapi.yaml \
2  git+ssh://git@github.com/your-org/your-private-template.git \
3  -o output

You can use any git specifier supported by npm, for example:

  • git+https://github.com/your-org/your-private-template.git#v1.0.0
  • git+ssh://git@github.com/your-org/your-private-template.git#main
  • git://github.com/your-org/your-private-template.git
  • git@gitlab.com:your-org/your-private-template.git
  • github:your-org/your-private-template
  • gitlab:your-org/your-private-template
  • bitbucket:your-org/your-private-template

Make sure your Git credentials are configured so the underlying git client can access the repository. For example:

  • Configure SSH keys that have access to the private repository.
  • Use HTTPS URLs with a personal access token (PAT), following your Git provider’s documentation.

Library example

1const generator = new Generator(
2  'git+https://github.com/your-org/your-private-template.git#v1.0.0',
3  'output',
4  {
5    debug: true
6  }
7);

In both CLI and library usage, AsyncAPI Generator delegates cloning and authentication to npm and git; no additional generator-specific configuration is required beyond providing a valid git specifier and having your Git credentials set up correctly.

Was this helpful?
Help us improve the docs by adding your contribution.
OR
Github:AsyncAPICreate Issue on GitHub