api-platform/postman-collection-generator

此包已被废弃,不再维护。作者建议使用api-platform/core包。

基于API Platform 1.*的Postman集合生成器

dev-master / 1.0.x-dev 2016-10-31 13:14 UTC

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文档中创建集合。

基于PostmanAPI Platform的集合生成器。

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight Dependency Status

安装

通过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中以环境变量的形式进行管理。

请随意添加您自己的验证器作为请求和命令解析器。