当前位置: 首页 > news >正文

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

目录

    • 一、引言
    • 二、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

相关文章:

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

目录 一、引言二、maven插件三、smart-doc.json配置四、smart-doc-maven-plugin相关命令五、推送文档到Torna六、通过Maven Profile简化构建 一、引言 D3S&#xff08;DDD with SpringBoot&#xff09;为本作者使用DDD过程中开发的框架&#xff0c;目前已可公开查看源码&#…...

网络安全设备及部署

什么是等保定级&#xff1f; 之前了解了下等保定级&#xff0c;接下里做更加深入的探讨 文章目录 一、网路安全大事件1.1 震网病毒1.2 海康威视弱口令1.3 物联网Mirai病毒1.4 专网 黑天安 事件1.5 乌克兰停电1.6 委内瑞拉电网1.7 棱镜门事件1.8 熊猫烧香 二、法律法规解读三、安…...

LVS集群

目录 1、lvs简介&#xff1a; 2、lvs架构图&#xff1a; 3、 lvs的工作模式&#xff1a; 1&#xff09; VS/NAT&#xff1a; 即&#xff08;Virtual Server via Network Address Translation&#xff09; 2&#xff09;VS/TUN &#xff1a;即&#xff08;Virtual Server v…...

Kubernetes(K8s)从入门到精通系列之十二:安装和设置 kubectl

Kubernetes K8s从入门到精通系列之十二&#xff1a;安装和设置 kubectl 一、kubectl二、在 Linux 系统中安装并设置 kubectl1.准备工作2.用 curl 在 Linux 系统中安装 kubectl3.用原生包管理工具安装 三、验证 kubectl 配置四、kubectl 的可选配置和插件1.启用 shell 自动补全功…...

探索 TypeScript 元组的用例

元组扩展了数组数据类型的功能。使用元组&#xff0c;我们可以轻松构造特殊类型的数组&#xff0c;其中元素相对于索引或位置是固定类型的。由于 TypeScript 的性质&#xff0c;这些元素类型在初始化时是已知的。使用元组&#xff0c;我们可以定义可以存储在数组中每个位置的数…...

Pytorch使用NN神经网络模型实现经典波士顿boston房价预测问题

Pytorch使用多层神经网络模型实现经典波士顿boston房价预测问题 波士顿房价数据集介绍 波士顿房价数据集是一个经典的机器学习数据集&#xff0c;用于预测波士顿地区房屋的中位数价格。该数据集包含了506个样本&#xff0c;每个样本有13个特征&#xff0c;包括城镇的各种指标&…...

微服务间消息传递

微服务间消息传递 微服务是一种软件开发架构&#xff0c;它将一个大型应用程序拆分为一系列小型、独立的服务。每个服务都可以独立开发、部署和扩展&#xff0c;并通过轻量级的通信机制进行交互。 应用开发 common模块中包含服务提供者和服务消费者共享的内容provider模块是…...

python——案例16:约瑟夫生者死者链队列

约瑟夫游戏的大意是&#xff1a;一条船上有30个人&#xff0c;因为在海上遇到风暴 因此船长告诉乘客&#xff0c;必须牺牲15个人&#xff0c;并议定30个人围成一圈&#xff0c; 由第一个人数起&#xff0c;依次报数&#xff0c;数到第9人&#xff0c;便把他投入大海中&#xff…...

【人工智能前沿弄潮】—— 玩转SAM(Segment Anything)

玩转SAM(Segment Anything) 官网链接&#xff1a; Segment Anything | Meta AI (segment-anything.com) github链接&#xff1a; facebookresearch/segment-anything: The repository provides code for running inference with the SegmentAnything Model (SAM), links fo…...

每日一题——合并两个有序的数组

