avency/neos-openapi
Composer 安装命令:
composer require avency/neos-openapi
包简介
OpenApi Basic package with swagger ui rendering
README 文档
README
This package contains basics to generate an interactive OpenAPI documentation for a RESTful API using doctrine annotations.
It contains a controller that renders a swagger ui and which gets its input from a json-file generated based on the OpenAPI annotations in the projects' files.
It uses the sintbert/swagger-php package.
Calling the documentation
Backend
There is a backend module accessible as administrator, which renders the swagger UI.
Frontend
To call the documentation in the frontend, you need to be logged in in the backend as administrator. Then you can call the api:
{PROJECT_BASE_URI}/neos/api/documentation.html
To access just the generated json which is used to fill the Swagger UI, you can directly call the json file:
{PROJECT_BASE_URI}/neos/api/documentation.json
Writing the documentation
Files to consider for documentation
There is the possibility to specify the folder(s), which need to be considered for generating the documentation. The default is set to
FLOW_PATH_ROOT/LocalPackages
To change this, just change the Settings:
Avency:
Neos:
OpenApi:
scanPath: {NEW_PATH}
Import Statement
All files in which Annotations for the Documentation are added need to use the following statement
use OpenApi\Annotations as OA;
Annotations
Info
Need to be added in a separate file and contains general information about the api for example:
/**
* @OA\Info(
* version="0.1.0",
* title="Portal Api",
* description="This is a the documentation for the API which is used in the admin panel."
* )
*/
Tag
A tag serves as group in which the different api endpoints can be grouped in.
It should be defined in top of the distinct controllers.
The tag can be referenced in the different operations.
/**
* @OA\Tag(
* name="portal user",
* description="Everything about frontend portal users"
* )
*/
Operations
There are different operations available to describe the different api endpoints, like @OA\Get, @OA\Post, @OA\Put or @OA\Delete.
They should be each defined in the method description.
They contain a path, a brief summary and a description. @OA\Parameters can be added, if the url accepts parameters. The @OA\Response defines the different response codes.
/**
* @OA\Get(
* path="/api/v1/portaluser",
* summary="Find portal user by identifier",
* description="Returns user data for the given DB identifier or the specific value for a property",
* tags={"portal user"},
* @OA\Parameter(
* name="identifier",
* in="query",
* description="Identifier of user object",
* required=true,
* @OA\Schema(
* type="string",
* @OA\Items(type="string"),
* )
* ),
* @OA\Response(
* response=200,
* description="successful operation, returns user data",
* @OA\JsonContent(
* ref="#/components/schemas/User",
* type="object",
* @OA\Items(ref="#/components/schemas/User")
* ),
* ),
* @OA\Response(
* response="500",
* description="error - identifier was not passed as string, any portal user found by identifier",
* )
* )
*/
Schema
The schema describes a representation of a model.
The annotation should be added on the domain model. The schema-attribute is taken by the class name, but can be overwritten or set, if a special schema is defined outside of a domain model.
They contain a title and a brief description. If necessary, special @OA\Property values can be defined, if the schema should represent more than the in the class defined variables, like the identifier.
/**
* @OA\Schema(
* schema="User",
* title="User model",
* description="User model with all user related data",
* @OA\Xml(
* name="User"
* ),
* @OA\Property(
* property="identifier",
* description="db-identifier",
* title="identifier",
* example="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
* type="string"
* )
* )
*/
Property
The property describes a single property in a model. The annotation should be added close to the property.
Some information about type does not need to be explicitly defined but is for example taken from the type of the property.
/**
* @OA\Property(
* description="Last Name",
* title="Last Name",
* example="Mustermann"
* )
*
* @var string
* @ORM\Column(nullable=TRUE)
*/
protected $lastName;
It is also possible to refer to other Schema objects. This will be also detected by the property type, if there is an other schema for this type.
/**
* @OA\Property(
* description="Address",
* title="Address"
* )
*
* @ORM\OneToOne(cascade={"persist", "remove"})
* @ORM\Column(nullable=TRUE)
* @var Address
*/
protected $defaultAddress;
References can be also added manually.
@OA\Items(ref="#/components/schemas/Address")
More Information
Other parameters or annotations are available. More information can be found on the OpenAPI Specification website:
https://swagger.io/specification/
License
The MIT License (MIT). Please see License File for more information.
avency/neos-openapi 适用场景与选型建议
avency/neos-openapi 是一款 基于 CSS 开发的 Composer 扩展包,目前已累计 950 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「flow」 「documentation」 「rest」 「api」 「Neos」 「swagger」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 avency/neos-openapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 avency/neos-openapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 avency/neos-openapi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
Put images nicley in a row
Create link to static resources with cache-breaking segment based on md5 of the file
Laravel package that generates RESTful API documentation in Markdown based on PHPDoc.
A PSR-7 compatible library for making CRUD API endpoints
getting and sending flow
统计信息
- 总下载量: 950
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-11