kleijnweb / swagger-bundle
Makes your Swagger definition into a routing and validation spec
Installs: 16 043
Dependents: 2
Suggesters: 0
Security: 0
Stars: 24
Watchers: 4
Forks: 13
Open Issues: 11
Type:symfony-bundle
Requires
- php: ^7.0.0
- doctrine/cache: ^1.6
- doctrine/collections: ^1.3
- kleijnweb/php-api-descriptions: ^1.0.0-alpha4
- kleijnweb/php-api-hydrator: ^1.0.0-alpha2
- kleijnweb/php-api-middleware: ^1.0.0-alpha1
- kleijnweb/php-api-routing-bundle: ^1.0.0-alpha1
- psr/log: ^1.0
- symfony/config: >=2.8.7
- symfony/dependency-injection: >=2.8.7
- symfony/event-dispatcher: >=2.8.7
- symfony/filesystem: >=2.8.7
- symfony/finder: >=2.8.7
- symfony/http-foundation: >=2.8.7
- symfony/http-kernel: >=2.8.7
- symfony/property-access: >=2.8.7
- symfony/routing: >=2.8.7
- symfony/yaml: >=2.8.7
Requires (Dev)
- phpunit/phpunit: ^5.2
- phpunit/phpunit-mock-objects: ^3.1
- satooshi/php-coveralls: ^1.0
- symfony/browser-kit: >=2.8.7
- symfony/framework-bundle: >=2.8.7
- symfony/monolog-bridge: >=2.8.7
- symfony/monolog-bundle: ^2.8
- symfony/security-bundle: >=2.8.7
This package is not auto-updated.
Last update: 2024-01-15 08:27:58 UTC
README
Invert your workflow (contract first) using Swagger (Open API) specs and set up a Symfony REST app with minimal config.
Aimed to be lightweight, this bundle does not depend on FOSRestBundle or Twig.
HEADS UP: You are looking at the main (4.0 BETA) development line, which is PHP 7 only. SwaggerBundle 3.x is stable, maintained, and works with PHP 5.4+.
For a working example, check out https://github.com/kleijnweb/swagger-bundle-example.
Contract First
We say your OpenAPI definition is your config, and strive towards 'minimal additional config'. At the core, SwaggerBundle does three things:
- Configure Symfony routing
- Validate input
- Coerce/transform in- and output
Usage
- Create an OpenAPI document, for example using http://editor.swagger.io/.
- Install and configure this bundle
- Create one or more controllers (as services)
Check out the User Documentation for more details.
What's new in 4.0?
SwaggerBundle 4.0 is currently in the beta stage. Much of the behavior dealing with OpenAPI documents has been moved to KleijnWeb\PhpApi\Descriptions.
Routing
Now using kleijnweb/php-api-routing-bundle with a number of small improvements.
Security Integration
Request matching, voting, OpenAPI configured RBAC. See docs.
Serialization/Hydration
Support for 3rd party serializers has been replaced by a new API Description Based (de-)hyrator. Hydrating of untyped data is expected to be stdClass|stdClass[]
, not a combination of arrays and associative arrays as was the <4.0
default.
The new procoess has support for JSON-Schema specifics such as default values and smart NULL/undefined handling, as well as high extensibility. This allows you to hook pretty much anything you like into the (de-)hydration process, such as loading objects to be populated with request values from a data store or preserving identity of objects that occur more than once in a request.
Testing
The dependency on SwaggerAssertions
has been removed, as response validation is now facilitated by KleijnWeb\PhpApi\Descriptions
and integrated into the request cycle.
Errors And Exceptions
vnd.error
support has been removed in favor of simpler error responses. This also gets rid of some dependencies that were unneeded for most use cases.HttpError
now supportsAccessDeniedException
.
FAQ
- Will SwaggerBundle do
x
?
If x
is any of these, the answer will probably stay 'no':
- Handle Form posts.
- Generate API documentation.
- Support Symfony sub-requests. You won't miss them.
- Support XML.
Symfony Compatibility
SwaggerBundle is tested against Symfony 2.8.18 and the latest release (4.x.x), at least once a week.
Notes
Go to the release page to find details about the latest release.
Contributing
Pull request are very welcome, as long as:
- All automated checks were successful
- Merge would not violate semantic versioning
- When applicable, the relevant documentation is updated
License
KleijnWeb\SwaggerBundle is made available under the terms of the LGPL, version 3.0.