【D3S】集成smart-doc并同步配置到Torna

news2024/9/22 23:22:34

目录

    • 一、引言
    • 二、maven插件
    • 三、smart-doc.json配置
    • 四、smart-doc-maven-plugin相关命令
    • 五、推送文档到Torna
    • 六、通过Maven Profile简化构建

一、引言

D3S(DDD with SpringBoot)为本作者使用DDD过程中开发的框架,目前已可公开查看源码,笔者正在持续完善该框架,争取打造一个可落地的DDD框架。而在开发D3S框架的过程中,相较Swagger、OpenApi以注解侵入代码的方式,笔者选择了smart-doc以代码注释的形式来完成REST接口文档的生成,配合Torna可以方便完成接口文档同步与管理的工作。之前笔者也成使用过YAPI,但是目前YAPI对OpenApi 3.0支持的不是很好,实测将OAS 3.0的接口文档JSON导入YAPI后,会出现接口返回结果为空的情况,实测Torna对OAS 3.0支持的较为完善,同时Torna也支持直接导入Swagger/OAS文档(JSON/YAML)或URL链接导入,故现阶段如果想选择一款文档管理工具,还是比较推荐Torna。
在这里插入图片描述
在这里插入图片描述

关于smart-doc与Swagger、OpenApi等的比较可参见笔者之前的博客:
SpringBoot应用生成RESTful API文档 - Swagger 2.0、OAS 3.0、Springfox、Springdoc、Smart-doc

接下来本文主要介绍如何通过maven插件集成smart-doc,并同步接口文档到Torna。由于smart-doc会直接解析代码注释,所以注释规范的代码几乎不需要额外的修改,如此也能养成团队规范代码注释的习惯。

二、maven插件

配置如下smart-doc-maven-plugin插件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    
    <properties>
        <smart.doc.version>2.6.1</smart.doc.version>
        <smart.doc.goal>openapi</smart.doc.goal>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <!-- smart-doc插件定义 -->
                <plugin>
                    <groupId>com.github.shalousun</groupId>
                    <artifactId>smart-doc-maven-plugin</artifactId>
                    <version>${smart.doc.version}</version>
                    <configuration>
                        <!--指定生成文档的使用的配置文件,配置文件放在自己的项目中-->
                        <configFile>./src/main/resources/smart-doc.json</configFile>
                        <!--smart-doc实现自动分析依赖树加载第三方依赖的源码,如果一些框架依赖库加载不到导致报错,这时请使用excludes排除掉-->
                        <excludes>
                            <!--格式为:groupId:artifactId;参考如下-->
                            <!--也可以支持正则式如:com.alibaba:.* -->
                            <exclude>com.alibaba:.*</exclude>
                            <exclude>cn.hutool:hutool-core</exclude>
                        </excludes>
                    </configuration>
                    <executions>
                        <execution>
                            <!--如果不需要在执行编译时启动smart-doc,则将phase注释掉-->
                            <phase>compile</phase>
                            <goals>
                                <!--smart-doc提供了html、openapi、markdown等goal,可按需配置-->
                                <goal>${smart.doc.goal}</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <!-- smart-doc插件定义 -->
            <plugin>
                <groupId>com.github.shalousun</groupId>
                <artifactId>smart-doc-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>    
</project>

三、smart-doc.json配置

在src/main/resources下添加smart-doc.json,示例配置如下:

注: 该配置文件smart-doc.json的具体位置可参见前一章节中的maven插件的<configFile/>配置

{
  "projectName": "D3S - Smartdoc - API",
  "serverUrl": "http://localhost:8080",
  "pathPrefix": "/",
  "outPath": "./target/smart-doc",
  "allInOne": true,
  "showAuthor": true,
  "groups": [
    {
      "name": "用户管理",
      "apis": "com.luo.demo.api.controller.user.*"
    },
    {
      "name": "角色管理",
      "apis": "com.luo.demo.api.controller.role.*"
    }
  ],
  "revisionLogs": [
    {
      "version": "1.0",
      "revisionTime": "2022-01-17 16:30",
      "status": "create",
      "author": "luohq",
      "remarks": "Smartdoc OAS3集成Springdoc"
    }
  ]
}

注:
outPath为生成接口文档位置,上述示例配置放到了target/smart-doc下,亦可将文档生成至源代码路径,如: ./src/main/resources/smart-doc,
groups、revisionLogs若不需要可移除,
完整配置说明可参见:https://smart-doc-group.github.io/#/zh-cn/diy/config。

