在老大的指引下,需要将系统的json文件格式转换成apidoc的json格式,也就是json格式的重组,但是这个apidoc的生成格式是不固定的,因为apidoc有自己一套的生成规则,我需要研究一下是怎么生成的。

一、官方基础栗子

二、理解apidoc生成静态文档的结构解读

三、深入理解一下apidoc生成原理以及规则

一、apidoc基础栗子

全局安装apidoc

npm install apidoc -g

1、首先建立文件目录

2、需要你在input文件夹里面写上你的js部分

这个是栗子的js部分。

/**
@api {get} /user/:id Request User information
@apiName GetUser
@apiGroup User @apiParam {Number} id Users unique ID. @apiSuccess {String} firstname Firstname of the User.
@apiSuccess {String} lastname Lastname of the User.
*/ /**
@api {post} /user/:id Create User information
@apiName CreateUser
@apiGroup User @apiParam {Number} id Users unique ID. @apiSuccess {String} data
@apiSuccess {String} data.firstname Firstname of the User.
@apiSuccess {String} data.first.lastname Lastname of the User. @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "firstname": "John",
* "lastname": "Doe"
* }
*/

3、新建apidoc.json文件

apidoc.json栗子

{
"name": "example",
"version": "0.1.0",
"description": "apiDoc basic example",
"title": "Custom apiDoc browser title",
"url" : "https://api.github.com/v1"
}

 

4、在myapp文件夹下面运行

apidoc -i myapp/ -o apidoc/ -t mytemplate/

官网原文:Creates an apiDoc of all files within dir myapp/, uses template from dir mytemplate/ and put all output to dir apidoc/.

-i  是输入文件的路径 ,  -o 是输出文件的路径,   -t是使用模板的路径(可缺省)

打开output文件夹,发现生成一个apidoc在线文档,直接打开html就可以看到

打开html文件

二、理解apidoc生成静态文档的结构解读

一个静态的文档很漂亮的生成了,但是实际控制这个现实的是api_data.js和api_project.js。但是实际上的数据显示是由api_data.json和api_project.json这两个json文件。

所以在支持将其他json格式转换成api_data.json和api_project.json,把apidoc生成的这两个文件进行替换,然后替换js文件,直接生产静态文档。

可以看一下api_data.json格式

对比一下api_data.js格式

很明显就能看出来,就是在api_data.json的基础上,封装成了一层,加上define({ "api": api_data.json});

api_project.json和api_project.js也是使用相同的方法封装的。

三、深入理解一下apidoc生成原理以及规则

apidoc设计到如下的参数

(1)第一个是@api

@api是必须的,

@api {method} path [title]

比如

method    包括请求的方式:get,post,put,delete,等

path  表示请求的路径。

title  (可选项)表示分组的解释,导航。

对应的静态页面

(2)@apiDefine

@apiDefine name [title] [description]

表示的是:嵌入在api块或api中的文档块

没有找到对应的页面

(3)@apiDeprecated

@apiDeprecated [text]

标志位api方法的反对(不对)的地方。

(4)@apiDescription

表示的是描述。

@apiDescription text

页面上显示的是:

(5)@apiError和@apiErrorExample

表示的错误返回的参数

@apiError [(group)] [{type}] field [description]

页面的显示:

(6)@apiGroup

这个是必填项,表示的分组。

页面显示的是:

(7)@apiHeader

表示的是:传递给API头部的参数

@apiHeader [(group)] {type} [field=defaultValue] [description]

发现:@apiHeader与@apiParam用法显示上很像,但是在生成的api_data.json所在的树形结构不一致。

,上面的红框是@apiHeader生成的,下面的红框是@apiParam生成的。

(8)@apiParam

表示的:传递给API方法的参数

页面显示的是:

(9)@apiParamExample

表示的是:参数实例

页面上的显示:

 (10)@apiSuccess和@apiSuccessExample

表示的是:成功返回的参数。

