2017 © Pedro Peláez
 

library api

Parse and generate API specification formats

image

psx/api

Parse and generate API specification formats

  • Saturday, May 5, 2018
  • by k42b3
  • Repository
  • 1 Watchers
  • 16 Stars
  • 17,348 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 41 Versions
  • 13 % Grown

The README.md

API

This library provides an attribute parser to dynamically generate a TypeAPI specification from any controller (code-first). Based on the specification it is then possible to generate client SDKs or an OpenAPI specification., (*1)

We provide also a hosted version of this code generator. For more integration options you can also take a look at the SDKgen project which provides a CLI binary or GitHub action to integrate the code generator., (*2)

Usage

The root model object is called a Specification which contains Operations and Definitions. Each operation maps to a specific REST API endpoint and the definitions represent the schemas to describe the JSON request or response payload., (*3)

Framework

You can use PHP attributes to describe the structure of your endpoints. You can then use the attribute parser (PSX\Api\Parser\Attribute) to automatically generate a specification for your controller. A controller class could then look like:, (*4)

<?php

class MyController
{
    #[Get]
    #[Path('/my/endpoint/:id')]
    public function getModel(#[Param] int $id, #[Query] int $year): \My\Response\Model
    {
        // @TODO implement
    }

    #[Post]
    #[Path('/my/endpoint')]
    public function insertModel(#[Body] \My\Request\Model $model): \My\Response\Model
    {
        // @TODO implement
    }
}

This would be enough for the API component to generate either an OpenAPI specification or a client SDK. Note this library only needs the meta information, if you can get those meta information at your framework in another way you can also implement a custom ParserInterface., (*5)

Standalone

Beside the framework integration you can use this component also to simply parse existing TypeAPI specification and generate specific output. The following is a simple example how to use the PHP API and how to generate code., (*6)

<?php

// use the API manager to obtain a specification from different sources
$manager = new \PSX\Api\ApiManager(new \PSX\Schema\SchemaManager());

// reads the TypeAPI specification and generates a specification
$specification = $manager->getApi('./typeapi.json');

// contains all schema type definitions
$definitions = $specification->getDefinitions();

// returns the resource foo from the specification
$operation = $specification->getOperations()->get('my.operation');

// returns all available arguments
$operation->getArguments();

// returns the return type
$operation->getReturn();

// returns all exceptions which are described
$operation->getThrows();

// returns the assigned HTTP method
$operation->getMethod();

// returns the assigned HTTP path
$operation->getPath();

// creates a PHP client which consumes the defined operations
$registry = \PSX\Api\GeneratorFactory::fromLocal()->factory();
$generator = $registry->getGenerator(\PSX\Api\Repository\LocalRepository::CLIENT_PHP)

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

The Versions

06/01 2018
30/11 2017
18/11 2017
14/11 2017
14/11 2017
12/11 2017
11/11 2017
11/11 2017
04/10 2017
03/10 2017
30/09 2017

v2.2.6

2.2.6.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

16/09 2017

v2.2.5

2.2.5.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

15/08 2017

v2.2.4

2.2.4.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

12/08 2017

v2.2.3

2.2.3.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

10/08 2017

v2.2.2

2.2.2.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

09/08 2017

v2.2.1

2.2.1.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

07/08 2017

v2.2.0

2.2.0.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

02/08 2017

v2.1.2

2.1.2.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

30/07 2017

v2.1.1

2.1.1.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

07/05 2017

v2.1.0

2.1.0.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

04/05 2017

v2.0.6

2.0.6.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

28/01 2017

v2.0.5

2.0.5.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

25/12 2016

v2.0.4

2.0.4.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

25/12 2016

v2.0.3

2.0.3.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

22/12 2016

v2.0.2

2.0.2.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

19/12 2016

v2.0.1

2.0.1.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

17/12 2016

v2.0.0

2.0.0.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

30/10 2016

v1.0.3

1.0.3.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

10/07 2016

v1.0.2

1.0.2.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

29/05 2016

v1.0.1

1.0.1.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

08/05 2016

v1.0.0

1.0.0.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

30/04 2016

v0.1.4

0.1.4.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

24/04 2016

v0.1.3

0.1.3.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

21/04 2016

v0.1.2

0.1.2.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

02/04 2016

v0.1.1

0.1.1.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml

02/04 2016

v0.1.0

0.1.0.0 http://phpsx.org

Parse and generate API specification formats

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

api swagger specification wsdl raml