Can't generate API documentation in l5-swagger
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!!!
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的更多相关文章
- L5 Swagger 使用说明
网上看了看,关于这个扩展介绍很少.今天工作恰好用到,研究了一下,觉得有必要分享一下. 一. 简介: 这个包是Swagger-php和Swagger-ui的封装,适用于Laravel5. 二.版本要求 ...
- 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 ...
- API生命周期第三阶段:API实施:使用swagger codegen生成可部署工程,择取一个作为mock service
在分享培训了swagger对于API的设计之后,有一些人问我说:你看,现在咱们前端使用web_API做为mock data在进行测试,后端也有mock 测试.然后我们再进行联调,这之中肯定会出现一些偏 ...
- 查看API工具 https://editor.swagger.io/
The base URL for the API is: https://api.cloud.nalantis.com/api/ The OpenAPI documentation is ava ...
- jQuery.mobile.changePage() | jQuery Mobile API Documentation
jQuery.mobile.changePage() | jQuery Mobile API Documentation <script> $.mobile.changePage( &qu ...
- API文档工具-Swagger的集成
最近安装了API文档工具swagger,因为Github上已有详细安装教程,且安装过程中没有碰到大的阻碍,所以此文仅对这次安装做一份大致记录 相关网站 Swagger 官方地址: http://swa ...
- Spring Data REST API集成Springfox、Swagger
原文: Documenting a Spring Data REST API with Springfox and Swagger 使用Spring Date REST,你可以迅速为Spring Da ...
- web API help pages with Swagger / OpenAPI
https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?view=aspnetc ...
- PhoneGap API Documentation API Reference
API Reference-API参考 Accelerometer-加速度计 Tap into the device's motion sensor.-点击进入该设备的运动传感器. Camera-相机 ...
随机推荐
- centos设置IP
centos设置IP 原由:虚拟机里安装了很多软件,每天要使用,原来使用的动态IP,而且很长时间也没变,一直使用的很好,忽然一天访问不了了,找了几次才发现动态IP地址变了,这些后决定将虚拟机的IP地址 ...
- SQL Server——死锁查看
一.通过语句查看 --查询哪些死锁SELECT request_session_id spid, OBJECT_NAME( resource_associated_entity_id ) tableN ...
- selenium中元素操作之简单的鼠标、键盘操作(三)
1.鼠标操作导入类:ActionChains --鼠标的操作形成一连串的动作链,由selenium的ActionChains类来完成模拟鼠标操作手表操作的过程:1.鼠标的操作,先放到一个列表中2.利用 ...
- Windows下使用MongoDb的经验
随着NoSql广泛应用MongoDb这个Json数据库现在也被广泛使用,接下来简单介绍一下Windows下如使安装使用MongoDb. 一.安装MongoDb 1.首先去官方网址:(https://w ...
- el-select和el-cascader的visible-change下拉框隐藏时触发相关事件(下拉框下拉显示时不触发)
原文:https://blog.csdn.net/CarryBest/article/details/79959389 今天做项目时,用elementUI框架,需要下拉框隐藏时出发某个函数,用了vis ...
- 如何删除mysql注释
Linux命令删除注释 先把库表导出成一个.sql文件,然后使用sed命令删除注释.此种适用于mysql端口不开外网的情况. $ cat create_table.sql create table t ...
- 【开发笔记】- Java写入、读取文本
文本写入 public static void createFile(String input) throws IOException { //设置文件路径 String filePath = &qu ...
- Flask蓝图Blueprint和特殊装饰器
Flask 中的 蓝图 Blueprint 不能被run的flask实例:相当于django中的app01 应用 蓝图作用:功能隔离 路由隔离 Blueprint就是 一个不能run的flask 蓝图 ...
- vue设置多个入口
做VUE项目时,有时想做多个入口来解决某些问题. 在根目录下的复制一份index.html,名称随便你命名,当然,你也可以都是放到一个文件夹下,我的就叫index1.html 然后在App.vue也复 ...
- C语言判断字符串是否是 hex string的代码
把写内容过程中经常用到的一些内容段备份一下,如下内容内容是关于C语言判断字符串是否是 hex string的内容. { static unsigned int hex2bin[256]={0}; me ...