njuhel/swagger-validator

This package is abandoned and no longer maintained. No replacement package was suggested.

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

1.3.2 2017-04-24 21:30 UTC

README

Dependency Status ~ Code Climate ~ Test Coverage ~ Travis branch

Packagist ~ Composer

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