四、smart-doc-maven-plugin相关命令

如上集成方式可直接使用mvn clean package即可生成smart-doc相关接口文档,
在D3S中使用smart-doc生成的OpenAPI接口文档,具体内容可参见:gitee/luoex/d3s/…/doc/openapi
更多smart-doc相关命令使用参考如下:

# =========== REST API文档 =============
# 生成html
mvn -Dfile.encoding=UTF-8 smart-doc:html
# 生成markdown
mvn -Dfile.encoding=UTF-8 smart-doc:markdown
# 生成adoc
mvn -Dfile.encoding=UTF-8 smart-doc:adoc
# 生成postman json数据
mvn -Dfile.encoding=UTF-8 smart-doc:postman
# 生成 Open Api 3.0+,Since smart-doc-maven-plugin 1.1.5
mvn -Dfile.encoding=UTF-8 smart-doc:openapi
# 生成文档推送到Torna平台
mvn -Dfile.encoding=UTF-8 smart-doc:torna-rest

# =========== Apache Dubbo RPC文档 =============
# 生成html
mvn -Dfile.encoding=UTF-8 smart-doc:rpc-html
# 生成markdown
mvn -Dfile.encoding=UTF-8 smart-doc:rpc-markdown
# 生成adoc
mvn -Dfile.encoding=UTF-8 smart-doc:rpc-adoc
# 生成dubbo接口文档推送到torna
mvn -Dfile.encoding=UTF-8 smart-doc:torna-rpc

五、推送文档到Torna

注:
关于Torna管理端的搭建可参见:https://gitee.com/durcframework/torna#方式1下载zip本地运行
Torna相关配置说明可参见:https://torna.cn/dev/config.html

修改src/main/resources/smart-doc.json配置,添加appToken、openUrl属性:

{
  "projectName": "D3S smart-doc API",
  "serverUrl": "http://localhost:8080",
  "pathPrefix": "/",
  "outPath": "./src/main/resources/static/doc",
  "allInOne": true,
  //appToken对应下图Tonar管理端中的token
  "appToken": "c16931fa6590483fb7a4e85340fcbfef",
  //openUrl对应下图Tonar管理端中的请求路径
  "openUrl": "http://localhost:7700/api"
}

其中appToken、openUrl对应Torna中具体应用下的配置,
在Torna中的层级分为:空间 -> 项目 -> 应用
依次创建对应层级后,到具体的应用中的OpenAPI菜单,
如下的token即对应appToken,请求路径即对应openUrl。

在这里插入图片描述

执行如下命令后,即可将smart-doc生成的文档同步到Torna:

# 生成接口文档并推送到Torna平台
mvn -Dfile.encoding=UTF-8 smart-doc:torna-rest

同步到Torna后效果如下:
在这里插入图片描述
在这里插入图片描述

六、通过Maven Profile简化构建

在pom中添加不同profile,用于区分smart-doc-maven-plugin构建目标,后续切换不同Profile即可执行对应的目标:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    
    <properties>
        <smart.doc.version>2.6.1</smart.doc.version>
        <smart.doc.goal>openapi</smart.doc.goal>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <!-- smart-doc插件定义 -->
                <plugin>
                    <groupId>com.github.shalousun</groupId>
                    <artifactId>smart-doc-maven-plugin</artifactId>
                    <version>${smart.doc.version}</version>
                    <configuration>
                        <!--指定生成文档的使用的配置文件,配置文件放在自己的项目中-->
                        <configFile>./src/main/resources/smart-doc.json</configFile>
                        <!--smart-doc实现自动分析依赖树加载第三方依赖的源码,如果一些框架依赖库加载不到导致报错,这时请使用excludes排除掉-->
                        <excludes>
                            <!--格式为:groupId:artifactId;参考如下-->
                            <!--也可以支持正则式如:com.alibaba:.* -->
                            <exclude>com.alibaba:.*</exclude>
                            <exclude>cn.hutool:hutool-core</exclude>
                        </excludes>
                    </configuration>
                    <executions>
                        <execution>
                            <!--如果不需要在执行编译时启动smart-doc,则将phase注释掉-->
                            <phase>compile</phase>
                            <goals>
                                <!--smart-doc提供了html、openapi、markdown等goal,可按需配置-->
                                <goal>${smart.doc.goal}</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <!-- 生成openapi.json -->
        <profile>
            <id>smart-doc-openapi</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <smart.doc.goal>openapi</smart.doc.goal>
            </properties>
        </profile>

        <!-- 同步到Torna -->
        <profile>
            <id>smart-doc-torna-rest</id>
            <properties>
                <smart.doc.goal>torna-rest</smart.doc.goal>
            </properties>
        </profile>

        <!-- 生成Html接口文档 -->
        <profile>
            <id>smart-doc-html</id>
            <properties>
                <smart.doc.goal>html</smart.doc.goal>
            </properties>
        </profile>

        <!-- 生成Markdown接口文档 -->
        <profile>
            <id>smart-doc-markdown</id>
            <properties>
                <smart.doc.goal>markdown</smart.doc.goal>
            </properties>
        </profile>
    </profiles>