题目 给出一个有序的整数数组 A 和有序的整数数组 B &#xff0c;请将数组 B 合并到数组 A 中&#xff0c;变成一个有序的升序数组 数据范围&#xff1a;0≤n,m≤100&#xff0c;∣Ai∣<100&#xff0c;∣Bi∣<100 注意&#xff1a; 1.保证 A 数组有足够的空间存放 B …...

MPP架构和Hadoop架构的区别

1. 架构的介绍 mpp架构是将许多数据库通过网络连接起来&#xff0c;相当于将一个个垂直系统横向连接&#xff0c;形成一个统一对外的服务的分布式数据库系统。每个节点由一个单机数据库系统独立管理和操作该物理机上的的所有资源&#xff08;CPU&#xff0c;内存等&#xff09…...

Java02-迭代器,数据结构,List,Set ,Map,Collections工具类

目录 什么是遍历&#xff1f; 一、Collection集合的遍历方式 1.迭代器遍历 方法 流程 案例 2. foreach&#xff08;增强for循环&#xff09;遍历 案例 3.Lamdba表达式遍历 案例 二、数据结构 数据结构介绍 常见数据结构 栈&#xff08;Stack&#xff09; 队列&a…...

福布斯发布2023云计算100强榜单,全球流程挖掘领导者Celonis排名17

近日&#xff0c;全球流程挖掘领导者Celonis入选福布斯2023 年云计算 100 强榜单&#xff0c;估值130亿美元&#xff0c;排名第17&#xff0c;Celonis已经是连续三年跻身榜单前20名。 本次榜单由福布斯与Bessemer Venture Partners和Salesforce Ventures联合发布&#xff0c;旨…...

计算机网络 MAC地址

...

Jay17 2023.8.10日报

笔记 【python反序列化】 序列化 类对象->字节流&#xff08;字符串&#xff09; 反序列化 字节流->对象 python反序列化没PHP这么灵活&#xff0c;没这么多魔术方法。 import pickle import os class ctfshow(): def init(self): self.username0 self.password0 d…...

Winform中DatagridView 表头实现一个加上一个checkBox,实现全选选项功能

实现效果 点击checkBox1或者直接在第一列列表头点击即可实现 代码实现 我的datagridview叫dgv 我在datagridview已经默认添加了一个DataGridViewCheckBoxColumn&#xff0c;勾选时value为1&#xff0c;不勾选时value为0 第一种通过可视化拖动一个checkBox来实现 拖动组…...

rust基础

这是笔者学习rust的学习笔记&#xff08;如有谬误&#xff0c;请君轻喷&#xff09; 参考视频&#xff1a; https://www.bilibili.com/video/BV1hp4y1k7SV参考书籍&#xff1a;rust程序设计语言&#xff1a;https://rust.bootcss.com/title-page.htmlmarkdown地址&#xff1a;h…...

剑指offer39.数组中出现次数超过一半的数字

这个题非常简单&#xff0c;解法有很多种&#xff0c;我用的是HashMap记录每个元素出现的次数&#xff0c;只要次数大于数组长度的一半就返回。下面是我的代码&#xff1a; class Solution {public int majorityElement(int[] nums) {int len nums.length/2;HashMap<Integ…...

spring技术栈面试题

1 Spring支持的事务管理类型有哪些&#xff1f;你在项目中使用哪种方式&#xff1f; Spring支持两种类型的事务管理&#xff1a; 编程式事务管理&#xff1a;这意味你通过编程的方式管理事务&#xff0c;给你带来极大的灵活性&#xff0c;但是难维护。声明式事务管理&#x…...

Android Glide MemorySizeCalculator计算值,Kotlin

