Generate API documentation from a Postman collection
Preconditions (2)
✅ Expected Result: A public documentation page is created and accessible via the copied URL, showing all requests and details from the selected collection
import newman from 'newman'; // Run the collection and generate documentation newman.run({ collection: './MyCollection.json', reporters: ['cli', 'html'], reporter: { html: { export: './docs/collection-documentation.html' } } }, function (err, summary) { if (err) { console.error('Collection run failed:', err); process.exit(1); } // Check if run was successful const runStats = summary.run.stats; if (runStats.failed > 0) { console.error(`Test failures: ${runStats.failed}`); process.exit(1); } console.log('Collection run completed successfully. Documentation generated at ./docs/collection-documentation.html'); });
This script uses Newman, the command-line runner for Postman collections, to run the collection and generate an HTML report which serves as documentation.
The collection option points to the local Postman collection file.
The reporters option includes html to generate a documentation page.
The reporter.html.export option specifies the output file path for the documentation.
After running, the script checks for errors and test failures, logging appropriate messages.
This approach automates documentation generation and verifies the collection runs without errors.
Now add data-driven testing by running the collection with 3 different environment files
Pass the test and this pattern moves unknown