kozluoglu / rest-api-bundle
Chameleon System 的 Symfony 扩展包
dev-master
2021-04-09 13:27 UTC
Requires
- php: ^7.4
- ext-json: *
- ext-pdo: *
- chameleon-system/chameleon-base: 7.1.x@dev
- zircote/swagger-php: ^3.1
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-25 20:22:35 UTC
README
此扩展包为 Chameleon Shop 提供 REST API 接口。所有业务功能(尚未)均可实现。
已完成的功能
- 登录
- 带有排序、偏移量和限制的基本产品列表
安装
- 使用 Composer 安装扩展包
composer.sh require kzorluoglu/rest-api-bundle:dev-master
- 在 app/AppKernel.php 中添加扩展包
new \kzorluoglu\RestApiBundle\kzorluogluRestApiBundle(),
- 在 app/autoload.php 中添加 AnnotationReader::addGlobalIgnoredNamespace("OA")
$loader = require __DIR__.'/../vendor/autoload.php';
// OA (open AI) Annotations adding Doctorine Ingored Namespaces List
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredNamespace("OA");
- 在 app/config/routing.yml 中添加 API 路由
api:
resource: "@kzorluogluRestApiBundle/Resources/config/routing.yml"
type: yaml
prefix: /api
API 端点文档
所有 URI 都相对于 https://demo.chameleon-system.de/
模型文档
测试
准备
cd /vendor/kzorluoglu/rest-api-bundle
composer install
并运行测试
./vendor/bin/phpunit -c phpunit.xml
开发
更改后创建新的 openapi yaml
./vendor/bin/openapi -o api.yml /your/root/path/vendor/kzorluoglu/rest-api-bundle/Controller
示例
./vendor/bin/openapi -o api.yml /usr/local/apache2/htdocs/customer/vendor/kzorluoglu/rest-api-bundle/Controller
- 检查 api.yml 是否存在
../customer
..../app
..../web
..../api.yml
- 预览;将 api.yml 文件的内容复制并粘贴到 https://editor.swagger.io
文档生成
预览
- 复制 api.yml 文件的内容
- 粘贴到 https://editor.swagger.io
替代方案 1
- 复制 api.yml 文件的内容并粘贴到 https://editor.swagger.io
- 点击 生成客户端
- 选择一种客户端软件语言
- 解压缩生成的 zip 文件
- 从 readme.md 中复制 "## API 端点文档" 部分
- 从 zip 文件中将 docs 文件夹复制到该扩展包中
替代方案 2
- 下载 https://github.com/swagger-api/swagger-ui - 相关文件夹为 "dist"
- 将您的 api YAML 复制到 dist 文件夹中
- 打开 index.html 并将文件底部标签中的 URL 的值更改为 ./swagger.json(或您的 swagger json 所叫的名称)
- 在线托管!(或启动本地服务器以查看输出)。