Download the PHP package wapmorgan/openapi-generator without Composer
On this page you can find all versions of the php package wapmorgan/openapi-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wapmorgan/openapi-generator
More information about wapmorgan/openapi-generator
Files in wapmorgan/openapi-generator
Package openapi-generator
Short Description OpenApi configuration generator directly from PHP code (PhpDoc, functions signature and type hints) and projects (for yii2, slim, laravel). Can be used with a large monolithic backend to maintain big API documentation
License MIT
Informations about the package openapi-generator
What is it?
It is OpenApi configuration generator that works with origin source code + phpdoc.
Main purpose of this library is to automatize generation of OpenApi-specification for existing JSON-API with a lot of methods. Idea by @maxonrock.
- Open Api generator
- Laravel Example
- How it works
- How to use
- Integrations
- Extending
- New scraper
- Settings
- Limitations
- ToDo
OpenApiGenerator
What it does?
It generates OpenApi 3.0 specification files for your REST JSON-based API written in PHP from source code directly. You do not need to write OpenApi-specification manually.
Laravel Example
-
Routes:
-
One controller:
-
One request and two responses:
- Result of generation from code: two endpoints with description and arguments for
select
.
How it works
- Scraper collects info about API (tags, security schemes and servers, all endpoints) and contains settings for Generator. Scraper is framework-dependent.
- Generator fulfills openapi-specification with endpoints information by analyzing source code:
- summary and description of actions
- parameters and result of actions Generator is common. It just receives information from Scraper and analyzes code by Scraper rules.
More detailed process description is in How it works document.
How to use
Invoke console script to generate openapi for your project (with help of integrations):
For example, for yii2-project:
-
Run parser on project to analyze files and retrieve info about endpoints
-
Generate specification(s) into yaml-files in
api_docs
folder by specification_name.yml - Deploy swagger with specification (e.g. _apidocs/main.yml on port 8091)
More detailed description is in How to use document.
Integrations
There's few integrations: Yii2, Laravel, Slim. Details is in Integrations document. You can write your own integration for framework or your project.
Extending
New scraper
You use (or extend) a predefined scraper (see Integrations) or create your own scraper from scratch (extend DefaultScraper
), which should return a result with list of your API endpoints. Also, your scraper should provide tags, security schemes and so on.
Scraper should return list of specifications (for example, list of api versions) with:
- meta - version/description/externalDocs - of specification.
- servers - list of servers (base urls).
- tags - list of tags with description and other properties (categories for endpoints).
- securitySchemes - list of security schemes (authorization types).
- endpoints - list of API endpoints (separate callbacks).
Detailed information about Scraper result: in another document.
Settings
DefaultGenerator provides list of settings to tune generator.
Parameter | type | default | description |
---|---|---|---|
CHANGE_GET_TO_POST_FOR_COMPLEX_PARAMETERS | bool | false | if callback has arguments with object , array , stdclass , mixed type or class-typed, method of argument will be changed to POST and these arguments will be placed as body data in json-format |
TREAT_COMPLEX_ARGUMENTS_AS_BODY | bool | false | move complex arguments to request body |
PARSE_PARAMETERS_FROM_ENDPOINT | bool | false | if callback id has macroses (users/{id} ), these arguments will be parsed as normal callback arguments |
PARSE_PARAMETERS_FORMAT_FORMAT_DESCRIPTION | bool | false | if php-doc for callback argument in first word after argument variable has one of predefined sub-types (@param string $arg SUBTYPE Full parameter description ), this will change sub-type in resulting specification. For example, for string format there are subtypes: date , date-time , password , byte , binary , for integer there are: float , double , int32 , int64 . Also, you can defined custom format with DefaultGenerator::setCustomFormat($format, $formatConfig) |
Usage:
By default, they all are disabled.
Limitations
- Only query parameters supported (
url?param1=...¶m2=...
) or body json parameters ({data: 123
). - Only one response type supported - HTTP 200 response.
- No support for parameters' / fields' / properties'
format
,example
and other validators.
ToDo
- [x] Support for few operations on one endpoint (GET/POST/PUT/DELETE/...).
- [x] Support for body parameters (when parameters are complex objects) - partially.
- [ ] Support for few responses (with different HTTP codes).
- [ ] Extracting class types into separate components (into openapi components).
- [ ] Support for other request/response types besides JSON
- [x] Add
@paramFormat
for specifying parameter format - partially. - [ ] Support for dynamic action arguments in dynamic model
- [ ] Switch 3.0/3.1 (https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0)
All versions of openapi-generator with dependencies
zircote/swagger-php Version ^3.0
doctrine/annotations Version ^1.6
phpdocumentor/reflection-docblock Version ^4.3|^5.1
symfony/console Version ^5.0|^6.0