【发布时间】:2021-11-15 12:09:34
【问题描述】:
背景:我已经安装了 composer install zircote/swagger-php 并使用 apt-get 安装了 openapi-generator-cli。
我不确定我是否正在尝试正确使用这些工具,但是我一直无法找到指向我任何方向的文档。
我有一个控制器文件,里面有一大堆代码。我想测试是否可以使用 open api 注释从中生成 json 文件。
这是我的代码示例(我已经删除了不相关的部分):
<?php
/**
* @OA\Info(title="My First API", version="0.1")
*/
class Apiv1_LocationController extends App_Controller_API
{
/* Publicly exposed attributes and the field type for filtering */
protected $_exported = array('id','created','modified','name','address','phone','external_id','postcode','country','timezone','date_format','lacps','staff_count');
protected $_schematypes = array(
'string' => ['name','address','phone','external_id','postcode','country','timezone','date_format'],
'int' => ['id','staff_count'],
'timestamp' => ['created','modified'],
'complex'=> ['lacps'],
);
{more unrelated code...}
/**
* @OA\Get(
* path="/api/resource.json",
* @OA\Response(response="200", description="An example resource")
* )
*/
public function getAction()
{
{code inside action...}
}
}
我使用的cli命令:
openapi-generator-cli generate -g php -i <path_to_LocationController>
我收到以下错误:
[main] INFO o.o.c.ignore.CodegenIgnoreProcessor - No .openapi-generator-ignore file found.
Exception in thread "main" java.lang.RuntimeException: Issues with the OpenAPI input. Possible causes: invalid/missing spec, malformed JSON/YAML files, etc.
这让我相信我错误地使用了 openapi-generator-cli 工具,因为我不希望需要 JSON 或 YAML 文件,我正在尝试生成该文件。
我会继续努力,但如果有人能帮助我意识到我做错了什么或我对工具的误解,我将不胜感激。
【问题讨论】:
标签: php swagger openapi openapi-generator swagger-php