如何生成API文档

问题描述:

我需要为我创建的REST API编写一些API文档。是否有工具可以将样式与下划线api文档类似的不错的html输出存档?或者,也许会输出一些东西作为Twitter引导样式的HTML?如何生成API文档

我看到docco没有注释代码,但实际上我只是想要记录API。理想情况下,我想在控制器文件中指向一个工具,并让它生成有关方法和路由的文档,但不会显示任何源代码,除非我专门调用示例。

+0

我会找Express.js如何生成它的文档。它使用节点脚本,shell脚本和dox的组合。 – 2012-08-15 14:28:53

apiDoc在您的源代码中创建来自API注释的文档。

集成是一个API历史记录,可以比较各种API版本级别。 因此,它可以追溯自API上次版本以来更改的API。

演示:http://apidocjs.com/example

Github上:https://github.com/apidoc/apidoc

+0

请注意,这个库不再被主动维护。 – d4nyll 2017-10-18 15:59:56

查看Github上的I/O Docs - http://github.com/mashery/iodocs。它在Node.js中被黑客攻击,并且有很多社区贡献/参与。要看到它在野外工作:

尤伯杯简单的配置模式(JSON),和地狱,如果你不想用手工来形容这一切在JSON ,使用I/O医生,导入/ JSON建设与CONFIGS一个UI基于Web的工具:

在Github上也可在https://github.com/brandonmwest/iodoctor

让我知道如果我能帮助您开始。 I/O Docs回购中有很多示例配置。保重。

+1

有没有一种方法,您知道,从.NET WebAPI ApiExplorer生成Mashery I/O Docs(类似于Swagger的方式)? – 2014-02-10 17:52:16

+0

请更正答案中的链接。其中一些坏了。 – 2017-03-24 22:03:02

+0

请注意,该库不再被主动维护。 – d4nyll 2017-10-18 15:59:58

I/O Docs或Swagger,这是最流行的RESTful API文档系统。还有RAMLApiary

test2doc.js帮助你生成你的测试/规格API文档。因此,您始终可以获取最新的最新API文档,并填入真实的请求/响应数据。

测试的代码示例:

const doc = require('test2doc') 
const request = require('supertest') // We use supertest as the HTTP request library 
require('should') // and use should as the assertion library 

// For Koa, you should exports app.listen() or app.callback() in your app entry 
const app = require('./my-express-app.js') 

after(function() { 
    doc.emit('api-documentation.apib') 
}) 

doc.group('Products').is(doc => { 
    describe('#Products', function() { 
    doc.action('Get all products').is(doc => { 
     it('should get all products', function() { 
     // Write specs towards your API endpoint as you would normally do 
     // Just decorate with some utility methods 
     return request(app) 
      .get(doc.get('/products')) 
      .query(doc.query({ 
      minPrice: doc.val(10, 'Only products of which price >= this value should be returned') 
      })) 
      .expect(200) 
      .then(res => { 
      body = doc.resBody(res.body) 
      body.desc('List of all products') 
       .should.not.be.empty() 
      body[0].should.have.properties('id', 'name', 'price') 
      body[0].price.desc('Price of this product').should.be.a.Number 
      }) 
     }) 
    }) 
    }) 
})