Parse and generate API specification formats
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
bin fix api bin and add test case Jan 6, 2018
resources update template Oct 3, 2017
src Merge branch 'master' of Sep 4, 2018
.travis.yml add php 7.2 Nov 30, 2017 update changelog May 5, 2018
LICENSE initial import Mar 31, 2016 update docs May 5, 2018
composer.json update deps Apr 9, 2018
phpunit.xml fix tests and moved framework dependent tests Apr 1, 2016



Currently there are several API specification formats (OpenAPI, RAML, Swagger, etc.) which describe the functionality of an API endpoint. This project provides a data model which contains the common information of an API endpoint. There are parser classes which create such models based on a specification and it is also possible to generate a specification from a model object. We have also created an online tool to test those conversions.



  • HTML (Generates a HTML representation of the resource)
  • JsonSchema (Generates a JsonSchema which contains all schemas of the specification)
  • Markdown (Generates a Markdown representation of the resource)
  • OpenAPI (Generates a OpenAPI 3.0 specification)
  • PHP (Generates PHP source code which represents a controller consuming the API resource)
  • RAML (Generates a RAML 1.0 specification)
  • Swagger (Generates a Swagger 2.0 specification)
  • Template (Generates a representation based on a Twig template)


The root model object is called resource which represents a specific API endpoint. The following is a simple showcase of the resource API so you get a basic understanding how it is designed.


// reads the OpenAPI specification and generates a resource object which was
// defined under the path /foo
$resource = \PSX\Api\Parser\OpenAPI::fromFile('openapi.json', '/foo');

// returns the title

// returns available path parameters as PSX\Schema\PropertyInterface

// checks whether a specific request method is supported

// returns all allowed methods

// returns the available query parameters per method as PSX\Schema\PropertyInterface

// checks whether the method has a request specification

// returns the request body specification as PSX\Schema\SchemaInterface

// checks whether the method has a response with the status code 201

// returns the response body specification as PSX\Schema\SchemaInterface

// creates a PHP controller which consumes the defined /foo resource
$generator = new \PSX\Api\Generator\Php();

$source = $generator->generate($resource);