https://github.com/apioo/psx-api
TypeAPI parser and SDK code generator
https://github.com/apioo/psx-api
code-generator openapi php swagger typeapi
Last synced: about 2 months ago
JSON representation
TypeAPI parser and SDK code generator
- Host: GitHub
- URL: https://github.com/apioo/psx-api
- Owner: apioo
- License: apache-2.0
- Created: 2016-03-31T12:39:05.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-09-27T09:35:26.000Z (2 months ago)
- Last Synced: 2025-09-27T11:28:08.279Z (2 months ago)
- Topics: code-generator, openapi, php, swagger, typeapi
- Language: PHP
- Homepage: https://typeapi.org/
- Size: 1.58 MB
- Stars: 36
- Watchers: 2
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# API
This library provides an attribute parser to dynamically generate a [TypeAPI](https://typeapi.org/) specification
from any controller (code-first). Based on the specification it is then possible to generate client SDKs or
an OpenAPI specification.
We provide also a hosted version of this [code generator](https://typeapi.org/generator).
For more integration options you can also take a look at the [SDKgen](https://sdkgen.app/) project
which provides a CLI binary or GitHub action to integrate the code generator.
## 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.
### 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:
```php
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);
```