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. js中常用的获得日期对象的方法

    // 默认是当前时区的日期和时间 var date = new Date(); // 获取特定日期和时间的日期对象,需要传递毫秒数,不过可以传递规范日期格式字符串来代替 // 一些常见的日期格式 // ...

  2. vue3 createComponent

    这个函数不是必须的,除非你想要完美结合 TypeScript 提供的类型推断来进行项目的开发. 这个函数仅仅提供了类型推断,方便在结合 TypeScript 书写代码时,能为 setup() 中的 p ...

  3. Spring Boot 优雅的配置拦截器方式

    https://my.oschina.net/bianxin/blog/2876640 https://cs.xieyonghui.com/java/55.html 其实spring boot拦截器的 ...

  4. idea使用git进行项目管理

    第一部分: 安装 1. 下载地址:  https://git-scm.com/download/win; 如果速度慢, 使用 迅雷下载; 2. 点击安装, 然后下一步, 直到下面这个页面: 建议: 按 ...

  5. C++字符串相互转换

    转自cs_wu原文 C++ char*,const char*,string的相互转换 1. string转const char* string s ="abc"; const c ...

  6. Java中强大的format

    Java中强大的format Java中允许我们对指定的对象进行某种格式化,从而得到我们想要的格式化样式. Format 首先介绍java.text包中的Format Foramt是一个抽象基类,其具 ...

  7. csdn 分享私藏的18个黑科技网站,想找什么软件就找什么软件!!!

    https://blog.csdn.net/sinat_33921105/article/details/103307419 1.NO.1–胡萝卜周 http://www.carrotchou.blo ...

  8. vue学习(1) vue-cli 项目搭建

    vue学习(1)  vue-cli 项目搭建 一.windows环境 1. 下载node.js安装包 官网:https://nodejs.org/en/download/ 选择LTS下载 2. 安装 ...

  9. javascript中attribute和property的区别详解

    DOM元素的attribute和property很容易混倄在一起,分不清楚,两者是不同的东西,但是两者又联系紧密.很多新手朋友,也包括以前的我,经常会搞不清楚. attribute翻译成中文术语为“特 ...

  10. MongoDB 基本概念

    MongoDB和关系型数据库的对应关系 关系数据库 MongoDB 数据库   database 数据库   database 表格  table 集合  collection 行  row 文档  ...