micro-module/postman-generator

Generate Postman collections from OpenAPI specifications

Maintainers

Package info

github.com/temafey/micro_modules_postman_generator

pkg:composer/micro-module/postman-generator

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-03-28 09:25 UTC

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.0
  • symfony/http-kernel ^7.0 or ^8.0
  • symfony/http-foundation ^7.0 or ^8.0

License

MIT