首先声明下,apidoc是基于注释来生成文档的,它不基于任何框架,而且支持大多数编程语言,为了springboot系列的完整性,所以标了个题。

一、apidoc简介

apidoc通过在你代码的注释来生成api文档的。它对代码没有侵入性,只需要你写好相关的注释即可,并且它仅通过写简单的配置就可以生成高颜值的api接口页面。它基于Node.js,所以你需要安装node.js环境。node.js安装,点击这里。这里就不介绍。

二、准备工作

安装完node.js安装api.doc,它的项目源码:https://github.com/apidoc/apidoc

通过命令安装:

npm install apidoc -g

三、注释怎么写

  • @api
@api {method} path [title]

method:请求方法,
path:请求路径
title(可选):标题
  • @apiDescription
@apiDescription text
text说明
  • @apiError
@apiError [(group)] [{type}] field [description]

(group)(可选):参数将以这个名称分组,不设置的话,默认是Error 4xx
{type}(可选):返回值类型,例如:{Boolean}, {Number}, {String}, {Object}, {String[]}
field:返回值字段名称
descriptionoptional(可选):返回值字段说明
  • @apiGroup
@apiGroup name
name:组名称,也是导航的标题

更多注释,参见官方文档:http://apidocjs.com/#params

四、写给栗子

首先写配置文件

在项目的主目录新建一个apidoc.json文件:

{
"name": "example",
"version": "0.1.0",
"description": "A basic apiDoc example"
}

更多配置参考:http://apidocjs.com/#configuration

写个注释:

    /**
* @api {POST} /register 注册用户
* @apiGroup Users
* @apiVersion 0.0.1
* @apiDescription 用于注册用户
* @apiParam {String} account 用户账户名
* @apiParam {String} password 密码
* @apiParam {String} mobile 手机号
* @apiParam {int} vip = 0 是否注册Vip身份 0 普通用户 1 Vip用户
* @apiParam {String} [recommend] 邀请码
* @apiParamExample {json} 请求样例:
* ?account=sodlinken&password=11223344&mobile=13739554137&vip=0&recommend=
* @apiSuccess (200) {String} msg 信息
* @apiSuccess (200) {int} code 0 代表无错误 1代表有错误
* @apiSuccessExample {json} 返回样例:
* {"code":"0","msg":"注册成功"}
*/

用apidoc命令生成文档界面

先cd到工程的外层目录,并在外层目建个输出文档的目录,我建的是docapi。

输命令:

apidoc -i chapter4/ -o apidoc/

-i 输入目录 -o 输出目录

chapter4是我的工程名。

可以看到在apidoc目录生成了很多文件:

打开index.html,可以看到文档页面:

五、参考资料

apidoc

apidocjs.com

使用apidoc 生成Restful web Api文档

转自:http://blog.csdn.net/forezp/article/details/71023579

(转)SpringBoot非官方教程 | 第十二篇:springboot集成apidoc的更多相关文章

  1. SpringBoot非官方教程 | 第二十二篇: 创建含有多module的springboot工程

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springbot22-modules/ 本文出自方志朋的博客 这篇文 ...

  2. SpringBoot非官方教程 | 第十二篇:springboot集成apidoc

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot-apidoc/ 本文出自方志朋的博客 首先声明下 ...

  3. (转) SpringBoot非官方教程 | 第二十四篇: springboot整合docker

    这篇文篇介绍,怎么为 springboot程序构建一个Docker镜像.docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源.Docker 可以让开发者打包他们的 ...

  4. SpringBoot非官方教程 | 第二十六篇: sprinboot整合elk,搭建实时日志平台

    转载请标明出处: 原文首发于https://www.fangzhipeng.com/springboot/2017/07/11/sprinboot25-elk/ 本文出自方志朋的博客 这篇文章主要介绍 ...

  5. SpringBoot非官方教程 | 第二十四篇: springboot整合docker

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot24-docker/ 本文出自方志朋的博客 这篇文 ...

  6. SpringBoot非官方教程 | 第二十五篇:2小时学会springboot

    转载请标明出处: http://blog.csdn.net/forezp/article/details/61472783 本文出自方志朋的博客 一.什么是spring boot Takes an o ...

  7. SpringBoot非官方教程 | 第十九篇: 验证表单信息

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot19/ 本文出自方志朋的博客 这篇文篇主要简述如何 ...

  8. SpringBoot非官方教程 | 第十八篇: 定时任务(Scheduling Tasks)

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot18-scheduling/ 本文出自方志朋的博客 ...

  9. SpringBoot非官方教程 | 第十六篇:用restTemplate消费服务

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot11-restTemplate/ 本文出自方志朋的 ...

随机推荐

  1. WPF 自定义命令 以及 命令的启用与禁用

    自定义命令:     在WPF中有5个命令类(ApplicationCommands.NavigationCommands.EditingCommands.ComponentCommands 以及 M ...

  2. POJ 1742 Coins(多重背包, 单调队列)

    Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...

  3. eclipse、tomca和jvm的相关内存配置

    1,  设置Eclipse内存使用情况        修改eclipse根目录下的eclipse.ini文件        -vmargs  //虚拟机设置        -Xms40m        ...

  4. 安装autoit libary失败问题解决

    运行环境:win7-32,python2.7安装遇到的问题:

  5. jq如何实现内容的无限滚动

    html: <div> <ul> <li>1</li> <li>2</li> <li>3</li> &l ...

  6. php学习二:表达式

    1.  可变变量$$ 在php中,可变变量可以用$$来表示, 代码如下: $name = "zhangSan"; $$name = "liSi"; //相当于$ ...

  7. AS3在函数内部移除监听(arguments.callee)

    scene.addEventListener(Event.ADDED_TO_STAGE, function():void { scene.removeEventListener(Event.ADDED ...

  8. AndroidStudio build.gradle 报错

    Android Studio. I'm getting this kind of error during application run. Error:Execution failed for ta ...

  9. @Apiimplicitparam的paramType

    转自:https://swagger.io/docs/specification/describing-parameters/ Parameter Types OpenAPI 3.0 distingu ...

  10. 【MySQL案例】error.log的Warning:If a crash happens thisconfiguration does not guarantee that the relay lo(转)

    标签: 1.1.1. If a crash happens thisconfiguration does not guarantee that the relay log info will be c ...