{"id":19300046,"url":"https://github.com/kirschbaum-development/laravel-openapi-validator","last_synced_at":"2025-04-07T15:07:57.915Z","repository":{"id":43704983,"uuid":"298427889","full_name":"kirschbaum-development/laravel-openapi-validator","owner":"kirschbaum-development","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-28T17:26:34.000Z","size":43,"stargazers_count":55,"open_issues_count":3,"forks_count":11,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-03-31T12:08:30.686Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kirschbaum-development.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-25T00:37:05.000Z","updated_at":"2025-03-28T17:26:38.000Z","dependencies_parsed_at":"2024-04-10T12:40:37.731Z","dependency_job_id":null,"html_url":"https://github.com/kirschbaum-development/laravel-openapi-validator","commit_stats":{"total_commits":21,"total_committers":7,"mean_commits":3.0,"dds":0.4285714285714286,"last_synced_commit":"7fd3d9982f356a919e9239d2f061d086ead9187d"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-openapi-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-openapi-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-openapi-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-openapi-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kirschbaum-development","download_url":"https://codeload.github.com/kirschbaum-development/laravel-openapi-validator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T23:13:30.967Z","updated_at":"2025-04-07T15:07:57.891Z","avatar_url":"https://github.com/kirschbaum-development.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel OpenAPI Validator\n\n![Laravel Supported Versions](https://img.shields.io/badge/laravel-6.x/7.x/8.x/9.x/10.x/11.x/12.x-green.svg)\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n\nUsing an OpenAPI spec is a great way to create and share a contract to which your API adheres. This package will automatically verify both the request and response used in your integration and feature tests wherever the Laravel HTTP testing methods (`-\u003eget('/uri')`, etc) are used.\n\nBehind the scenes this package connects the [Laravel HTTP helpers](https://laravel.com/docs/8.x/http-tests) to [The PHP League's OpenAPI Validator](https://github.com/thephpleague/openapi-psr7-validator).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require kirschbaum-development/laravel-openapi-validator\n```\n\n## Setup\n\nIn any feature/integration test (such as those that extend the framework's `Tests\\TestCase` base class), add the `ValidatesOpenApiSpec` trait:\n\n```php\nuse Kirschbaum\\OpenApiValidator\\ValidatesOpenApiSpec;\n\nclass HttpTest extends TestCase\n{\n    use ValidatesOpenApiSpec;\n}\n```\n\nIn many situations, the defaults should handle configuration. If you need to customize your configuration (namely the location of the `openapi.yaml` or `openapi.json` file), publish the config with:\n\n```bash\nphp artisan vendor:publish --provider=\"Kirschbaum\\OpenApiValidator\\OpenApiValidatorServiceProvider\"\n```\n\nand configure the path to the OpenAPI spec in `config/openapi_validator.php` to fit your needs.\n\n## Usage\n\nAfter applying the trait to your test class, anytime you interact with an HTTP test method (`get`, `post`, `put`, `delete`, `postJson`, `call`, etc), the validator will validate both the request and the response.\n\n### Skipping Validation\n\nEspecially when initially writing tests (such as in TDD), it can be helpful to turn off the request or response validation until the tests are closer to complete. You can do so as follows:\n\n```php\npublic function testEndpointInProgress()\n{\n    $response = $this-\u003ewithoutRequestValidation()-\u003eget('/'); // Skips request validation, still validates response\n    // or\n    $response = $this-\u003ewithoutResponseValidation()-\u003eget('/'); // Validates the request, but skips response\n    // or\n    $response = $this-\u003ewithoutValidation()-\u003eget('/'); // No validation\n}\n```\n\nYou are free to chain these methods as shown above, or call them on their own:\n\n```php\npublic function testEndpointInProgress()\n{\n    $this-\u003ewithoutRequestValidation();\n    $response = $this-\u003eget('/');\n}\n```\n\nKeep in mind that `withoutRequestValidation()`, `withoutResponseValidation()`, and `withoutValidation()` only apply to the _next_ request/response and will reset afterwards.\n\n#### Skipping Responses Based on Response Code\n\nWe assume, by default, that any `5xx` status code should not be validated. You may change this by setting the protected `responseCodesToSkip` property on your test class, or by using the `skipResponseCode` method to add response codes (single, array, or a regex pattern):\n\n```php\nuse Kirschbaum\\OpenApiValidator\\ValidatesOpenApiSpec;\n\nclass HttpTest extends TestCase\n{\n    use ValidatesOpenApiSpec;\n\n    protected $responseCodesToSkip = [200]; // Will validate every response EXCEPT 200\n\n    public function testNoRedirects()\n    {\n        $this-\u003eskipResponseCode(300); // Will skip 200 and 300\n        $this-\u003eskipResponseCode(301, 302); // Will skip 200, 300, 301, 302\n        $this-\u003eskipResponseCode('3[1-2]1'); // Will skip 200, 300, 301, 302, 311, and 321\n        // ...\n    }\n}\n```\n\n### Authentication/Authorization\n\nIn most tests, you're likely using Laravel's helpers such as `actingAs($user)` to handle auth. This package, by default, assumes you're using bearer token as an authorization header, _and that this is specified in your OpenAPI spec_. The validator will expect the authorization to be part of the request, even though Laravel does not send them. If you are using security other than a bearer token, you should override the `getAuthenticatedRequest` method and add the appropriate headers. Note that they do not need to be valid (unless your code will check them), they just need to be present to satisfy the validator.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email security@kirschbaumdevelopment.com instead of using the issue tracker.\n\n## Credits\n\n- [Zack Teska](https://github.com/zerodahero)\n\n## Sponsorship\n\nDevelopment of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more [about us](https://kirschbaumdevelopment.com) or [join us](https://careers.kirschbaumdevelopment.com)!\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirschbaum-development%2Flaravel-openapi-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkirschbaum-development%2Flaravel-openapi-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirschbaum-development%2Flaravel-openapi-validator/lists"}