Skip to content

Commit 39f38e2

Browse files
CLOUDP-261458: Fetch the latest version of OpenAPI Spec (#77)
1 parent 4132f4d commit 39f38e2

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.so
66
*.dylib
77
/tools/*/bin/*
8+
/tools/*/tmp/*
89
/tools/cli/test/e2e/cli/output/**
910
!/tools/cli/test/e2e/cli/output/.gitkeep
1011
/tools/*/dist/*
@@ -16,4 +17,3 @@
1617
*.vscode
1718

1819
*.out
19-
*.keep

tools/postman/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export OPENAPI_FOLDER=./openapi
2+
3+
.PHONY: fetch_openapi
4+
fetch_openapi:
5+
./scripts/fetch.sh

tools/postman/openapi/.keep

Whitespace-only changes.

tools/postman/scripts/fetch.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
#########################################################
7+
# Fetch openapi from remote file
8+
# Environment variables:
9+
# OPENAPI_FILE_NAME - openapi file name to use
10+
# OPENAPI_FOLDER - folder for saving openapi file
11+
# API_BASE_URL - base URL where the spec is hosted
12+
# S3_BUCKET - S3 bucket where the spec is hosted
13+
# VERSIONS_FILE - openapi versions file name to use
14+
#########################################################
15+
16+
OPENAPI_FILE_NAME=${OPENAPI_FILE_NAME:-"atlas-api.json"}
17+
OPENAPI_FOLDER=${OPENAPI_FOLDER:-"../openapi"}
18+
API_BASE_URL=${API_BASE_URL:-"https://cloud.mongodb.com"}
19+
S3_BUCKET=${S3_BUCKET:-"mongodb-mms-prod-build-server"}
20+
VERSIONS_FILE=${VERSIONS_FILE:-"versions.json"}
21+
22+
versions_url="${API_BASE_URL}/api/openapi/versions"
23+
24+
pushd "${OPENAPI_FOLDER}"
25+
26+
echo "Fetching versions from $versions_url"
27+
curl --show-error --fail --silent -o "${VERSIONS_FILE}" \
28+
-H "Accept: application/json" "${versions_url}"
29+
30+
## Dynamic Versioned API Version
31+
CURRENT_API_REVISION=$(jq -r '.versions."2.0" | .[-1]' < "./${VERSIONS_FILE}")
32+
33+
echo "Fetching OpenAPI release sha"
34+
sha=$(curl --show-error --fail --silent -H "Accept: text/plain" "${API_BASE_URL}/api/private/unauth/version")
35+
36+
echo "Fetching OAS file for ${sha}"
37+
openapi_url="https://${S3_BUCKET}.s3.amazonaws.com/openapi/${sha}-v2-${CURRENT_API_REVISION}.json"
38+
39+
echo "Fetching api from $openapi_url to $OPENAPI_FILE_NAME"
40+
curl --show-error --fail --silent -o "$OPENAPI_FILE_NAME" "$openapi_url"
41+
42+
popd -0

tools/postman/tmp/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)