在这里阅读了这2篇关于Stackoverflow的文章之后:如何解决ErrorException : Required @OA\PathItem()未找到 无法在l5-swagger中生成API文档
在运行php l5-swagger:Required @OA\PathItem() not found后,我仍然会得到一个错误。
这是我的Controller.php部分:
/**
* @OA\Info(
* title="My First API Documentation",
* version="0.1",
* @OA\Contact(
* email="info@yeagger.com"
* ),
* ),
* @OA\Server(
* description="Learning env",
* url="https://foo.localhost:8000/api/"
* ),
*/
class Controller extends BaseController
{这是我的ProfileController部分:
/**
* @OA\Get(
* path="/profiles",
* @OA\Response(
* response=200,
* description="Successful operation",
* ),
* @OA\PathItem (
* ),
* )
*/
function index()
{
return new ProfileCollection(Profile::with('user')->paginate());
}我在看什么?如果有人能解释并提供帮助,那就太好了:)
编辑-解决方案
之所以出现这个问题,是因为我使用的是一个laravel模块包,我不得不更改l5-swagger.php配置文件中的一些代码:
'annotations' => [
base_path('Modules/Api/Http'), <-- changed the base path to the correct module
],然后,我将主Controller.php从App/Http/Controller复制到相同的模块中,以消除之后出现的@OA\Info() not found错误。
发布于 2022-08-26 19:07:01
当我第一次安装和配置时,我也发生了同样的错误。原来,仅仅@OA\Info还不足以生成文档。除此之外,它至少需要一个路径条目。在添加了api端点注释之后,它得到了修复。
示例:
/**
* @OA\Get(
* path="/api/users",
* @OA\Response(response="200", description="An example endpoint")
* )
*/
public function getUsers() {
...
}发布于 2022-03-24 07:10:00
根据迁移文件,您需要导入批注类use OpenApi\Annotations as OA;来解决您的问题。
https://stackoverflow.com/questions/71323595
复制相似问题