micro-module / postman-generator
Generate Postman collections from OpenAPI specifications
Package info
github.com/temafey/micro_modules_postman_generator
pkg:composer/micro-module/postman-generator
v0.1.0
2026-03-28 09:25 UTC
Requires
- php: ^8.4
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0 || ^12.0
- symfony/console: ^7.0 || ^8.0
- symfony/dependency-injection: ^7.0 || ^8.0
- symfony/http-foundation: ^7.0 || ^8.0
- symfony/http-kernel: ^7.0 || ^8.0
Suggests
- symfony/console: Required for CLI command (^7.0 || ^8.0)
- symfony/dependency-injection: Required for #[Lazy] attribute support (^7.0 || ^8.0)
- symfony/http-foundation: Required for OpenApiParser (^7.0 || ^8.0)
- symfony/http-kernel: Required for OpenApiParser (^7.0 || ^8.0)
This package is auto-updated.
Last update: 2026-03-29 20:37:01 UTC
README
Generate Postman collections and environments from OpenAPI (Swagger) specifications.
Features
- OpenAPI Parsing: Extract endpoints, schemas, and parameters from OpenAPI 3.0 specs
- Collection Generation: Build Postman v2.1 collections with folders, requests, and examples
- Environment Generation: Create Postman environments with base URLs and auth variables
- Request Building: Construct request bodies, headers, and query params from OpenAPI schemas
- File Export: Write collections and environments to JSON files
- CLI Command: Symfony console command for automated generation
Installation
composer require --dev micro-module/postman-generator
Usage
CLI Command
bin/console postman:generate \
--openapi-url=http://localhost/api/v1/docs.json \
--output-dir=tests/postman \
--collection-name="My API" \
--base-url="{{base_url}}"
Programmatic Usage
use MicroModule\PostmanGenerator\PostmanGeneratorService; use MicroModule\PostmanGenerator\OpenApi\OpenApiParser; use MicroModule\PostmanGenerator\PostmanCollectionFactory; use MicroModule\PostmanGenerator\PostmanEnvironmentGenerator; use MicroModule\PostmanGenerator\PostmanRequestBuilder; use MicroModule\PostmanGenerator\CollectionFileWriter; $generator = new PostmanGeneratorService( new OpenApiParser(), new PostmanCollectionFactory(new PostmanRequestBuilder()), new PostmanEnvironmentGenerator(), new CollectionFileWriter() ); $generator->generate( openApiUrl: 'http://localhost/api/v1/docs.json', outputDir: 'tests/postman', collectionName: 'My API', baseUrl: '{{base_url}}' );
Architecture
OpenAPI Spec (JSON)
└── OpenApiParser
└── Parsed endpoints, schemas, parameters
├── PostmanCollectionFactory
│ └── PostmanRequestBuilder (per endpoint)
│ └── Postman Collection JSON
└── PostmanEnvironmentGenerator
└── Postman Environment JSON
CollectionFileWriter → writes both to disk
PostmanGeneratorService → orchestrates the full pipeline
Key Classes
| Class | Purpose |
|---|---|
PostmanGeneratorService |
Main orchestrator for the generation pipeline |
OpenApiParser |
Parses OpenAPI 3.0 JSON specs into structured data |
PostmanCollectionFactory |
Builds Postman v2.1 collection structure |
PostmanRequestBuilder |
Constructs individual request items from endpoints |
PostmanEnvironmentGenerator |
Creates Postman environment with variables |
CollectionFileWriter |
Writes collection/environment JSON to files |
GeneratePostmanCollectionCommand |
Symfony console command |
Output Format
Collection (Postman v2.1)
{
"info": {
"name": "My API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "News",
"item": [
{
"name": "Create News",
"request": {
"method": "POST",
"url": "{{base_url}}/api/v1/news",
"header": [...],
"body": { "mode": "raw", "raw": "..." }
}
}
]
}
]
}
Environment
{
"name": "My API - Local",
"values": [
{ "key": "base_url", "value": "http://localhost:8088", "enabled": true },
{ "key": "bearer_token", "value": "", "enabled": true }
]
}
Requirements
- PHP 8.4+
Optional (for CLI command)
symfony/console^7.0 or ^8.0symfony/http-kernel^7.0 or ^8.0symfony/http-foundation^7.0 or ^8.0
License
MIT