增加gson依赖 生成json文件到outpath目录

This commit is contained in:
xingzi 2019-12-01 12:01:12 +08:00
parent 2cb1c62d41
commit 1ec2af6b27
3 changed files with 18 additions and 6 deletions

View File

@ -83,6 +83,12 @@
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -1,6 +1,9 @@
package com.power.doc.builder;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.power.common.util.FileUtil;
import com.power.doc.constants.DocGlobalConstants;
import com.power.doc.model.ApiConfig;
import com.power.doc.model.ApiDoc;
@ -26,10 +29,9 @@ public class PostMainJsonBuilder {
/**
* 构建postman json
*
* @param config
* @return
* @param config 配置文件
*/
public static RequestItem BuildPostmanApi(ApiConfig config) {
public static void BuildPostmanApi(ApiConfig config) {
DocBuilderTemplate builderTemplate = new DocBuilderTemplate();
builderTemplate.checkAndInit(config);
SourceBuilder sourceBuilder = new SourceBuilder(config);
@ -45,9 +47,11 @@ public class PostMainJsonBuilder {
}
);
requestItem.setItem(itemBeans);
// requestItem 为最终的数据 转json ok
// System.out.println(new Gson().toJson(requestItem));
return requestItem;
String filePath = config.getOutPath();
filePath = filePath +DocGlobalConstants.POSTMAN_JSON;
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String data = gson.toJson(requestItem);
FileUtil.nioWriteFile(data,filePath);
}
/**

View File

@ -45,6 +45,8 @@ public class DocGlobalConstants {
public static final String ALL_IN_ONE_CSS = "AllInOne.css";
public static final String POSTMAN_JSON = "/smart-doc.json";
public static final String CONTROLLER_FULLY = "org.springframework.stereotype.Controller";
public static final String REST_CONTROLLER_FULLY = "org.springframework.web.bind.annotation.RestController";