Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/temirkhann/openapi-validator-bundle
An OpenAPI specification validator for a symfony application
https://github.com/temirkhann/openapi-validator-bundle
openapi symfony-bundle
Last synced: 3 days ago
JSON representation
An OpenAPI specification validator for a symfony application
- Host: GitHub
- URL: https://github.com/temirkhann/openapi-validator-bundle
- Owner: TemirkhanN
- License: mit
- Created: 2022-06-16T12:15:29.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-06-17T17:28:10.000Z (over 2 years ago)
- Last Synced: 2024-11-14T08:09:10.747Z (2 months ago)
- Topics: openapi, symfony-bundle
- Language: PHP
- Homepage: https://temirkhan.nasukhov.me/blog/2022-06-07_How-to-keep-an-API-documentation-up-to-date
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# openapi-validator-bundle
An OpenAPI specification validator for a symfony applicationIt checks if the request and response from your symfony application matches your openapi documentation file.
If the endpoint is not documented, receives or responds with mismatching payload it will throw `ValidationError`.
This comes in handy when application has integration/functional/manual tests because it will alert early that documentation
is outdated.## Installation
```bash
composer require temirkhann/openapi-validator-bundle
```## Usage
Enable bundle in `config/bundles.php`
```php
// Usually you don't want validation to work on your production server.
// So, enable it for all envs and disable for prod
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['test' => true],
....
TemirkhanN\OpenapiValidatorBundle\OpenapiValidatorBundle::class => ['all' => true, 'prod' => false],
];```
Declare configuration in `config/packages/openapi_validator.yaml` as follows:
```yaml
openapi_validator:
# Path to your openapi specification (json or yaml)
# Only local file is accepted (http links won't work)
specification: '%kernel.project_dir%/openapi.yaml'```
## Configuration
If you have multiple sections in your application or for some reason don't want to apply validation to some particular
endpoints you can use exclusion policy```yaml
openapi_validator:
specification: '%kernel.project_dir%/openapi.yaml'
policy:
exclude:
paths:
- '#^/some-internal/#'
status_codes:
- 304
- 500
````paths` accepts list of regexp patterns. If the request path(not URI) matches pattern then validation will be omitted.
> defaults value is empty list - validation is applied to every single route.`status_codes` accepts list of integer values which represent http status-codes. If response code matches any of these
then validation will be omitted.
> default value is 500. There should never be 500 in API documentation.