swagger的由來(lái)
- 隨著互聯(lián)網(wǎng)技術(shù)的發(fā)展,現(xiàn)在的網(wǎng)站架構(gòu)基本都由原來(lái)的后端渲染,變成了:前端渲染、先后端分離的形態(tài),而且前端技術(shù)和后端技術(shù)在各自的道路上越走越遠(yuǎn)。
- 前端和后端的唯一聯(lián)系,變成了API接口;API文檔變成了前后端開(kāi)發(fā)人員聯(lián)系的紐帶,變得越來(lái)越重要,swagger就是一款讓你更好的書(shū)寫(xiě)API文檔的框架。
同類技術(shù)
- confluence
- README.md
- rap——API文檔工具,阿里開(kāi)發(fā),rap2官網(wǎng)
- swagger——API文檔框架,swagger官網(wǎng)
swagger生態(tài)圖

20170827202033991.png
swagger UI
示例

整個(gè)頁(yè)面.png
展開(kāi)界面

展開(kāi)界面.png
swagger-editor
就是一個(gè)在線編輯文檔說(shuō)明文件(swagger.json或swagger.yaml文件)的工具,以方便生態(tài)中的其他小工具(swagger-ui)等使用。 左邊編輯,右邊立馬就顯示出編輯內(nèi)容來(lái)。

swagger-editor.jpg
使用方法
-
在pom中引入依賴
<dependency> <groupId>com.spring4all</groupId> <artifactId>swagger-spring-boot-starter</artifactId> <version>1.8.0.RELEASE</version> </dependency> 在應(yīng)用主類中增加@EnableSwagger2Doc注解
@SpringBootApplication
@EnableSwagger2Doc
public class Springboot2Swagger2Application {
public static void main(String[] args) {
SpringApplication.run(Springboot2Swagger2Application.class, args);
}
}
默認(rèn)情況下就能產(chǎn)生所有當(dāng)前SpringMVC加載的請(qǐng)求映射文檔
訪問(wèn)地址:http://localhost:8080/swagger-ui.html
-
參數(shù)配置示例
swagger.enabled=true swagger.title=spring-data-jpa module swagger.description=Starter for swagger 2.x swagger.license=Apache License, Version 2.0 swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter- swagger swagger.contact.name=RanRan Tao swagger.contact.url=http://www.itdecent.cn/u/822585e5c69a swagger.contact.email=16422802@qq.com swagger.base-package=com.example.springdatajpa.controller swagger.base-path=/** swagger.exclude-path=/error, /ops/**