Android Glide MemorySizeCalculator计算值,Kotlin for (i in 100..1000 step 50) {val calculator MemorySizeCalculator.Builder(this).setMemoryCacheScreens(i.toFloat()).setBitmapPoolScreens(i.toFloat()).setMaxSizeMultiplier(0.8f).setLowMemoryMaxSizeMultiplier(0…...

基于算法竞赛的c++编程(28)结构体的进阶应用

结构体的嵌套与复杂数据组织 在C中&#xff0c;结构体可以嵌套使用&#xff0c;形成更复杂的数据结构。例如&#xff0c;可以通过嵌套结构体描述多层级数据关系&#xff1a; struct Address {string city;string street;int zipCode; };struct Employee {string name;int id;…...

基于ASP.NET+ SQL Server实现(Web)医院信息管理系统

医院信息管理系统 1. 课程设计内容 在 visual studio 2017 平台上&#xff0c;开发一个“医院信息管理系统”Web 程序。 2. 课程设计目的 综合运用 c#.net 知识&#xff0c;在 vs 2017 平台上&#xff0c;进行 ASP.NET 应用程序和简易网站的开发&#xff1b;初步熟悉开发一…...

YSYX学习记录(八)

C语言&#xff0c;练习0&#xff1a; 先创建一个文件夹&#xff0c;我用的是物理机&#xff1a; 安装build-essential 练习1&#xff1a; 我注释掉了 #include <stdio.h> 出现下面错误 在你的文本编辑器中打开ex1文件&#xff0c;随机修改或删除一部分&#xff0c;之后…...

【Redis技术进阶之路】「原理分析系列开篇」分析客户端和服务端网络诵信交互实现(服务端执行命令请求的过程 - 初始化服务器)

服务端执行命令请求的过程 【专栏简介】【技术大纲】【专栏目标】【目标人群】1. Redis爱好者与社区成员2. 后端开发和系统架构师3. 计算机专业的本科生及研究生 初始化服务器1. 初始化服务器状态结构初始化RedisServer变量 2. 加载相关系统配置和用户配置参数定制化配置参数案…...

自然语言处理——循环神经网络

自然语言处理——循环神经网络 循环神经网络应用到基于机器学习的自然语言处理任务序列到类别同步的序列到序列模式异步的序列到序列模式 参数学习和长程依赖问题基于门控的循环神经网络门控循环单元&#xff08;GRU&#xff09;长短期记忆神经网络&#xff08;LSTM&#xff09…...

在WSL2的Ubuntu镜像中安装Docker

Docker官网链接: https://docs.docker.com/engine/install/ubuntu/ 1、运行以下命令卸载所有冲突的软件包&#xff1a; for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done2、设置Docker…...

AI,如何重构理解、匹配与决策?

AI 时代&#xff0c;我们如何理解消费&#xff1f; 作者&#xff5c;王彬 封面&#xff5c;Unplash 人们通过信息理解世界。 曾几何时&#xff0c;PC 与移动互联网重塑了人们的购物路径&#xff1a;信息变得唾手可得&#xff0c;商品决策变得高度依赖内容。 但 AI 时代的来…...

管理学院权限管理系统开发总结

文章目录 &#x1f393; 管理学院权限管理系统开发总结 - 现代化Web应用实践之路&#x1f4dd; 项目概述&#x1f3d7;️ 技术架构设计后端技术栈前端技术栈 &#x1f4a1; 核心功能特性1. 用户管理模块2. 权限管理系统3. 统计报表功能4. 用户体验优化 &#x1f5c4;️ 数据库设…...

Unity中的transform.up

2025年6月8日&#xff0c;周日下午 在Unity中&#xff0c;transform.up是Transform组件的一个属性&#xff0c;表示游戏对象在世界空间中的“上”方向&#xff08;Y轴正方向&#xff09;&#xff0c;且会随对象旋转动态变化。以下是关键点解析&#xff1a; 基本定义 transfor…...

Python 高效图像帧提取与视频编码:实战指南

Python 高效图像帧提取与视频编码:实战指南 在音视频处理领域,图像帧提取与视频编码是基础但极具挑战性的任务。Python 结合强大的第三方库(如 OpenCV、FFmpeg、PyAV),可以高效处理视频流,实现快速帧提取、压缩编码等关键功能。本文将深入介绍如何优化这些流程,提高处理…...