{"id":37014028,"url":"https://github.com/luispabon/swagger-validator","last_synced_at":"2026-01-14T01:23:35.247Z","repository":{"id":62519979,"uuid":"111580625","full_name":"luispabon/swagger-validator","owner":"luispabon","description":"Validate Swagger (OpenAPI) interface agreements in PHP. The useful component for tests automation !","archived":false,"fork":true,"pushed_at":"2020-02-08T23:09:03.000Z","size":104,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-27T15:24:37.592Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"WakeOnWeb/swagger","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luispabon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-21T17:30:32.000Z","updated_at":"2020-02-08T23:09:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/luispabon/swagger-validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/luispabon/swagger-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luispabon%2Fswagger-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luispabon%2Fswagger-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luispabon%2Fswagger-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luispabon%2Fswagger-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luispabon","download_url":"https://codeload.github.com/luispabon/swagger-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luispabon%2Fswagger-validator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-14T01:23:34.696Z","updated_at":"2026-01-14T01:23:35.222Z","avatar_url":"https://github.com/luispabon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Note: \n\nThis is a fork of WakeOnWeb's swagger validation component. It is a pretty good package, but fairly limited and very \nslow moving - it probably was made to serve the needs of WakeOnWeb's projects.\n\nI intend to push this forward without the limitations of requiring upstream approval as there are many gaps in\nfunctionality and test coverage. This will be for v2.x.\n\n## Roadmap:\n\n    * Version 1.0.x (up to 1.0.4) is essentially the same as WakeOnWeb's.\n    * Version 1.1.x will contain any fixes beyond WakeOnWeb\n    * Version 2.0.x will go well beyond the original library with OA3 support, framework integrations etc\n\n# Original README: \n\n# WakeOnWeb Swagger Validation Component [![Build Status](https://travis-ci.org/WakeOnWeb/swagger.svg?branch=master)](https://travis-ci.org/WakeOnWeb/swagger)\n\nThe WakeOnWeb Swagger Validation Component is an extensible component for validating API data using the \n[Swagger - OpenAPI](http://swagger.io) specification. The component supports both YAML and JSON Open API file formats. \nThe component has very a small dependency set in order to be usable in different PHP frameworks.\n\nThe component uses:\n\n- [PSR-6](http://www.php-fig.org/psr/psr-6/): For caching your OpenApi specification files\n- [PSR-7](http://www.php-fig.org/psr/psr-7/): For processing HTTP messages (requests and responses)\n\nInstallation\n------------\n\nThe component can easily be installaed using\n\n    composer require wakeonweb/swagger\n    \nThe component uses a JSON Schema validator, by default, the [justinrainbow/json-schema](https://github.com/justinrainbow/json-schema) \nis in the dev dependencies. If you intend to use the component in production you need to execute:\n\n    composer require justinrainbow/json-schema\n    \nLoading an OpenAPI specification file\n-------------------------------------\n\nThe component supports both YAML and JSON OpenAPI format. Swagger files are loaded by the `SwaggerFactory`. The factory \naccepts a [PSR-6](http://www.php-fig.org/psr/psr-6/) `CacheItemPoolInterface`. If none provided it will use the\n`ArrayCachePool` provided by [cache/array-adapter](https://github.com/php-cache/array-adapter).\n\n```php\n$factory = new SwaggerFactory();\n\n// Register a YAML loader to load YAML Swagger files.\n$factory-\u003eaddLoader(new YamlLoader());\n\n// Load the Swagger definition.\n$swagger = $factory-\u003ebuildFrom('/path/to/swagger/file.yml');\n```\n\nExecuting this code will result in retrieving a tree representation of the specification into an instance of a `Swagger`\ndocument. At the moment, the cache contains the instance of the `Swagger` document.\n\nCreating the a content validator\n--------------------------------\n\nContent validation in the component is based on JSON Schema Validation. The OpenAPI Specification handles much more than this. \nFor example it allows to define query string parameters or the format of any HTTP Headers. The component supports all kind \nof validation.\n\nContent validators are used to validate the content of a request or a response. Any content validator must implement the \n`ContentValidatorInterface` and should be registered into an instance of a `ContentValidator`. The resulting instance can be \nused into an instance of a `SwaggerValidator`. \n\n```php\n// Create a content validator that validates requests and responses bodies.\n$contentValidator = new ContentValidator();\n\n// Register a specific content validator that handle \"application/json\".\n$contentValidator-\u003eregisterContentValidator(new JustinRainbowJsonSchemaValidator());\n```\n\nValidating a response\n---------------------\n\nValidating response makes sense only for testing... As you are supposed to have valid code respectfull of your \ninterface agreements in production! \n\n```php\n// Create the validator and register the content validator.\n$validator = new SwaggerValidator($swagger);\n$validator-\u003eregisterResponseValidator($contentValidator);\n\n// Sample with Symfony Response....\n$response = new Response(...);\n\n$psr7Factory = new DiactorosFactory();\n\n// Converts the response to a PRS-7 compliant format.\n$response = $psr7Factory-\u003ecreateResponse($response);\n\ntry {\n    // Validates the response against the required specification.\n    $validator-\u003evalidateResponseFor($response, PathItem::METHOD_GET, '/api/resource', 200);\n} catch (SwaggerValidatorException $e) {\n    // display $e message.\n}\n```\n\nValidating a request\n--------------------\n\nValidating response makes sense only for testing... As you are supposed to have valid code respectfull of your \ninterface agreements in production! \n\n```php\n// Create the validator and register the content validator.\n$validator = new SwaggerValidator($swagger);\n$validator-\u003eregisterRequestValidator($contentValidator);\n\n// Sample with Symfony Response....\n$request = new Request(...);\n\n$psr7Factory = new DiactorosFactory();\n\n// Converts the response to a PRS-7 compliant format.\n$request = $psr7Factory-\u003ecreateRequest($request);\n\ntry {\n    // Validates the request against the required specification.\n    $validator-\u003evalidateRequestFor($request, PathItem::METHOD_GET, '/api/resource');\n} catch (SwaggerValidatorException $e) {\n    // display $e message.\n}\n```\nComplete sample\n---------------\n\nThe following sample code demonstrates a complete usage of the component.\n\n```php\n\u003c?php\n\nuse Symfony\\Bridge\\PsrHttpMessage\\Factory\\DiactorosFactory;\nuse Symfony\\Component\\HttpFoundation\\Response;\nuse WakeOnWeb\\Component\\Swagger\\Specification\\PathItem;\nuse WakeOnWeb\\Component\\Swagger\\SwaggerFactory;\nuse WakeOnWeb\\Component\\Swagger\\Loader\\YamlLoader;\nuse WakeOnWeb\\Component\\Swagger\\Loader\\JsonLoader;\nuse WakeOnWeb\\Component\\Swagger\\Test\\ContentValidator;\nuse WakeOnWeb\\Component\\Swagger\\Test\\Exception\\SwaggerValidatorException;\nuse WakeOnWeb\\Component\\Swagger\\Test\\JustinRainbowJsonSchemaValidator;\nuse WakeOnWeb\\Component\\Swagger\\Test\\SwaggerValidator;\n\n$factory = new SwaggerFactory();\n\n// Register a YAML loader to load YAML Swagger files.\n$factory-\u003eaddLoader(new YamlLoader());\n\n// Load the Swagger definition.\n$swagger = $factory-\u003ebuildFrom('/path/to/swagger/file.yml');\n\n// Create a content validator that validates requests and responses bodies.\n$contentValidator = new ContentValidator();\n\n// Register a specific content validator that handle \"application/json\".\n$contentValidator-\u003eregisterContentValidator(new JustinRainbowJsonSchemaValidator());\n\n// Create the validator and register the content validator.\n$validator = new SwaggerValidator($swagger);\n$validator-\u003eregisterResponseValidator($contentValidator);\n\n$response = new Response(\n    '{...}',\n    200,\n    [\n        'Content-Type' =\u003e 'application/json',\n    ]\n);\n\n$psr7Factory = new DiactorosFactory();\n\n// Converts the response to a PRS-7 compliant format.\n$response = $psr7Factory-\u003ecreateResponse($response);\n\ntry {\n    // Validates the response against the required specification.\n    $validator-\u003evalidateResponseFor($response, PathItem::METHOD_GET, '/api/resource', 200);\n} catch (SwaggerValidatorException $e) {\n    // display $e message.\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluispabon%2Fswagger-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluispabon%2Fswagger-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluispabon%2Fswagger-validator/lists"}