{"id":16948254,"url":"https://github.com/dermanomann/openapi-verifier","last_synced_at":"2025-03-22T13:31:09.153Z","repository":{"id":34933910,"uuid":"191481717","full_name":"DerManoMann/openapi-verifier","owner":"DerManoMann","description":"Verify JSON (api response) against OpenAPI specification.","archived":false,"fork":false,"pushed_at":"2025-03-05T00:03:22.000Z","size":90,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-18T11:38:57.931Z","etag":null,"topics":["annotation","hacktoberfest","laravel","openapi","phpunit"],"latest_commit_sha":null,"homepage":"","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/DerManoMann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2019-06-12T02:20:40.000Z","updated_at":"2025-01-09T20:28:35.000Z","dependencies_parsed_at":"2023-12-22T04:08:38.917Z","dependency_job_id":"17b388ec-c678-46be-ab10-3576a43a38dd","html_url":"https://github.com/DerManoMann/openapi-verifier","commit_stats":{"total_commits":42,"total_committers":2,"mean_commits":21.0,"dds":0.09523809523809523,"last_synced_commit":"3a858245e8f9ad54070fffa1b2b69841a85ae058"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerManoMann%2Fopenapi-verifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerManoMann%2Fopenapi-verifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerManoMann%2Fopenapi-verifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerManoMann%2Fopenapi-verifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DerManoMann","download_url":"https://codeload.github.com/DerManoMann/openapi-verifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244962780,"owners_count":20539224,"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":["annotation","hacktoberfest","laravel","openapi","phpunit"],"created_at":"2024-10-13T21:50:07.572Z","updated_at":"2025-03-22T13:31:09.134Z","avatar_url":"https://github.com/DerManoMann.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openapi-verifier\n[![build](https://github.com/DerManoMann/openapi-verifier/actions/workflows/build.yml/badge.svg)](https://github.com/DerManoMann/openapi-verifier/actions/workflows/build.yml)\n[![Coverage Status](https://coveralls.io/repos/github/DerManoMann/openapi-verifier/badge.svg)](https://coveralls.io/github/DerManoMann/openapi-verifier)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Introduction\nAllows to validate a controller response from your API project against a given [OpenAPI](https://www.openapis.org/)\nspecification. \n\n## Requirements\n* [PHP 8.1 or higher](http://www.php.net/)\n\n## Installation\nYou can use **composer** or simply **download the release**.\n\n**Composer**\n\nThe preferred method is via [composer](https://getcomposer.org). Follow the\n[installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have\ncomposer installed.\n\nOnce composer is installed, execute the following command in your project root to install this library:\n\n```sh\ncomposer require radebatz/openapi-verifier\n```\nAfter that all required classes should be availabe in your project to add routing support.\n\n## Usage\n### Manual verification\nThe `VerifiesOpenApi` trait can be used directly and customized in 3 ways in order to provide the reqired OpenApi specifications:\n* Overriding the method `getOpenApiSpecificationLoader()` as shown below\n* Populating the `$openapiSpecificationLoader` property.\n* Setting a property `$openapiSpecification` pointing to the specification file\n\n```php\n\u003c?php\n\nnamespace Tests\\Feature;\n\nuse Radebatz\\OpenApi\\Verifier\\VerifiesOpenApi;\nuse Radebatz\\OpenApi\\Verifier\\OpenApiSpecificationLoader;\nuse PHPUnit\\Framework\\TestCase;\n\nclass UsersTest extends TestCase\n{\n    use VerifiesOpenApi;\n    \n    /** @inheritdoc */\n    protected function getOpenApiSpecificationLoader(): ?OpenApiSpecificationLoader\n    {\n        return new OpenApiSpecificationLoader(__DIR__ . '/specifications/users.yaml');\n    }\n\n    /** @test */\n    public function index()\n    {\n        // PSR client\n        $client = $this-\u003eclient();\n        $response = $client-\u003eget('/users');\n\n        $this-\u003eassertEquals(200, $response-\u003egetStatusCode());\n        \n        // will throw OpenApiSchemaMismatchException if verification fails\n        $this-\u003everifyOpenApiResponseBody('get', '/users', 200, (string) $response-\u003egetBody());\n    }\n}\n\n```\n### Laravel adapter\nThe adapter will try to resolve the specification dynamically in this order:\n* filename passed into `registerOpenApiVerifier()`\n* `/tests/openapi.json`\n* `/tests/openapi.yaml`\n* Generate specification from scratch by scanning the `app` folder\n\nThe code expects to be in the context of a Laravel `Test\\TestCase`.\n\n```php\n\u003c?php\n\nnamespace Tests\\Feature;\n\nuse Radebatz\\OpenApi\\Verifier\\Adapters\\Laravel\\OpenApiResponseVerifier;\nuse Tests\\TestCase;\n\nclass UsersTest extends TestCase\n{\n    use OpenApiResponseVerifier;\n\n    public function setUp(): void\n    {\n        parent::setUp();\n\n        $this-\u003eregisterOpenApiVerifier(/* $this-\u003e\u003ecreateApplication() */ /* , [specification filename] */);\n    }\n\n    /** @test */\n    public function index()\n    {\n        // will `fail` if schema found and validation fails\n        $response = $this-\u003eget('/users');\n\n        $response-\u003eassertOk();\n    }\n}\n\n```\n\n### Slim adapter\nThe adapter will try to resolve the specification dynamically in this order:\n* filename passed into `registerOpenApiVerifier()`\n* `/tests/openapi.json`\n* `/tests/openapi.yaml`\n* Generate specification from scratch by scanning the `src` folder\n\nSimplest way is to register the verifier in the `Tests\\Functional\\BaseTestCase`.\n\n**Attention**: In order to be able to resolve routes with placeholders (i.e. something like `/user/{id}`) it is required to register the verifier **before** the routing middleware.\n\n```php\n\u003c?php\n\nnamespace Tests\\Functional;\n\nuse ...\nuse Radebatz\\OpenApi\\Verifier\\Adapters\\Slim\\OpenApiResponseVerifier;\nuse PHPUnit\\Framework\\TestCase;\n\nclass BaseTestCase extends TestCase\n{\n    use OpenApiResponseVerifier;\n\n    public function runApp($requestMethod, $requestUri, $requestData = null)\n    {\n        ...\n        \n        $app = new App();\n        \n        // register OpenApi verifier\n        $this-\u003eregisterOpenApiVerifier($app, __DIR__ . '/../specifications/users.yaml');\n        $app-\u003eaddRoutingMiddleware();\n        \n        // ...\n    }\n}\n```\n```php\n\u003c?php\n\nnamespace Tests\\Functional;\n\nclass UsersTest extends BaseTestCase\n{\n    /** @test */\n    public function index()\n    {\n        // will `fail` if schema found and validation fails\n        $response = $this-\u003erunApp('GET', '/users');\n\n        $this-\u003eassertEquals(200, $response-\u003egetStatusCode());\n    }\n}\n```\n\n## License\nThe openapi-verifier project is released under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdermanomann%2Fopenapi-verifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdermanomann%2Fopenapi-verifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdermanomann%2Fopenapi-verifier/lists"}