Spring Boot 入门(七)生成接口契约

我这里使用的是smart-doc

官网地址:https://smart-doc-group.github.io/#/zh-cn/?id=smart-doc

  • 在项目中创建/src/main/resources/smart-doc.json
{
  "outPath": "./src/main/resources/static/contract",
  "allInOne": true,  //是否将文档合并到一个文件中,一般推荐为true
  "createDebugPage": true //@since 2.0.0 smart-doc支持创建可以测试的html页面,仅在AllInOne模式中起作用。
}

  •  把smart-doc插件相关配置放到启动模块的pom中
<plugin>
    <groupId>com.github.shalousun</groupId>
    <artifactId>smart-doc-maven-plugin</artifactId>
    <version>2.2.7</version>
    <configuration>
        <!--指定生成文档的使用的配置文件,配置文件放在自己的项目中-->
        <configFile>./src/main/resources/smart-doc.json</configFile>
        <!--指定项目名称-->
        <projectName>测试</projectName>
    </configuration>
    <executions>
        <execution>
            <goals>
                <!--smart-doc提供了html、openapi、markdown等goal,可按需配置-->
                <goal>html</goal>
            </goals>
        </execution>
    </executions>
</plugin>
  • 运行“smart-doc:html”,生成文件

  •  预览契约文件

地址:http://localhost:8080/contract/debug-all.html#_HelloWorld

posted @ 2021-12-02 16:33  小小渔  阅读(191)  评论(0编辑  收藏  举报