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:
- Save huge amounts of development time
- Dramatically reduce “time to first API call”
- Embed optimization & best practices into API usage
# Generate Node SDK with OpenAPI and Publish to GitLab Registry
This documentation was developed using this GitLab
documentation
- Create a Temporary Project Access Token with full permissions for testing the SDK upload to Gitlab Registry locally
- 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 .
|
- Install packages and build
- Ensure secure communication for private registries
1
| npm config set always-auth true
|
- Deploying to GitLab Registry
- 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
|
- Publish to GitLab Registry
# Publishing an npm package to Gitlab locally
- 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/"
}
|
- 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/
|