bradcrumb / ze-swagger-codegen
Zend Expressive Swagger codegen
Installs: 1 334
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: ^7.1
- doctrine/annotations: ^1.6
- fig/http-message-util: ^1.1
- ocramius/proxy-manager: ^2.1
- roave/security-advisories: dev-master
- symfony/console: ^3.0 || ^4.0
- zendframework/zend-cache: ^2.7
- zendframework/zend-diactoros: ^1.7
- zendframework/zend-filter: ^2.8
- zendframework/zend-hydrator: ^2.3
- zendframework/zend-servicemanager: ^3.3
- zendframework/zend-validator: ^2.10
- zordius/lightncandy: ^1.2
Requires (Dev)
- filp/whoops: ^2.1.12
- guzzlehttp/guzzle: ^6.3
- infection/infection: ^0.12.2
- leanphp/phpspec-code-coverage: ^4.2
- mikey179/vfsstream: ^1.6
- phpspec/phpspec: ^4.3
- phpstan/phpstan: ^0.10.0
- psr/http-server-middleware: ^1.0
- squizlabs/php_codesniffer: ^2.9.1
This package is not auto-updated.
Last update: 2025-03-02 08:09:11 UTC
README
With this package you can easily generate Handlers, Models and Routes according to your OpenAPI Specification (OAS) 3.0 config.
Requirements
- Zend Expressive +3.0
Installation
composer require bradcrumb/ze-swagger-codegen
Usage
Simply place your openapi.json
inside of your project root and run the following command:
vendor/bin/swagger codegen
By default the choosen namespace will be App
. You can overwrite the namespace with the --namespace option:
vendor/bin/swagger codegen --namespace MyOwnNamespace
The CLI will search for the correct path inside of the composer autoloading. When a namespace is not registered for autoloading it will ask if the namespace folder have to be created and registered in composer.json
.
Files
The Codegen will generate the following files:
File | Description |
---|---|
config/autoload/swagger.dependencies.global.php |
Generated dependency and hydrators config |
config/swagger.routes.php |
Swagger routing config |
*/Handler/* |
Namespace to put all generated Handlers |
*/Model/* |
Namespace to put all generated Models |
*/Hydrator/* |
Namespace to put all generated Hydrators |
Model Middleware
Every route that requires a Model in its RequestBody has a prepended Middleware: Swagger\Middleware\ModelMiddleware
.
The Middleware retrieves the RequestBody, hydrates the correct Model and validates the Model.
When the RequestBody is invalid it simply returns all errors messages for every property in a 400 response.
When the RequestBody is valid the hydrated model will be added as attribute to the request and can be retrieved inside the Handler:
$request->getAttribute('Model');