0
0
Postmantesting~8 mins

Generating documentation from collections in Postman - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Generating documentation from collections
Folder Structure of a Postman Test Project
postman-project/
├── collections/
│   └── api-collection.json       (Postman collection file with requests and tests)
├── environments/
│   ├── dev.postman_environment.json
│   └── prod.postman_environment.json
├── documentation/
│   └── generated-docs.md         (Exported or generated documentation files)
├── scripts/
│   ├── pre-request-scripts.js   (Reusable scripts for requests)
│   └── test-scripts.js           (Reusable test scripts)
├── reports/
│   └── test-report.html          (Test run reports)
└── postman.config.json           (Optional config for Newman or CI integration)
  
Test Framework Layers in Postman Collections
  • Collections Layer: Contains API requests grouped logically with tests and pre-request scripts.
  • Environment Layer: Holds environment variables for different setups (dev, staging, prod).
  • Scripts Layer: Reusable JavaScript code for pre-request and test scripts to keep collections clean.
  • Documentation Layer: Generated API documentation from collections, often exported as Markdown or HTML.
  • Reports Layer: Test run reports generated by Newman or Postman CLI for CI/CD visibility.
Configuration Patterns for Documentation Generation
  • Environment Variables: Use environment files to switch base URLs, tokens, and other settings without changing collections.
  • Collection Metadata: Add descriptive info in collection settings (name, description, version) to enrich generated docs.
  • Documentation Settings: Use Postman's built-in documentation feature or Newman reporters configured in postman.config.json or CLI flags.
  • Automation: Integrate Newman CLI commands in CI pipelines to generate and publish documentation automatically after test runs.
Test Reporting and CI/CD Integration
  • Newman CLI: Run collections and generate HTML or JSON reports with newman run collection.json -r html,json.
  • Documentation Export: Use Postman's "Publish Docs" feature or export collection docs as Markdown/HTML for sharing.
  • CI/CD Pipelines: Automate collection runs and documentation generation in Jenkins, GitHub Actions, GitLab CI, etc.
  • Version Control: Store collections, environments, and generated docs in Git for traceability and collaboration.
Best Practices for Generating Documentation from Collections
  1. Keep Collections Clean: Use folders and descriptive names to organize requests clearly for better docs.
  2. Write Clear Descriptions: Add meaningful descriptions to requests, parameters, and responses to improve documentation quality.
  3. Use Environment Variables: Avoid hardcoding URLs or tokens to keep docs adaptable across environments.
  4. Automate Documentation: Integrate documentation generation in CI/CD to keep docs up-to-date with API changes.
  5. Review Generated Docs: Always check exported docs for clarity and completeness before publishing.
Self-Check Question

Where in this folder structure would you add a new Postman collection for a User Authentication API to ensure it is included in the generated documentation?

Key Result
Organize Postman collections, environments, scripts, and documentation exports clearly to automate and maintain up-to-date API docs.