feat: Update OpenAPI file replicated from CMS4 #288
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Postman collection | |
| on: | |
| push: | |
| branches: [master] | |
| paths: | |
| - openapi/openapi.yaml | |
| workflow_dispatch: | |
| inputs: | |
| postman_api_key: | |
| description: Postman API key - For debugging purposes | |
| default: '' | |
| postman_workspace_name: | |
| description: Postman Workspace name - For debugging purposes | |
| default: 'Shoptet public API Workspace' | |
| postman_collection_name: | |
| description: Postman Collection name - For debugging purposes | |
| default: 'Shoptet API' | |
| env: | |
| POSTMAN_API_KEY: ${{ github.event.inputs.postman_api_key || secrets.POSTMAN_API_KEY }} | |
| POSTMAN_WORKSPACE_NAME: ${{ github.event.inputs.postman_workspace_name || 'Shoptet public API Workspace' }} | |
| POSTMAN_COLLECTION_NAME: ${{ github.event.inputs.postman_collection_name || 'Shoptet API' }} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install openapi-to-postmanv2 | |
| run: npm install -g openapi-to-postmanv2 | |
| - name: Generate Postman collection from OpenAPI | |
| run: | | |
| openapi2postmanv2 -s ./openapi/openapi.yaml -o postman_collection.json -p -O folderStrategy=Tags | |
| - name: Cleanup empty Postman collection items | |
| run: | | |
| cp postman_collection.json postman_collection.json.tmp && | |
| jq 'del(.item[] | select(.name == "Batch" or .name == "Snapshot"))' < postman_collection.json.tmp > postman_collection.json && | |
| rm postman_collection.json.tmp | |
| - name: Prepare Postman collection request body | |
| run: | | |
| jq '{ collection: . }' <postman_collection.json | jq --arg POSTMAN_COLLECTION_NAME "$POSTMAN_COLLECTION_NAME" '.collection.info.name |= $POSTMAN_COLLECTION_NAME' >postman_collection_request_body.json | |
| - name: Postman API - Get Workspace ID | |
| id: get_postman_workspace_id | |
| run: | | |
| RESPONSE_BODY=$(curl --fail --silent --show-error --location --request GET \ | |
| "https://api.getpostman.com/workspaces" \ | |
| --header "X-Api-Key: $POSTMAN_API_KEY" \ | |
| --header "Content-Type: application/json") | |
| echo "::debug::$RESPONSE_BODY" | |
| WORKSPACE_ID=$(echo $RESPONSE_BODY | jq -r --arg POSTMAN_WORKSPACE_NAME "$POSTMAN_WORKSPACE_NAME" '.workspaces[] | select(.name == $POSTMAN_WORKSPACE_NAME)'.id) | |
| echo "::debug::$WORKSPACE_ID" | |
| echo "workspace_id=$WORKSPACE_ID" >> $GITHUB_OUTPUT | |
| if [[ $WORKSPACE_ID = '' ]]; then | |
| echo "::error::No Workspace found. Please create a workspace with name $POSTMAN_WORKSPACE_NAME" | |
| exit 1 | |
| fi | |
| - name: Postman API - Get Collection ID | |
| id: get_postman_collection_id | |
| run: | | |
| echo "::debug::${{ steps.get_postman_workspace_id.outputs.workspace_id }}" | |
| RESPONSE_BODY=$(curl --fail --silent --show-error --location --request GET \ | |
| "https://api.getpostman.com/collections?workspace=${{ steps.get_postman_workspace_id.outputs.workspace_id }}" \ | |
| --header "X-Api-Key: $POSTMAN_API_KEY" \ | |
| --header "Content-Type: application/json") | |
| echo "::debug::$RESPONSE_BODY" | |
| COLLECTION_ID=$(echo $RESPONSE_BODY | jq -r --arg POSTMAN_COLLECTION_NAME "$POSTMAN_COLLECTION_NAME" '.collections[] | select(.name == $POSTMAN_COLLECTION_NAME)'.id) | |
| echo "::debug::$COLLECTION_ID" | |
| echo "collection_id=$COLLECTION_ID" >> $GITHUB_OUTPUT | |
| - name: Postman API - Create Collection if not exists | |
| if: steps.get_postman_collection_id.outputs.collection_id == '' | |
| run: | | |
| echo "::debug::${{ steps.get_postman_workspace_id.outputs.workspace_id }}" | |
| RESPONSE_BODY=$(curl --fail --silent --show-error --location --request POST \ | |
| "https://api.getpostman.com/collections?workspace=${{ steps.get_postman_workspace_id.outputs.workspace_id }}" \ | |
| --header "X-Api-Key: $POSTMAN_API_KEY" \ | |
| --header "Content-Type: application/json" \ | |
| --data @postman_collection_request_body.json) | |
| echo "::debug::$RESPONSE_BODY" | |
| - name: Postman API - Update existing Collection | |
| if: steps.get_postman_collection_id.outputs.collection_id != '' | |
| run: | | |
| echo "::debug::${{ steps.get_postman_collection_id.outputs.collection_id }}" | |
| RESPONSE_BODY=$(curl --fail --silent --show-error --location --request PUT \ | |
| "https://api.getpostman.com/collections/${{ steps.get_postman_collection_id.outputs.collection_id }}" \ | |
| --header "X-Api-Key: $POSTMAN_API_KEY" \ | |
| --header "Content-Type: application/json" \ | |
| --data @postman_collection_request_body.json) | |
| echo "::debug::$RESPONSE_BODY" |