cvwiki

OpenAPI

May 4, 2022

# Why use OpenAPI?

As a tool, OpenAPI allows you to generate client SDKs for your API across dozens of supported languages. Building SDKs are an integral part of the developer experience because they:

# Generate Node SDK with OpenAPI and Publish to GitLab Registry

This documentation was developed using this GitLab documentation

  1. Create a Temporary Project Access Token with full permissions for testing the SDK upload to Gitlab Registry locally
  2. Generate the SDK
1
2
3
4
mkdir javascript-sdk
cd javascript-sdk
export JS_POST_PROCESS_FILE="/usr/local/bin/js-beautify -r -f"
openapi-generator generate -i $SWAGGER_URL -g javascript -o .
  1. Install packages and build
1
npm install
  1. Ensure secure communication for private registries
1
npm config set always-auth true
  1. Deploying to GitLab Registry
    1. For local GitLab Registry uploads, we need a personal access token, with full registry write permissions.
1
npm config set @your_scope/npm_package_name:registry https://gitlab.com/api/v4/projects/$PROJECT_ID/packages/npm/
1
npm config set -- '//gitlab.com/api/v4/projects/$PROJECT_ID/packages/npm/:_authToken' $AUTH_TOKEN
  1. Publish to GitLab Registry
1
npm publish

# Publishing an npm package to Gitlab locally

  1. Add the following to your generated SDK’s package.json file
1
2
3
{  
  "name": "@scope/package-name"
}	
1
2
3
 "publishConfig": {  
    "@scope:registry": "$GITLAB_API_V4/projects/$PROJECT_ID/packages/npm/"
 } 
  1. Add the following to your .npmrc file
1
2
3
//gitlab.com/api/v4/projects/$PROJECT_ID/packages/npm/:_authToken=$PERSONAL_ACCESS_TOKEN
//gitlab.com/api/v4/packages/npm/:_authToken=$PERSONAL_ACCESS_TOKEN
@scope:registry=https://gitlab.com/api/v4/packages/npm/