使用Swagger的原因:
前后端调用接口过程中,存在接口文档与实际情况不一致的问题。且强制规范随着版本迭代接口文档也很难再跟上代码的变化。
Swagger是什么?
通过规范和Swagger衍生出来的一系列项目和工具,生成各种格式的接口文档,生成过重语言的客户端和服务端代码,以及在线接口调试页面等等,能够做到调用端代码、服务端代码以及接口文档的一致性。
需要编写yml或json格式的描述文档。在通过维护这个描述文件去更新接口文档,以及生成各端代码。
Spring-Swagger项目到Springfox
通过在项目中引入Springfox,可以扫描相关的代码,生成该描述文件,进而生成与代码一直的接口文档和客户端代码。在后面需求持续迭代的项目中,显得尤为重要。
做到了代码即接口文档,接口文档即代码。
【参考文件】
1.Swagger介绍及使用 https://www.cnblogs.com/sea520/p/13195439.html.