OpenAPI to Postman Collection #47
This file contains 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: OpenAPI to Postman Collection | |
on: | |
workflow_dispatch: # Allows manual triggering from GitHub UI | |
schedule: | |
- cron: '0 2 * * 1' # Runs at 02:00 AM every Monday (UTC) | |
push: | |
branches: | |
- main # Set to your default branch | |
paths: | |
- 'yaml/*.yaml' # Assuming all your OpenAPI files are in this directory | |
jobs: | |
convert-and-update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Install Postman Converter | |
run: npm install -g openapi-to-postmanv2 | |
- name: Convert OpenAPI Specs to Postman Collections and Upload | |
env: | |
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} | |
run: | | |
for file in yaml/*.yaml; do | |
collection_name=$(basename "$file" .yaml) # Extracts file name without extension | |
postman_collection="${collection_name}_postman.json" | |
openapi2postmanv2 -s "$file" -o "$postman_collection" --pretty | |
# Ensure you have collection UID for each file | |
collection_uid="21750812-5ba27ed4-8b4a-4db7-a255-46e4749cb477" # Replace or dynamically fetch this | |
curl --location --request PUT "https://api.getpostman.com/collections/$collection_uid" \ | |
--header 'X-Api-Key: $POSTMAN_API_KEY' \ | |
--header 'Content-Type: application/json' \ | |
--data-binary "@$postman_collection" | |
done |