</project>

之后即可通过切换mvn profile生成不同形式的接口文档:

# 生成openapi.json
mvn clean package -P smart-doc-openapi
# 生成html接口文档
mvn clean package -P smart-doc-html
# 生成markdown接口文档
mvn clean package -P smart-doc-markdown
# 推送到Torna
mvn clean package -P smart-doc-torna-rest

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/855322.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

leetcode26-删除有序数组中的重复项

双指针—快慢指针 慢指针 slow 走在后面&#xff0c;快指针 fast 走在前面探路&#xff0c;找到一个不重复的元素的时候就让slow前进一步并赋值给它。 流程&#xff1a; 代码 class Solution { public:int removeDuplicates(vector<int>& nums) {int slow 0, fas…

【2012年专利】基于中继节点的互联网通信系统和通信路径选择方法

基于中继节点的互联网通信系统和通信路径选择方法 CN102594703A地址基于中继节点的互联网通信系统和通信路径选择方法 ,解决:服务器间直接传输时丢包率高及延时长的缺点包括:服务器之间转发数据包的中继节点计算服务器间最优传输路径的选路决策节点, 本发明涉及一种晶于中继…

【Spring专题】Spring之底层架构核心概念解析

目录 前言前置知识课程内容一、BeanDefinition&#xff1a;图纸二、BeanDefinitionReader&#xff1a;图纸读取器——Spring工厂基础设施之一2.1 AnnotatedBeanDefinitionReader2.2 XmlBeanDefinitionReader2.3 ClassPathBeanDefinitionScanner 三、BeanFactory&#xff1a;生产…

银行电子密码器也远程管理吗?操作步骤如下

企业需要在不同办公地点管理多个资金账户&#xff0c;能不能远程点按读取银行电子密码器呢&#xff1f; 三个字&#xff0c;很简单&#xff01; 可以用密码点按器&#xff01; 有了它就可以自动输入密码和读取验证码&#xff01; 第一步 用双面胶把密码器固定在点按器上&…

【UE4 RTS】04-Camera Pan

前言 本篇实现了CameraPawn的旋转功能。 效果 步骤 1. 打开项目设置&#xff0c;添加两个操作映射 2. 打开玩家控制器“RTS_PlayerController_BP”&#xff0c;新建一个浮点型变量&#xff0c;命名为“PanSpeed” 在事件图表中添加如下节点 此时运行游戏可以发现当鼠标移动…

【学习日记】【FreeRTOS】调度器函数实现详解

写在前面 本文主要是对于 FreeRTOS 中调度器函数实现的详细解释&#xff0c;代码大部分参考了野火 FreeRTOS 教程配套源码&#xff0c;作了一小部分修改。 一、MSP 和 PSP Cortex-M有两种栈空间&#xff0c;主堆栈和进程堆栈。 MSP 用于系统级别和中断处理的堆栈 MSP 用于保…

一文看懂Apipost接口自动化使用方法

随着项目研发进程的不断推进&#xff0c;软件功能不断增多&#xff0c;对于软件测试的要求也越来越高。为了提高测试效率和减少测试成本&#xff0c;许多软件测试团队借助于自动化测试工具来优化测试流程。Apipost也提供了自动化测试工具&#xff0c;在本文中&#xff0c;我们将…

Android Studio System.out.println()中文乱码

第一步&#xff1a; 打开studio64.exe.vmoptions加入-Dfile.encodingUTF-8 第二步&#xff1a; File-Settings-Editor-File Encodings 把所有的编码格式改为UTF-8 尝试跑一下代码&#xff0c;如果还不行&#xff0c;重启IDE 再试试。

利用DNS隧道构建隐蔽CC信道

