Asked 3 months ago
Active 1 month ago
Viewed 286 times
0

I'm starting to study swagger. I'm trying to do the same which is done in book "Hands-On Full Stack Web Development with Angular 6 and Laravel 5". Using php-fpm bash after typing command "php artisan l5-swagger:generate" I have got this exception in VS Code terminal:

root@8e6435be9103:/application# php artisan l5-swagger:generate
Regenerating docs ErrorException : Required @OA\Info() not found
at /application/vendor/zircote/swagger-php/src/Logger.php:39
35| $this->log = function ($entry, $type) {
36| if ($entry instanceof Exception) {
37| $entry = $entry->getMessage();
> 39| trigger_error($entry, $type);
40| };
41| }
42|
43| /** Exception trace: 1 trigger_error("Required @OA\Info() not found")
/application/vendor/zircote/swagger-php/src/Logger.php:39 2 OpenApi\Logger::OpenApi\{closure}("Required @OA\Info() not found")
/application/vendor/zircote/swagger-php/src/Logger.php:71

And when I trying to open http://localhost:8081/api/documentation url it gives this error:

Failed to load API definition.
Fetch errorNot Found http://localhost:8081/docs/api-docs.json

I'am using php-fpm bash inside docker. My OS is Ubuntu 18.04.3 LTS.

Can anyone help me to fix this problem. Thank you!!!

asked Aug 25 at 10:18
armenarz

111 bronze badge
 
0

You have to put some annotations in your code before running php artisan l5-swagger:generate. First, go to app/Http/Controllers/Controller.php and add a phpdoc comment block as follow before the class declaration:

/**
* @OA\Info(title="My First API", version="0.1")
*/

This annotation by itself is sufficient to resolve the issue that you described, but if you execute php artisan l5-swagger:generate again you will see the following Exception:

 ErrorException  : Required @OA\PathItem() not found

  at /home/nathanael/dev/laravel-projects/laravel-swagger/vendor/zircote/swagger-php/src/Logger.php:39
35| $this->log = function ($entry, $type) {
36| if ($entry instanceof Exception) {
37| $entry = $entry->getMessage();
38| }
> 39| trigger_error($entry, $type);
40| };
41| }
42|
43| /** Exception trace: 1 trigger_error("Required @OA\PathItem() not found")
/home/nathanael/dev/laravel-projects/laravel-swagger/vendor/zircote/swagger-php/src/Logger.php:39 2 OpenApi\Logger::OpenApi\{closure}("Required @OA\PathItem() not found")
/home/nathanael/dev/laravel-projects/laravel-swagger/vendor/zircote/swagger-php/src/Logger.php:71 Please use the argument -v to see more details.

That's because you must have at least one method in a controller with an annotation that describes a route. You can easily create a resource in your application to test running php artisan make:controller ProjectsController -r and adding Route::resource('projects', 'ProjectsController') to routes/web.php. After creating the controller open it and add the following phpdoc comment block before the index method, for example:

/**
* @OA\Get(
* path="/projects",
* @OA\Response(response="200", description="Display a listing of projects.")
* )
*/

Then, run php artisan l5-swagger:generate again and you must see a success message in the terminal.

Can't generate API documentation in l5-swagger的更多相关文章

  1. L5 Swagger 使用说明

    网上看了看,关于这个扩展介绍很少.今天工作恰好用到,研究了一下,觉得有必要分享一下. 一.  简介: 这个包是Swagger-php和Swagger-ui的封装,适用于Laravel5. 二.版本要求 ...

  2. ASP.NET Web API Help Pages using Swagger

    Understanding the various methods of an API can be a challenge for a developer when building a consu ...

  3. API生命周期第三阶段:API实施:使用swagger codegen生成可部署工程,择取一个作为mock service

    在分享培训了swagger对于API的设计之后,有一些人问我说:你看,现在咱们前端使用web_API做为mock data在进行测试,后端也有mock 测试.然后我们再进行联调,这之中肯定会出现一些偏 ...

  4. 查看API工具 https://editor.swagger.io/

    The base URL for the API is:    https://api.cloud.nalantis.com/api/ The OpenAPI documentation is ava ...

  5. jQuery.mobile.changePage() | jQuery Mobile API Documentation

    jQuery.mobile.changePage() | jQuery Mobile API Documentation <script> $.mobile.changePage( &qu ...

  6. API文档工具-Swagger的集成

    最近安装了API文档工具swagger,因为Github上已有详细安装教程,且安装过程中没有碰到大的阻碍,所以此文仅对这次安装做一份大致记录 相关网站 Swagger 官方地址: http://swa ...

  7. Spring Data REST API集成Springfox、Swagger

    原文: Documenting a Spring Data REST API with Springfox and Swagger 使用Spring Date REST,你可以迅速为Spring Da ...

  8. web API help pages with Swagger / OpenAPI

    https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?view=aspnetc ...

  9. PhoneGap API Documentation API Reference

    API Reference-API参考 Accelerometer-加速度计 Tap into the device's motion sensor.-点击进入该设备的运动传感器. Camera-相机 ...

随机推荐

  1. 解决kali安装成功后没有声音的问题

    Kali Linux系统默认状态下,root用户是无法使用声卡的,也就没有声音.启用的方法如下: (1)在终端执行命令:systemctl --user enable pulseaudio (2)在/ ...

  2. [cf 1239 B] The World Is Just a Programming Task (Hard Version)

    题意: 给你一个长度为n的括号序列,你可以交换其中的两个元素,需要使该序列的n个循环移位中合法的括号序列个数尽量多. 输出最大的答案以及交换哪两个元素能够取到这个答案. $n\leq 3\times ...

  3. Huber Loss 介绍

    Huber Loss 是一个用于回归问题的带参损失函数, 优点是能增强平方误差损失函数(MSE, mean square error)对离群点的鲁棒性. 当预测偏差小于 δ 时,它采用平方误差,当预测 ...

  4. C# vb .net实现相机视图效果滤镜

    在.net中,如何简单快捷地实现Photoshop滤镜组中的相机视图效果呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第 ...

  5. vim打开多个文件、同时显示多个文件、在文件之间切换

    打开多个文件: 1.vim还没有启动的时候: 在终端里输入  vim file1 file2 ... filen便可以打开所有想要打开的文件 2.vim已经启动 输入 :open file 可以再打开 ...

  6. Java之路---Day05

    2019-10-19-21:09:31 面向对象的封装性 封装性 概念:封装就是将一些细节信息隐藏起来,对于外界不可见 面向对象封装性在Java中的体现 1.方法就是一种封装 public class ...

  7. 【转载】sqlserver中小数类型float和deciaml类型比较

    在sqlserver数据库中,float类型和double类型都可以用来表示小数类型,float类型是一种近似数值的小数类型,而decimal类型则是精确数值的小数类型.如果需要在sqlserver数 ...

  8. html解决空格显示问题

    在前端里面,大家都知道,html中输入空格或换行是识别不了是空格的,但是有时候需要实现,那么该如何解决呢?主要有以下几个方面: 1:常用的转义:  2:使用全角拼音,然后输入空格也可实现 3:用标签 ...

  9. Java 之 Response 对象

    Response 对象 一.Response 原理和继承结构 原理和继承结构参考 request. 二.Response 对象 Response 就是用来设置响应消息. 1.设置响应行   响应头格式 ...

  10. Android App 架构演变

    文:https://www.jianshu.com/p/ce26e7960926 最近App项目(MVC架构)越做越大,协同开发效率较低,维护困难,所以产生了调整架构的想法,在 简书.csdn.知乎上 ...