njuhel / swagger-validator
A Swagger Validation and Parser as lib for PHP to secure and helpful application for request / response validating, security stage, testunit skeleton, testauto generation, ... This lib can be used into any existing application who's having a swagger definition file for request/response (no framework
Installs: 1 901
Dependents: 1
Suggesters: 0
Security: 0
Stars: 21
Watchers: 3
Forks: 3
Open Issues: 5
Requires
- php: >5.3.10
- ext-bcmath: *
- ext-dom: *
- ext-json: *
- ext-pcre: *
- ext-reflection: *
- ext-spl: *
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- evert/phpdoc-md: ^0.2
- phpdocumentor/phpdocumentor: ^2.0
- phpunit/php-code-coverage: <=4.0
- phpunit/php-file-iterator: ^1.4
- phpunit/php-text-template: ^1.2
- phpunit/php-timer: ^1
- phpunit/phpunit: <=5.6
- phpunit/phpunit-mock-objects: <=3.4
This package is not auto-updated.
Last update: 2023-08-19 13:37:51 UTC
README
Swagger Validator PHP
A Swagger(OpenAPI) Validation and Parser as lib for PHP to secure and helpful application for request / response validating, security stage, testunit skeleton, testauto generation, ... This lib can be used into any existing application who's having a swagger definition file for request/response.
Swagger is old name of OpenAPI Projet and who manage the OAI Specification
Why Using a Swagger Validator
A Swagger Validator could be understand as a validation of our swagger definition file with the swagger definition. A Swagger Parser could be understand as a parser for request entry (sometimes in addition parsing response) The Swagger Validator is doing all this. It validate your swagger file, validate your entry request and response.
Validation / Parsing are mandatory
- validating the swagger guarantee that your definition file has no error and will be understand correctly
- validating the request is a security stage to filter bad request, attempted hack, limit the control and filtering statement in your working source code, ...
- validating the response is also security stage to filter not needed information before sent them, to limit and prevent error code attack, limit the control and filtering statement in your working source code ...
Features
- Best for Swagger First, Code after
- Validate / Filter All Request & Response
- Integration easy with any existing framework, application, ...
- Allow a soft migration for a complete application MVC to HIM/API application
- Give example model of request/response based on the swagger to example built automated testing stage, human skeleton for code, documentation skeletton, ...
- Validate the swagger file in following the Swagger 2.0 specification and JSON Draft v4 (swagger has higher priority to json draft 4)
- Custimization easy : all classes are overriding without writing the parser (using a customized factory)
- Working finely with single and multi file swagger definition
- Can generate single swagger definition file based on multi swagger definition file
- Allow local and remote definition file
- Allow using circular reference (only for no required properties in an object)
- Store validated request params into a sandbox to access only validated params (and clean magics globals variables)
- Follow RFC and recommandation for primitive type and format and not native language understanding type and format
- Using cache for working file in parsing request/response
- Using easy overriding IO class for collect request/response data to be validated
- Unit test in your environnement for checking compatibility
Need to do
- response building automaticly base on content type response, accept and produce
- reduce scope to PHP 7.1 (release >= 1.4)
- swagger / openapi version 3.0 (release >= 2.0)
Compatibility
- release <= 1.3 : scope PHP 5.3.10 (bug reported, need some more compatibilities) to PHP 7.0
- release >= 1.4 : scope PHP 7.1
- release >= 2.0 : openapi release 3.0 & PHP 7.1
Installation Guide
- Install into a git repository as submodule :
git submodule init git submodule add http://srv01.https://github.com/nabbar/SwaggerValidator-PHP src/lib/SwaggerValidator git submodule update
- Install by cloning git :
git clone https://github.com/nabbar/SwaggerValidator-PHP SwaggerValidator
- Install with composer (adding this in composer.json):
"require": { "nabbar/swagger-validator":">=1.2.0" },
- Install with phar :
wget https://github.com/nabbar/SwaggerValidator-PHP/raw/master/bin/SwaggerValidator.phar
Example & Docs
- Examples : Example.php
- Documentation : generated