Swagger转换成Excel文件

1、添加swagger解析依赖包:

        <dependency>
            <groupId>io.swagger.parser.v3</groupId>
            <artifactId>swagger-parser</artifactId>
            <version>2.1.12</version>
        </dependency>

2、示例代码:

package com.rlcloud.risk.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.models.*;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.properties.Property;
import io.swagger.parser.SwaggerParser;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Map;


/**
 * @Description : Swagger转换成Excel文件
 * @date 2024/3/28 17:30
 * @return
 * @auther xushuanglu
 */
public class SwaggerToExcel {
   
   

    public static void main(String[] args) throws Exception {
   
   
        // 1、获取Swagger文档
        Swagger swagger = new SwaggerParser().read("http://your-swagger-url/v2/api-docs");

        // 创建Excel工作簿
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("Swagger API Documentation");

        // 创建标题行
        Row titleRow = sheet.createRow(0);
        Cell titleCell1 = titleRow.createCell(0);
        titleCell1.setCellValue("Path");
        Cell titleCell2 = titleRow.createCell(1);
        titleCell2.setCellValue("Description");
        // ... 添加其他需要的列标题
        Cell titleCell3 = titleRow.createCell(2);
        titleCell3.setCellValue("dataType");
        Cell titleCell4 = titleRow.createCell(3);
        titleCell4.setCellValue("接口名称");
        Cell titleCell5 = titleRow.createCell(4);
        titleCell5.setCellValue("code");

        int rowNum = 1;
        String oldNum = "001";
        // 遍历每个路径
        for (String path : swagger.getPaths().keySet()) {
   
   
            // 遍历每个操作
            for (Map.Entry<HttpMethod, Operation> entry : swagger.getPaths().get(path).getOperationMap().entrySet()) {
   
   
                Row row = sheet.createRow(rowNum);
                Cell cell1 = row.createCell(0);
                cell1.setCellValue(path);
                Cell cell2 = row.createCell(1);
                cell2.setCellValue(entry.getValue().getSummary());
                // ... 填充其他需要的信息
                Cell cell3 = row.c
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xushuanglu_csdn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值