页面上的显示:

目前主要用到了这10多个参数,还是够完成老大要求的任务。

apidoc的输入的js文件

/**
* @api {get} /user/:id Read data of a User
* @apiVersion 0.3.0
* @apiName GetUser
* @apiGroup User
* @apiDeprecated use now (#Group:Name)
*
* @apiDescription Compare Verison 0.3.0 with 0.2.0 and you will see the green markers with new items in version 0.3.0 and red markers with removed items since 0.2.0.
*
* @apiHeader (User) {String} [field=1111] ceshi
* @apiParam (header) {String} [hhhhh=aaa] The Users-ID.
* @apiParam (query) {Number} [X=1001] Users unique key.
* @apiParam (query) {Number} [Y=join] Users unique value.
* @apiParam (rest) {Object} a Users unique ID.
* @apiParam (rest) {String} a.b=hello Users unique ID.
* @apiParam (body) {Object} a Users unique ID.
* @apiParam (body) {String} a.b=hello Users unique ID.
* @apiParam (body) {String} a.b.c=world Users unique ID.
* @apiParam (body) {String} a.c=ccccc Users unique ID.
* @apiParamExample {json} Request-Example:
* {
* "id": 4711
* }
*
* @apiSuccess {String} id The Users-ID.
* @apiSuccess {String} registered Registration String.
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "firstname": "John",
* "lastname": "Doe"
* }
*
* @apiError NoAccessRight Only authenticated Admins can access the data.
* @apiError UserNotFound The <code>id</code> of the User was not found.
*
* @apiErrorExample Response (example):
* HTTP/1.1 401 Not Authenticated
* {
* "error": "NoAccessRight"
* }
*/ /**
* @api {post} /user Create a new User
* @apiVersion 0.3.0
* @apiName PostUser
* @apiGroup User
*
* @apiDescription In this case "apiUse" is defined and used.
* Define blocks with params that will be used in several functions, so you dont have to rewrite them.
*
* @apiParam {String} name Name of the User.
*
* @apiSuccess {String} id The new Users-ID.
*
* @apiUse CreateUserError
*/ /**
* @api {put} /user/:id Change a new User
* @apiVersion 0.3.0
* @apiName PutUser
* @apiGroup User
*
* @apiDescription This function has same errors like POST /user, but errors not defined again, they were included with "apiUse"
*
* @apiParam {String} name Name of the User.
*
* @apiUse CreateUserError
*/

apidoc.json文件

{
"name": "apidoc-example",
"version": "0.3.0",
"description": "apiDoc example project",
"title": "Custom apiDoc browser title",
"url" : "https://api.github.com/v1", "order": [
"GetUser",
"PostUser"
],
"template": {
"withCompare": true,
"withGenerator": true
}
}

