All Projects → cocoakekeyu → swaggerdoc

cocoakekeyu / swaggerdoc

Licence: other
一个简便的django app将swagger ui搬到项目中展示

Programming Languages

python
139335 projects - #7 most used programming language
HTML
75241 projects

Swaggerdoc

说明

这是一个简便的django app将swagger ui搬到项目中展示。开发人员只需将swagger文档放到项目指定目录,即可打开相应的URL查看swagger文档,非常适合使用Django开发的项目,在开发过程同时编写文档,并同步更新到项目中,团队其他人员也可以同时看到最新修改的文档。

用法

Django APP为swaggerdoc,像其他APP一样将该目录放到项目目录中。然后准备一些配置:

  1. 在项目setting中的INSTALLED_APPS列表写入'swaggerdoc', 主要便于Django自动查找'swaggerdoc'APP中的static和templates目录下面的文件。该APP没有models文件,如果不想写入INSTALLD_APPS,需要将静态文件目录包含swaggerdoc内的statictemplates目录。
  2. 在项目setting中设置DOC_DIR, 存放swagger文档的目录。也可以不设置,默认为项目目录下的docs文件夹。
  3. 设置STATICFIELS_DIRS,包含第2点的DOC_DIR。如设置为os.path.join(BASE_DIR, 'docs'),使得Django可以找到该目录下的swagger文档。
  4. 设置url patterns, 在项目的urls.py文件设置swagger文档访问路径,包含swaggerdoc.urls即可。如: url(r'^api/doc/', include('swaggerdoc.urls')

这样,启动项目服务器,即可打开浏览器访问{服务其地址}/api/doc就可以看到项目文档了。

效果图如下:

代码是一个完整的django工程,提供可运行的示例, 直接git clone试运行。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].