api-platform / postman-collection-generator
Requires
- php: >=5.5
- api-platform/core: ~1.1@beta
- doctrine/inflector: ^1.1
- fzaninotto/faker: ^1.6
- ramsey/uuid: ^3.2
- symfony/config: ^2.3|^3.0
- symfony/console: ^2.3|^3.0
- 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 not auto-updated.
Last update: 2022-02-01 12:56:16 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
获取更多详细信息。
使用解析器
此库提供了一个简单的方式来扩展它,称为parsers
。有2个:请求解析器和命令解析器。
请求解析器
请求解析器是执行以编辑在发送到集合之前Postman请求的服务。例如,可以添加自定义认证头,添加一些测试等。
要创建自己的请求解析器,你的服务必须实现PostmanGeneratorBundle\RequestParser\RequestParserInterface
,并具有标签postman.request_parser
。
注意:一些请求解析器可能会在您的之前执行。请检查Symfony依赖注入中的priority
处理。
命令解析器
命令解析器是执行以连接到主命令的服务,例如请求认证访问。
要创建自己的命令解析器,你的服务必须实现PostmanGeneratorBundle\CommandParser\CommandParserInterface
,并具有标签postman.command_parser
。`parse`方法允许您向用户提问,而`execute`方法可以执行您的操作。
注意:一些命令解析器可能会在您的之前执行。请检查Symfony依赖注入中的priority
处理。
认证
默认情况下,该库可以管理OAuth2身份验证。要使用它,请使用oauth2
填充authentication
配置键。当使用主命令时,您将需要输入用户名和密码。它们将在Postman中以环境变量的形式进行管理。
请随意添加您自己的验证器作为请求和命令解析器。