apidoc快速生成在线文档,apidoc生成静态文件的生成规则以及原理分析的更多相关文章

  1. asp.net webapi 生成在线文档--Swagger

    第一步:使用nuget包获取Swashbule.swagger.net.ui的包并安装. 安装成功后 打开App_Start->SwaggerNet.cs 注释掉一下两行 //[assembly ...

  2. 第二十节:Asp.Net Core WebApi生成在线文档

    一. 基本概念 1.背景 使用 Web API 时,了解其各种方法对开发人员来说可能是一项挑战. Swagger 也称为OpenAPI,解决了为 Web API 生成有用文档和帮助页的问题. 它具有诸 ...

  3. C#生成PDF文档,读取TXT文件内容

    using System.IO;using iTextSharp.text;using iTextSharp.text.pdf; //需要在项目里引用ICSharpCode.SharpZipLib.d ...

  4. 使用apidocJs快速生成在线文档

    https://blog.csdn.net/xialei199023/article/details/63251482 https://blog.csdn.net/qq_16142851/articl ...

  5. (转)WebApi自动生成在线文档Swashbuckle

    原文地址:http://www.cnblogs.com/Arrays/p/5146194.html?utm_source=tuicool&utm_medium=referral 1.前言 1. ...

  6. (转)WebApi自动生成在线文档WebApiTestClient

    原文链接:http://www.cnblogs.com/landeanfen/p/5210356.html 前言:这两天在整WebApi的服务,由于调用方是Android客户端,Android开发人员 ...

  7. 求你别再用swagger了,给你推荐几个在线文档生成神器

    前言 最近公司打算做一个openapi开放平台,让我找一款好用的在线文档生成工具,具体要求如下: 必须是开源的 能够实时生成在线文档 支持全文搜索 支持在线调试功能 界面优美 说实话,这个需求看起来简 ...

  8. 基于数据库的自动化生成工具,自动生成JavaBean、自动生成数据库文档等(v4.1.2版)

            目录:            第1版:http://blog.csdn.net/vipbooks/article/details/51912143            第2版:htt ...

  9. flask + apidoc 生成接口文档(附加一个坑)

    具体使用方法见这里 https://blog.csdn.net/lynnyq/article/details/79254290 挺详细的,我就不抄了. 重点是一个坑: 执行 python manage ...

随机推荐

  1. google C++编程风格指南之头文件的包括顺序

    google C++编程风格对头文件的包括顺序作出例如以下指示: (1)为了加强可读性和避免隐含依赖,应使用以下的顺序:C标准库.C++标准库.其他库的头文件.你自己project的头文件.只是这里最 ...

  2. Linux已经全然统治了这个世界:反对开源社区愚不可及

    原文来自:http://readwrite.jp/archives/9977 不管一个企业多强大,它都不存在和开源社区抗衡的实力 十年前.Unix占有最快的计算机世界排名前10位的五席,以及超级计算机 ...

  3. CUDA编程(六)进一步并行

    CUDA编程(六) 进一步并行 在之前我们使用Thread完毕了简单的并行加速,尽管我们的程序运行速度有了50甚至上百倍的提升,可是依据内存带宽来评估的话我们的程序还远远不够.在上一篇博客中给大家介绍 ...

  4. Android仿微信朋友圈图片浏览器(支持图片手势缩放,拖动)

    ※效果 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGluZ2xvbmd4aW4yNA==/font/5a6L5L2T/fontsize/400/fil ...

  5. [Sqoop]利用sqoop对mysql运行DML操作

    业务背景 利用sqoop对mysql进行查询.加入.删除等操作. 业务实现 select操作: sqoop eval \ --connect jdbc:mysql://127.0.0.1:3306/m ...

  6. Python3.x和Python2.x的区别【转】

    转载自:https://www.cnblogs.com/codingmylife/archive/2010/06/06/1752807.html 1.性能 Py3.0运行 pystone benchm ...

  7. POST/有道翻译 有bug

    1.发现在翻译时地址没有变,那是POST请求. 2.通过fidder抓包工具抓取url 3.对data分析,发现每次salt和sign都在变化. 4.查看源码,先用站长工具http://tool.ch ...

  8. 《软件测试的艺术(原书第2版)》【PDF】下载

    <软件测试的艺术(原书第2版)>[PDF]下载链接: https://u253469.ctfile.com/fs/253469-231196343 内容简介 本书以一次自评价测试开篇,从软 ...

  9. 小白的Python之路 day1 数据类型,数据运算

    一.数据类型初识 1.数字 2 是一个整数的例子.长整数 不过是大一些的整数.3.23和52.3E-4是浮点数的例子.E标记表示10的幂.在这里,52.3E-4表示52.3 * 10-4.(-5+4j ...

  10. arcgis api for js热力图优化篇-不依赖地图服务

    前面我写过一篇文章,介绍如何实现arcgis api的热力图效果,但是依赖arcgis server发布的地图服务来获取热力图的数据源.实际应用中,很多业务数据来源数据库,并不一定是从地图服务来获取的 ...