Download the PHP package methorz/openapi-generator without Composer
On this page you can find all versions of the php package methorz/openapi-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package openapi-generator
MethorZ OpenAPI Generator
Automatic OpenAPI 3.0 specification generator from routes and DTOs
Automatically generates OpenAPI specifications by analyzing your application's routes and Data Transfer Objects (DTOs). Perfect for Mezzio, Laminas, and any PSR-15 application.
โจ Features
- ๐ Automatic Generation: Scans routes and DTOs to generate complete OpenAPI specs
- ๐ DTO Analysis: Extracts request/response schemas from PHP DTOs with property promotion
- โ Validation Integration: Reads Symfony Validator attributes for schema constraints
- ๐ฏ Handler Detection: Automatically finds request and response DTOs in handlers
- ๐ฆ Multiple Formats: Generates both YAML and JSON outputs
- ๐ง Zero Configuration: Works out-of-the-box with sensible defaults
- ๐จ Customizable: Configure via application config
- ๐ Nested DTOs: Automatically generates schemas for nested DTO references
- ๐ Collections: Supports typed arrays with
@param array<Type>PHPDoc - ๐ฒ Enums: Full support for backed and unit enums (PHP 8.1+)
- ๐ Union Types: Generates
oneOfschemas for union types (PHP 8.0+) - โก Performance: Schema caching for efficient generation
๐ Requirements
This package requires PHP 8.2+ and uses the following runtime dependencies:
| Package | Purpose | Framework Required? |
|---|---|---|
psr/container |
PSR-11 Container Interface | โ No |
symfony/console |
CLI command handling | โ No (standalone utility) |
symfony/yaml |
YAML file parsing/writing | โ No (standalone utility) |
Note: The Symfony packages used are standalone utility libraries, not framework components. They work independently without the Symfony framework and are used by many non-Symfony projects (Composer, PHPStan, PHPUnit, etc.).
๐ฆ Installation
๐ Quick Start
1. Register the Command
Add to your application's command configuration:
2. Generate Specification
This will create:
public/openapi.yaml- YAML formatpublic/openapi.json- JSON format
๐ Usage
Basic Configuration
Example Handler
The generator automatically analyzes your handlers:
Example Request DTO
Generated Schema:
๐ Supported Validation Attributes
The generator extracts constraints from Symfony Validator attributes:
| Attribute | OpenAPI Property |
|---|---|
@Assert\NotBlank |
required: true |
@Assert\Length(min, max) |
minLength, maxLength |
@Assert\Range(min, max) |
minimum, maximum |
@Assert\Email |
format: email |
@Assert\Url |
format: uri |
@Assert\Uuid |
format: uuid |
๐ Advanced Features
Enum Support
Generates enum schemas from PHP 8.1+ backed enums:
Generated Schema:
Nested DTOs
Automatically generates schemas for nested DTO objects:
Generated Schema:
Typed Collections
Supports typed arrays using PHPDoc annotations:
Generated Schema:
Union Types
Generates oneOf schemas for union types:
Generated Schema:
๐ฏ Features
Route Detection
Scans your application's route configuration:
Automatic Operation Generation
Creates OpenAPI operations with:
- HTTP method (GET, POST, PUT, DELETE, etc.)
- Path parameters (extracted from
{id}patterns) - Request body (for POST/PUT/PATCH)
- Response schemas
- Summary and operationId
- Tags (from module namespace)
Path Parameters
Automatically detects and types path parameters:
๐ Generated Output
OpenAPI Structure
๐ง Configuration
Full Configuration Example
๐ Integration with Swagger UI
View your generated OpenAPI specification:
Or use online tools:
๐งช Testing
๐ค Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Write tests for new features
- Ensure all quality checks pass (
composer quality) - Submit a pull request
๐ License
MIT License. See LICENSE for details.
๐ Related Packages
This package is part of the MethorZ HTTP middleware ecosystem:
| Package | Description |
|---|---|
| methorz/http-dto | Automatic HTTP โ DTO conversion with validation |
| methorz/http-problem-details | RFC 7807 error handling middleware |
| methorz/http-cache-middleware | HTTP caching with ETag support |
| methorz/http-request-logger | Structured logging with request tracking |
| methorz/openapi-generator | Automatic OpenAPI spec generation (this package) |
These packages work together seamlessly in PSR-15 applications.
๐ Acknowledgments
Built with:
๐ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
๐ Links
- Changelog
- Contributing
- Security
Made with โค๏ธ by Thorsten Merz
All versions of openapi-generator with dependencies
psr/container Version ^1.1 || ^2.0
symfony/console Version ^6.0 || ^7.0
symfony/yaml Version ^6.0 || ^7.0