michelmelo/postman-collection-generator

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

dev-master / 1.0.x-dev 2021-07-14 14:59 UTC

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

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获取更多详细信息。

使用解析器

此库提供了一个简单的方式来扩展它,称为解析器。有两种类型:请求解析器和命令解析器。

请求解析器

请求解析器是执行以编辑Postman请求的服务,在将其发送到集合之前。例如,您可以添加自定义认证头,添加一些测试等。

要创建自己的请求解析器,您的服务必须实现PostmanGeneratorBundle\RequestParser\RequestParserInterface,并具有标签postman.request_parser

注意:某些请求解析器可能在您的解析器之前执行。请检查Symfony依赖注入中的priority过程。

命令解析器

命令解析器是执行以连接到主命令的服务,例如请求认证访问。

要创建自己的命令解析器,您的服务必须实现PostmanGeneratorBundle\CommandParser\CommandParserInterface,并具有标签postman.command_parserparse方法允许您向用户提问,execute方法允许您执行操作。

注意:某些命令解析器可能在您的解析器之前执行。请检查Symfony依赖注入中的priority过程。

认证

默认情况下,此库可以管理OAuth2认证。要使用它,使用oauth2填充authentication配置键。当使用主命令时,您将需要输入用户名和密码。它们将在Postman中作为环境变量管理。

您可以根据需要添加自己的认证器作为请求和命令解析器。