背景介绍 无论是高级持续性威胁(APT&#xff09;、僵尸网络(Botnet)&#xff0c;还是勒索软件、后门等&#xff0c;命令与控制信道(C &C)都是其重要组成部分&#xff0c;尤其是APT和僵尸网络中的C&C信道决定了其威胁程度。学术界和工业界就C&C方面的研究已逐渐深入…

vue3:新特性

一、react和vue的主要区别 &#xff08;1&#xff09;数据更新上&#xff1a; 1、 react 采用 fiber架构 &#xff0c;使用 链表 表示 DOM 结构可以在 diff 时随时中断和继续&#xff0c;利用requestIdleCallback 在空闲时 diff &#xff0c;防止数据量大 diff 时间长导致卡顿…

Python 之禅

Python 社区的理念都包含在 Tim Peters 撰写的 “Python 之禅” 中 在 Windows 平台的 cmd 命令中打开 python&#xff0c;输入 import this&#xff0c;就能看到 Python 之禅: 翻译&#xff1a; Tim Peters 的 python 之禅Beautiful is better than ugly. # 优美胜于丑陋&am…

生成树协议

文章目录 STP冗余交换网络为什么存在广播风暴&#xff1f;广播的危害&#xff1f;交换环路的危害&#xff1f; 工作机制BPDU什么是最好的bpduBPDU触发机制 STP选举步骤配置协议分析字段分析开销模式端口状态 故障类型根桥故障直连故障间接故障 &#xff08;链路中间可能有HUB&a…

vuejs 设计与实现 - 渲染器的设计

渲染器与响应式系统的结合 本节&#xff0c;我们暂时将渲染器限定在 DOM 平台。既然渲染器用来渲染真实 DOM 元素&#xff0c;那么严格来说&#xff0c;下面的函数就是一个合格的渲染器: // 渲染器&#xff1a; function renderer(domString, container) {container.innerHTM…

中级课程-SSRF(CSRF进阶)

文章目录 成因危害挖掘 成因 危害 挖掘

JUC并发编程之线程锁(一)

目录 1.ReentrantLock(互斥锁) 2.ReentRantReaderWriterLock&#xff08;互斥读写锁&#xff09; 3.StampedLock&#xff08;无障碍锁&#xff09; 4.Condition&#xff08;自定义锁&#xff09; 5.LockSupport 问题引出&#xff1a; 由于传统的线程控制需要用到同步机制Sy…

LeetCode--HOT100题(23)

目录 题目描述&#xff1a;206. 反转链表&#xff08;简单&#xff09;题目接口解题思路代码 PS: 题目描述&#xff1a;206. 反转链表&#xff08;简单&#xff09; 给你单链表的头节点 head &#xff0c;请你反转链表&#xff0c;并返回反转后的链表。 LeetCode做题链接&…

剑指offer56-II.数组中数字出现的次数II

第一种方法非常简单&#xff0c;就是用一个HashMap&#xff0c;key是数组中元素的值&#xff0c;value是出现的次数&#xff0c;所以遍历一遍数组&#xff0c;如果map中没有这个元素就把它put进去value设为1&#xff0c;否则value加1&#xff0c;然后遍历一遍map&#xff0c;如…

tensorflow 1.14 的 demo 02 —— tensorboard 远程访问

tensorflow 1.14.0&#xff0c; 提供远程访问 tensorboard 服务的方法 第一步生成 events 文件&#xff1a; 在上一篇demo的基础上加了一句&#xff0c;如下&#xff0c; tf.summary.FileWriter("./tmp/summary", graphsess1.graph) hello_tensorboard_remote.py …

Celery嵌入工程的使用

文章目录 1.config 1.1 通过app.conf进行配置1.2 通过app.conf.update进行配置1.3 通过配置文件进行配置1.4 通过配置类的方式进行配置2.任务相关 2.1 任务基类(base)2.2 任务名称(name)2.3 任务请求(request)2.4 任务重试(retry) 2.4.1 指定最大重试次数2.4.2 设置重试间隔时间…

基础排障实验

排障实验要求&#xff1a; 确保重启后服务能正常访问。确保在客户机上&#xff0c;应用能够使用http://www.jxjz.com:8081访问。确保DNS能够解析邮件服务器mail.jxjz.com。确保DHCP能够保留地址192.168.100.200/24给MAC为ff-0a-ac-44-33-22的主机。确保client客户机能正常的分…