From 67b68ee12e6af49a8772d2f96db31d5e965123dd Mon Sep 17 00:00:00 2001 From: wtrocki Date: Tue, 25 Mar 2025 12:37:59 +0100 Subject: [PATCH 1/3] CLOUDP-308303: size of postman file --- .github/workflows/release-postman.yml | 3 +-- tools/postman/scripts/transform-postman.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-postman.yml b/.github/workflows/release-postman.yml index 95f6bab5bc..37da75d0b8 100644 --- a/.github/workflows/release-postman.yml +++ b/.github/workflows/release-postman.yml @@ -48,8 +48,7 @@ jobs: BASE_URL: ${{ inputs.atlas_prod_base_url }} working-directory: ./tools/postman run: | - make transform_collection - make transform_collection_test + make transform_collection_js - name: Upload Collection to Postman env: diff --git a/tools/postman/scripts/transform-postman.js b/tools/postman/scripts/transform-postman.js index 453cbbeb0a..87dec1ce36 100644 --- a/tools/postman/scripts/transform-postman.js +++ b/tools/postman/scripts/transform-postman.js @@ -24,8 +24,8 @@ const OPENAPI_FOLDER = process.env.OPENAPI_FOLDER || './openapi'; const TMP_FOLDER = process.env.TMP_FOLDER || './tmp'; const VERSION_FILE_NAME = process.env.VERSION_FILE_NAME || 'version.txt'; const DESCRIPTION_FILE = process.env.DESCRIPTION_FILE || './collection-description.md'; -const TOGGLE_INCLUDE_BODY = process.env.TOGGLE_INCLUDE_BODY !== 'false'; -const TOGGLE_ADD_DOCS_LINKS = process.env.TOGGLE_ADD_DOCS_LINKS === 'true'; +const TOGGLE_INCLUDE_BODY = false; +const TOGGLE_ADD_DOCS_LINKS = false; const TOKEN_URL_ENV = process.env.TOKEN_URL_ENV || ''; const BASE_URL = process.env.BASE_URL || ''; From 1ce77d44824b9a6fe640ca6a62b3107578e78e15 Mon Sep 17 00:00:00 2001 From: wtrocki Date: Tue, 25 Mar 2025 13:18:49 +0100 Subject: [PATCH 2/3] fix: reduce size to 4mb --- tools/postman/scripts/transform-postman.js | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/postman/scripts/transform-postman.js b/tools/postman/scripts/transform-postman.js index 87dec1ce36..1fa0da0ae5 100644 --- a/tools/postman/scripts/transform-postman.js +++ b/tools/postman/scripts/transform-postman.js @@ -67,6 +67,35 @@ const transform = () => { console.log(`Adding baseUrl property ${BASE_URL}`); collection.collection.variable.push({ key: 'baseUrl', value: BASE_URL }); + console.log('Removing redundant fields to reduce size'); + _.forEach(collection.collection.item, (item) => { + if (item.request) { + delete item.request.description; // Remove request descriptions + delete item.request.auth; // Remove unused auth fields + + if (item.request.body && item.request.body.mode === 'raw') { + delete item.request.body.raw; // Remove raw fields from body + } + } + if (item.response) { + item.response.forEach((response) => { + delete response.originalRequest; // Remove original request from responses + delete response._postman_previewlanguage; // Remove preview language metadata + delete response.header; // Remove headers from responses + response.body = ''; // Clear response body + }); + } + }); + + console.log('Removing empty arrays and objects'); + collection = JSON.parse( + JSON.stringify(collection, (key, value) => { + if (Array.isArray(value) && value.length === 0) return undefined; + if (value && typeof value === 'object' && Object.keys(value).length === 0) return undefined; + return value; + }) + ); + if (TOGGLE_ADD_DOCS_LINKS) { console.log('Adding links to docs for each request'); @@ -119,7 +148,7 @@ function loadJsonFile(filePath) { } function saveJsonFile(filePath, json) { - fs.writeFileSync(filePath, JSON.stringify(json, null, 2), 'utf8'); + fs.writeFileSync(filePath, JSON.stringify(json, null, 0), 'utf8'); } // hack From 97e38871cecd0df6a041a14f32b70939cdadc8bf Mon Sep 17 00:00:00 2001 From: wtrocki Date: Tue, 25 Mar 2025 13:55:44 +0100 Subject: [PATCH 3/3] fix: remove whitespaces from the collection --- tools/postman/scripts/transform-for-api.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/postman/scripts/transform-for-api.sh b/tools/postman/scripts/transform-for-api.sh index 7e08a60f7b..5b208af4c1 100755 --- a/tools/postman/scripts/transform-for-api.sh +++ b/tools/postman/scripts/transform-for-api.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash set -euo pipefail +## NOTE: Use JS script instead. +## Script is kept only for backwards compatibilty + ######################################################### # Prepare collection for Postman API # Environment variables: @@ -27,7 +30,6 @@ DESCRIPTION_FILE=${DESCRIPTION_FILE:-"../collection-description.md"} TOGGLE_INCLUDE_BODY=${TOGGLE_INCLUDE_BODY:-true} TOGGLE_ADD_DOCS_LINKS=${TOGGLE_ADD_DOCS_LINKS:-true} -TOKEN_URL_ENV=${TOKEN_URL_ENV:-""} current_api_revision=$(<"$OPENAPI_FOLDER/$VERSION_FILE_NAME") @@ -117,13 +119,10 @@ else cp intermediateCollectionWithLinks.json intermediateCollectionPostBody.json fi -if [ "$TOKEN_URL_ENV" != "" ]; then - echo "Adding client credentials auth url variable $TOKEN_URL_ENV" - jq --arg token_url "$TOKEN_URL_ENV" '.collection.variable += [{"key": "clientCredentialsTokenUrl", "value": $token_url}]' \ - intermediateCollectionPostBody.json > "$COLLECTION_TRANSFORMED_FILE_NAME" -else - cp intermediateCollectionPostBody.json "$COLLECTION_TRANSFORMED_FILE_NAME" -fi +# Remove trailing whitespaces by reformatting the JSON +echo "Removing trailing whitespaces from the final JSON file" +jq '.' "$COLLECTION_TRANSFORMED_FILE_NAME" > tmp.json && mv tmp.json "$COLLECTION_TRANSFORMED_FILE_NAME" + # Clean up temporary files echo "Removing temporary files"