Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-264634: Add links to the docs page for each endpoint in the Postman Collection #132

Merged
merged 11 commits into from
Aug 2, 2024
4 changes: 1 addition & 3 deletions tools/postman/scripts/compare-forks.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
set -euo pipefail

#########################################################
# Compare number of forks for each collection to the previous week
Expand Down
4 changes: 1 addition & 3 deletions tools/postman/scripts/convert-to-collection.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
set -euo pipefail

#########################################################
# Convert from OpenAPI to PostmanV2 Collection
Expand Down
4 changes: 1 addition & 3 deletions tools/postman/scripts/fetch-forks.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
set -euo pipefail

#########################################################
# Fetch number of forks of each collection
Expand Down
3 changes: 1 addition & 2 deletions tools/postman/scripts/fetch-openapi.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -euo pipefail

#########################################################
# Fetch openapi from remote file
Expand Down
4 changes: 1 addition & 3 deletions tools/postman/scripts/send-fork-data.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
set -euo pipefail

#########################################################
# Send the Fork metrics message to Slack
Expand Down
42 changes: 35 additions & 7 deletions tools/postman/scripts/transform-for-api.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
set -euo pipefail

#########################################################
# Prepare collection for Postman API
# Environment variables:
# COLLECTION_FILE_NAME - name of the postman collection file
# COLLECTION_TRANSFORMED_FILE_NAME - name of the transformed collection file
# OPENAPI_FILE_NAME - name of the openapi specification file
# OPENAPI_FOLDER - folder where openapi file is saved
# TMP_FOLDER - folder for temporary files during transformations
# TOGGLE_USE_ENVIRONMENT_AUTH - bool for if auth variables are stored at the environment or collection level
Expand All @@ -18,6 +17,7 @@ set -o pipefail

COLLECTION_FILE_NAME=${COLLECTION_FILE_NAME:-"collection.json"}
COLLECTION_TRANSFORMED_FILE_NAME=${COLLECTION_TRANSFORMED_FILE_NAME:-"collection-transformed.json"}
OPENAPI_FILE_NAME=${OPENAPI_FILE_NAME:-"atlas-api.json"}
OPENAPI_FOLDER=${OPENAPI_FOLDER:-"../openapi"}
TMP_FOLDER=${TMP_FOLDER:-"../tmp"}
VERSIONS_FILE=${VERSIONS_FILE:-"versions.json"}
Expand Down Expand Up @@ -51,11 +51,38 @@ jq --arg base_url "$BASE_URL" \
'.collection.variable[0].value = $base_url' \
intermediateCollectionWithName.json > intermediateCollectionWithBaseURL.json

echo "Adding links to docs"
cp intermediateCollectionWithBaseURL.json intermediateCollectionWithLinks.json

# Store all paths to requests. The summary field is the same as the title in the collection
paths=$(jq 'path(.. | objects | select(has("summary"))) | @sh' "$OLDPWD"/"$OPENAPI_FOLDER"/"$OPENAPI_FILE_NAME")
declare -a paths_array="($paths)"

for path in "${paths_array[@]}"; do
declare -a single_path_array="($path)"
path_json=$(jq -n '$ARGS.positional' --args "${single_path_array[@]}")

# Use the path to get all the information about this request without searching
requestInfo=$(jq --argjson path "$path_json" 'getpath($path)' "$OLDPWD"/"$OPENAPI_FOLDER"/"$OPENAPI_FILE_NAME")

title=$(echo "$requestInfo" | jq -r '.summary')
operationId=$(echo "$requestInfo" | jq -r '.operationId')
tag=$(echo "$requestInfo" | jq -r '.tags.[0]' | tr " " "-")

url="https://mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/${tag}/operation/$operationId"

# Search the collection for the request with the matching name. Add the link to its description
jq --arg title "$title" --arg url "$url" \
'first(.collection.item.[].item.[].request | select(.name == $title).description.content) += "\n\nFind out more at " + $url' \
intermediateCollectionWithLinks.json > tmp.json && cp tmp.json intermediateCollectionWithLinks.json

done

# Togglable features
if [ "$TOGGLE_INCLUDE_BODY" = "false" ]; then
echo "Removing generated bodies"
jq '.collection.item.[].item.[].response.[].body |= ""' \
intermediateCollectionWithBaseURL.json > intermediateCollectionRemovedResponseBody.json
intermediateCollectionWithLinks.json > intermediateCollectionRemovedResponseBody.json

jq '.collection.item.[].item.[].request.body |= {}' \
intermediateCollectionRemovedResponseBody.json > intermediateCollectionRemovedRequestBody.json
Expand All @@ -65,7 +92,7 @@ if [ "$TOGGLE_INCLUDE_BODY" = "false" ]; then

rm intermediateCollectionRemovedResponseBody.json intermediateCollectionRemovedRequestBody.json
else
cp intermediateCollectionWithBaseURL.json intermediateCollectionPostBody.json
cp intermediateCollectionWithLinks.json intermediateCollectionPostBody.json
fi

if [ "$TOGGLE_USE_ENVIRONMENT_AUTH" = "false" ]; then
Expand All @@ -83,7 +110,8 @@ rm intermediateCollectionWrapped.json \
intermediateCollectionDisableQueryParam.json \
intermediateCollectionNoPostmanID.json \
intermediateCollectionWithName.json \
intermediateCollectionPostBody.json \
intermediateCollectionWithBaseURL.json
intermediateCollectionWithBaseURL.json \
intermediateCollectionWithLinks.json \
intermediateCollectionPostBody.json

popd -0
4 changes: 1 addition & 3 deletions tools/postman/scripts/upload-collection.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
set -euo pipefail

#########################################################
# Upload collection to Postman
Expand Down
Loading