psx / api
Parse and generate API specification formats
Installs: 48 392
Dependents: 1
Suggesters: 0
Security: 0
Stars: 25
Watchers: 1
Forks: 8
Open Issues: 0
Requires
- php: >=7.2
- doctrine/annotations: ^1.3
- doctrine/cache: ^1.6
- nikic/php-parser: ^4.0
- psx/cache: ^1.0
- psx/json: ^1.0
- psx/model: ^3.0
- psx/schema: ^3.0
- symfony/console: ^4.0|^5.0
- symfony/yaml: ^4.0|^5.0
- twig/twig: ^2.4
Requires (Dev)
- phpunit/phpunit: ^8.0
- vimeo/psalm: ^3.11
- dev-master
- v3.0.1
- v3.0.0
- v3.0.0-RC5
- v3.0.0-RC4
- v3.0.0-RC3
- v3.0.0-RC2
- v3.0.0-RC1
- 2.7.x-dev
- v2.7.4
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.6
- v2.6.5
- v2.6.4
- v2.6.3
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.6
- v2.5.5
- v2.5.4
- v2.5.3
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.9
- v2.4.8
- v2.4.7
- v2.4.6
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.1
- v2.3.0
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
This package is auto-updated.
Last update: 2020-12-25 21:08:10 UTC
README
About
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.
Parser
- Annotation (Parses a class which contains annotations)
- OpenAPI (OpenAPI 3.0 specification)
- RAML (RAML 0.8/1.0 specification)
- Swagger (Swagger 2.0 specification)
Generator
Client
- PHP (Generates a PHP client stub)
- Typescript (Generates a Typescript based client stub)
Markup
- HTML (Generates a HTML representation of the resource)
- Markdown (Generates a Markdown representation of the resource)
- Template (Generates a representation based on a Twig template)
Server
- PHP (Generates a PHP controller class which represents the API resource)
Spec
- JsonSchema (Generates a JsonSchema which contains all schemas of the specification)
- OpenAPI (Generates a OpenAPI 3.0 specification)
- RAML (Generates a RAML 1.0 specification)
- Swagger (Generates a Swagger 2.0 specification)
Usage
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.
<?php // 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 $resource->getTitle(); // returns available path parameters as PSX\Schema\PropertyInterface $resource->getPathParameters(); // checks whether a specific request method is supported $resource->hasMethod('POST'); // returns all allowed methods $resource->getAllowedMethods(); // returns the available query parameters per method as PSX\Schema\PropertyInterface $resource->getMethod('POST')->getQueryParameters(); // checks whether the method has a request specification $resource->getMethod('POST')->hasRequest(); // returns the request body specification as PSX\Schema\SchemaInterface $resource->getMethod('POST')->getRequest(); // checks whether the method has a response with the status code 201 $resource->getMethod('POST')->hasResponse(201); // returns the response body specification as PSX\Schema\SchemaInterface $resource->getMethod('POST')->getResponse(201); // creates a PHP client which consumes the defined /foo resource $generator = new \PSX\Api\Generator\Client\Php(); $source = $generator->generate($resource);