$npx -y skills add girijashankarj/cursor-handbook --skill postman-collection-generatorGenerate Postman or Insomnia collections from OpenAPI specs, code, or endpoint descriptions. Use when the user asks to create an API collection, export endpoints for testing, or set up Postman/Insomnia.
| 1 | # Skill: Postman Collection Generator |
| 2 | |
| 3 | Generate importable API client collections (Postman v2.1 or Insomnia) for manual testing and team sharing. |
| 4 | |
| 5 | ## Trigger |
| 6 | When the user asks to create a Postman collection, Insomnia workspace, or export API endpoints for manual testing. |
| 7 | |
| 8 | ## Prerequisites |
| 9 | - [ ] API endpoints identified (from code, OpenAPI spec, or descriptions) |
| 10 | - [ ] Authentication method known |
| 11 | - [ ] Base URL and environments identified |
| 12 | |
| 13 | ## Steps |
| 14 | |
| 15 | ### Step 1: Gather Endpoints |
| 16 | - [ ] Scan route files or OpenAPI spec for all endpoints |
| 17 | - [ ] For each endpoint: method, path, parameters, request body, response shape |
| 18 | - [ ] Group endpoints by resource or feature |
| 19 | |
| 20 | ### Step 2: Define Environment Variables |
| 21 | |
| 22 | ```json |
| 23 | { |
| 24 | "id": "env-dev", |
| 25 | "name": "Development", |
| 26 | "values": [ |
| 27 | { "key": "baseUrl", "value": "http://localhost:3000/api/v1", "enabled": true }, |
| 28 | { "key": "authToken", "value": "", "enabled": true }, |
| 29 | { "key": "correlationId", "value": "{{$guid}}", "enabled": true } |
| 30 | ] |
| 31 | } |
| 32 | ``` |
| 33 | |
| 34 | Environments to create: |
| 35 | - **Development** — `localhost:3000` |
| 36 | - **Staging** — `[STAGING_URL]` |
| 37 | - **Production** — `[PROD_URL]` (read-only requests only) |
| 38 | |
| 39 | ### Step 3: Generate Collection Structure |
| 40 | |
| 41 | ```json |
| 42 | { |
| 43 | "info": { |
| 44 | "name": "{{CONFIG.project.name}} API", |
| 45 | "_postman_id": "{{$guid}}", |
| 46 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" |
| 47 | }, |
| 48 | "auth": { |
| 49 | "type": "bearer", |
| 50 | "bearer": [{ "key": "token", "value": "{{authToken}}", "type": "string" }] |
| 51 | }, |
| 52 | "variable": [ |
| 53 | { "key": "baseUrl", "value": "http://localhost:3000/api/v1" } |
| 54 | ], |
| 55 | "item": [] |
| 56 | } |
| 57 | ``` |
| 58 | |
| 59 | ### Step 4: Generate Request Items |
| 60 | |
| 61 | For each endpoint: |
| 62 | |
| 63 | ```json |
| 64 | { |
| 65 | "name": "List Orders", |
| 66 | "request": { |
| 67 | "method": "GET", |
| 68 | "header": [ |
| 69 | { "key": "X-Correlation-Id", "value": "{{correlationId}}" }, |
| 70 | { "key": "Content-Type", "value": "application/json" } |
| 71 | ], |
| 72 | "url": { |
| 73 | "raw": "{{baseUrl}}/orders?cursor=&pageSize=20", |
| 74 | "host": ["{{baseUrl}}"], |
| 75 | "path": ["orders"], |
| 76 | "query": [ |
| 77 | { "key": "cursor", "value": "", "description": "Pagination cursor" }, |
| 78 | { "key": "pageSize", "value": "20", "description": "Items per page (1-100)" } |
| 79 | ] |
| 80 | } |
| 81 | }, |
| 82 | "response": [ |
| 83 | { |
| 84 | "name": "Success (200)", |
| 85 | "status": "OK", |
| 86 | "code": 200, |
| 87 | "body": "{\"data\": [{\"id\": \"ord_001\", \"status\": \"PENDING\"}], \"meta\": {\"cursor\": \"abc\", \"hasMore\": true}}" |
| 88 | } |
| 89 | ] |
| 90 | } |
| 91 | ``` |
| 92 | |
| 93 | For POST/PUT endpoints: |
| 94 | ```json |
| 95 | { |
| 96 | "name": "Create Order", |
| 97 | "request": { |
| 98 | "method": "POST", |
| 99 | "header": [ |
| 100 | { "key": "X-Correlation-Id", "value": "{{correlationId}}" }, |
| 101 | { "key": "Content-Type", "value": "application/json" } |
| 102 | ], |
| 103 | "body": { |
| 104 | "mode": "raw", |
| 105 | "raw": "{\n \"customerId\": \"cust_001\",\n \"items\": [\n { \"productId\": \"prod_001\", \"quantity\": 2 }\n ]\n}", |
| 106 | "options": { "raw": { "language": "json" } } |
| 107 | }, |
| 108 | "url": { |
| 109 | "raw": "{{baseUrl}}/orders", |
| 110 | "host": ["{{baseUrl}}"], |
| 111 | "path": ["orders"] |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | ``` |
| 116 | |
| 117 | ### Step 5: Add Pre-Request Scripts (Optional) |
| 118 | |
| 119 | ```javascript |
| 120 | // Auto-generate correlation ID |
| 121 | pm.variables.set("correlationId", pm.variables.replaceIn("{{$guid}}")); |
| 122 | |
| 123 | // Auth token from login response |
| 124 | const authResponse = pm.environment.get("authResponse"); |
| 125 | if (authResponse) { |
| 126 | const token = JSON.parse(authResponse).data.token; |
| 127 | pm.environment.set("authToken", token); |
| 128 | } |
| 129 | ``` |
| 130 | |
| 131 | ### Step 6: Add Test Scripts (Optional) |
| 132 | |
| 133 | ```javascript |
| 134 | // Common assertions for all requests |
| 135 | pm.test("Status code is successful", () => { |
| 136 | pm.expect(pm.response.code).to.be.oneOf([200, 201, 204]); |
| 137 | }); |
| 138 | |
| 139 | pm.test("Response has correct envelope", () => { |
| 140 | const json = pm.response.json(); |
| 141 | pm.expect(json).to.have.property("data"); |
| 142 | pm.expect(json).to.have.property("meta"); |
| 143 | pm.expect(json.meta).to.have.property("correlationId"); |
| 144 | }); |
| 145 | |
| 146 | pm.test("Response time < 500ms", () => { |
| 147 | pm.expect(pm.response.responseTime).to.be.below(500); |
| 148 | }); |
| 149 | ``` |
| 150 | |
| 151 | ### Step 7: Organize Folders |
| 152 | - [ ] Group by resource: Users, Orders, Products, etc. |
| 153 | - [ ] Add an "Auth" folder with login/register/refresh endpoints |
| 154 | - [ ] Add a "Health" folder with health check endpoints |
| 155 | - [ ] Add an "Admin" folder for administrative endpoints |
| 156 | |
| 157 | ### Step 8: Export and Document |
| 158 | - [ ] Export as Postman Collection v2.1 JSON |
| 159 | - [ ] Export environment files separately |
| 160 | - [ ] Save to `docs/api/postman/` or project-standard location |
| 161 | - [ ] Add import instructions to README |
| 162 | |
| 163 | ## Rules |
| 164 | - **NEVER** include real credentials or tokens in the collection |
| 165 | - **NEVER** include PII in example request/response bodies |
| 166 | - **ALWAYS** use environment variables for base URLs and tokens |
| 167 | - **ALWAYS** include example responses for each endpoint |
| 168 | - Use `{{$guid}}` for dynamic IDs, `{ |