michelmelo / postman-collection-generator
基于API Platform 1.*的Postman集合生成器
Requires
- php: >=5.5
- api-platform/core: v2.0.3
- doctrine/inflector: ^2.0
- fzaninotto/faker: ^1.6
- ramsey/uuid: ^4.0
- symfony/config: ^2.3|^3.0
- symfony/console: ^2.3|^3.0|^5.1
- symfony/dependency-injection: ^2.3|^3.0
Requires (Dev)
- behat/behat: ~3.0
- behat/mink: ~1.5
- behat/mink-browserkit-driver: ~1.1
- behat/mink-extension: ~2.0
- behat/symfony2-extension: ~2.0
- behatch/contexts: ~2.3
- phpunit/phpunit: <5.0
This package is auto-updated.
Last update: 2024-09-14 22:08:46 UTC
README
如果您使用API Platform 2.0或更高版本,则不再需要此包。 API Platform现在原生支持Swagger,Postman可以创建来自Swagger文档的集合。
基于Postman的集合生成器,基于API Platform。
安装
通过Composer安装此包
composer require --dev api-platform/postman-collection-generator
使用Symfony,更新您的AppKernel.php
文件
public function registerBundles() { ... if ($this->getEnvironment() != 'prod') { ... $bundles[] = new PostmanGeneratorBundle\PostmanGeneratorBundle(); } }
配置
此库需要一些配置。按照以下方式编辑您的app/config_dev.yml
文件
postman_generator: name: Name of your API # Required description: Description of your API # Optional, default: null baseUrl: http://www.example.com # Required public: false # Optional, default: false authentication: oauth2 # Optional, default: null defaultLocale: fr_FR # Optional, default: en_GB
用法
此包提供了一条独特的命令,可以自动根据您的API Platform项目配置生成Postman集合。运行php app/console postman:collection:build --help
获取更多详细信息。
使用解析器
此库提供了一个简单的方式来扩展它,称为解析器
。有两种类型:请求解析器和命令解析器。
请求解析器
请求解析器是执行以编辑Postman请求的服务,在将其发送到集合之前。例如,您可以添加自定义认证头,添加一些测试等。
要创建自己的请求解析器,您的服务必须实现PostmanGeneratorBundle\RequestParser\RequestParserInterface
,并具有标签postman.request_parser
。
注意:某些请求解析器可能在您的解析器之前执行。请检查Symfony依赖注入中的priority
过程。
命令解析器
命令解析器是执行以连接到主命令的服务,例如请求认证访问。
要创建自己的命令解析器,您的服务必须实现PostmanGeneratorBundle\CommandParser\CommandParserInterface
,并具有标签postman.command_parser
。parse
方法允许您向用户提问,execute
方法允许您执行操作。
注意:某些命令解析器可能在您的解析器之前执行。请检查Symfony依赖注入中的priority
过程。
认证
默认情况下,此库可以管理OAuth2认证。要使用它,使用oauth2
填充authentication
配置键。当使用主命令时,您将需要输入用户名和密码。它们将在Postman中作为环境变量管理。
您可以根据需要添加自己的认证器作为请求和命令解析器。