在阅读了Stackoverflow上的这两篇文章后:如何解决错误异常:未找到必需的@OA\PathItem((可以';t在l5-货车中生成API文档
在运行php artisan l5 swagger:generate之后,我仍然得到一个错误Required @OAPathItem() not found
。
这是我的Controller.php部分:
/**
* @OAInfo(
* title="My First API Documentation",
* version="0.1",
* @OAContact(
* email="info@yeagger.com"
* ),
* ),
* @OAServer(
* description="Learning env",
* url="https://foo.localhost:8000/api/"
* ),
*/
class Controller extends BaseController
{
这是我的ProfileController部分:
/**
* @OAGet(
* path="/profiles",
* @OAResponse(
* response=200,
* description="Successful operation",
* ),
* @OAPathItem (
* ),
* )
*/
function index()
{
return new ProfileCollection(Profile::with('user')->paginate());
}
我在这里俯瞰什么?如果有人能解释并提供帮助,那就太好了:(
编辑-解决方案
出现这个问题是因为我使用的是laravel模块包,我不得不更改l5-swaker.php配置文件中的一些代码:
'annotations' => [
base_path('Modules/Api/Http'), <-- changed the base path to the correct module
],
然后,我将主Controller.php从App/Http/Controllers复制到同一个模块,以消除之后出现的@OAInfo() not found
错误。
当我第一次安装和配置时,我也遇到了同样的错误。事实证明,仅仅@OA\Info是不足以生成文档的。除此之外,它还需要至少一个路径条目。在添加了api端点注释后,它得到了修复。
示例:
/**
* @OAGet(
* path="/api/users",
* @OAResponse(response="200", description="An example endpoint")
* )
*/
public function getUsers() {
...
}
根据迁移文档,您需要导入Annotations类use OpenApiAnnotations as OA;
来解决问题。
/**
* Remove the specified resource from storage.
*
* @return IlluminateHttpJsonResponse
*/
如果在我的index((函数上方有这些代码,应该立即删除它。这就是为什么我得到这个错误