“m添加推送dubbo设置
This commit is contained in:
parent
a45e890fc8
commit
f4869361ef
|
@ -34,6 +34,7 @@ import com.power.doc.constants.TornaConstants;
|
|||
import com.power.doc.model.*;
|
||||
import com.power.doc.model.torna.*;
|
||||
import com.power.doc.template.SpringBootDocBuildTemplate;
|
||||
import com.power.doc.utils.TornaUtil;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
import okhttp3.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -47,6 +48,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import static com.power.doc.constants.TornaConstants.CATEGORY_CREATE;
|
||||
import static com.power.doc.constants.TornaConstants.PUSH;
|
||||
import static com.power.doc.utils.TornaUtil.*;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -87,212 +89,24 @@ public class TornaBuilder {
|
|||
* @param apiConfig ApiConfig
|
||||
*/
|
||||
public static void buildTorna(List<ApiDoc> apiDocs, ApiConfig apiConfig) {
|
||||
|
||||
//是否设置测试环境
|
||||
boolean hasDebugEnv = StringUtils.isNotBlank(apiConfig.getDebugEnvName())
|
||||
&&
|
||||
StringUtils.isNotBlank(apiConfig.getDebugEnvUrl());
|
||||
|
||||
if (apiConfig.isTornaDebug()) {
|
||||
String sb = "配置信息列表: \n" +
|
||||
"OpenUrl: " +
|
||||
apiConfig.getOpenUrl() +
|
||||
"\n" +
|
||||
"appToken: " +
|
||||
apiConfig.getAppToken() +
|
||||
"\n" +
|
||||
"appKey: " +
|
||||
apiConfig.getAppKey() +
|
||||
"\n" +
|
||||
"Secret: " +
|
||||
apiConfig.getSecret() +
|
||||
"\n";
|
||||
System.out.println(sb);
|
||||
}
|
||||
TornaApi tornaApi = new TornaApi();
|
||||
//设置测试环境
|
||||
List<DebugEnv> debugEnvs = new ArrayList<>();
|
||||
if (hasDebugEnv) {
|
||||
DebugEnv debugEnv = new DebugEnv();
|
||||
debugEnv.setName(apiConfig.getDebugEnvName());
|
||||
debugEnv.setUrl(apiConfig.getDebugEnvUrl());
|
||||
debugEnvs.add(debugEnv);
|
||||
|
||||
}
|
||||
//
|
||||
Apis api;
|
||||
List<Apis> apisList = new ArrayList<>();
|
||||
//添加接口数据
|
||||
for (ApiDoc a : apiDocs) {
|
||||
api = new Apis();
|
||||
api.setName(StringUtils.isBlank(a.getDesc()) ? a.getName() : a.getDesc());
|
||||
api.setItems(buildApis(a, hasDebugEnv));
|
||||
api.setItems(buildApis(a.getList(), TornaUtil.setDebugEnv(apiConfig,tornaApi)));
|
||||
api.setIsFolder(TornaConstants.YES);
|
||||
apisList.add(api);
|
||||
}
|
||||
tornaApi.setDebugEnvs(debugEnvs);
|
||||
tornaApi.setApis(apisList);
|
||||
//推送文档信息
|
||||
Map<String, String> requestJson =
|
||||
TornaConstants.buildParams(PUSH, new Gson().toJson(tornaApi), apiConfig);
|
||||
Map<String, String> requestJson = TornaConstants.buildParams(PUSH, new Gson().toJson(tornaApi), apiConfig);
|
||||
//获取返回结果
|
||||
String responseMsg = OkHttp3Util.syncPostJson(apiConfig.getOpenUrl(), new Gson().toJson(requestJson));
|
||||
//开启调试时打印请求信息
|
||||
if (apiConfig.isTornaDebug()) {
|
||||
JsonElement element = JsonParser.parseString(responseMsg);
|
||||
TornaRequestInfo info = new TornaRequestInfo()
|
||||
.of()
|
||||
.setCategory(PUSH)
|
||||
.setCode(element.getAsJsonObject().get(TornaConstants.CODE).getAsString())
|
||||
.setMessage(element.getAsJsonObject().get(TornaConstants.MESSAGE).getAsString())
|
||||
.setRequestInfo(requestJson)
|
||||
.setResponseInfo(responseMsg);
|
||||
System.out.println(info.buildInfo());
|
||||
}
|
||||
TornaUtil.printDebugInfo(apiConfig,responseMsg,requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* build apis
|
||||
* @param a api
|
||||
* @param hasDebugEnv has debug environment
|
||||
* @return List of Api
|
||||
*/
|
||||
public static List<Apis> buildApis(ApiDoc a, boolean hasDebugEnv) {
|
||||
List<ApiMethodDoc> apiMethodDocs = a.getList();
|
||||
//参数列表
|
||||
List<Apis> apis = new ArrayList<>();
|
||||
Apis methodApi;
|
||||
//遍历分类接口
|
||||
for (ApiMethodDoc apiMethodDoc : apiMethodDocs) {
|
||||
/**
|
||||
* "name": "获取商品信息",
|
||||
* "description": "获取商品信息",
|
||||
* "url": "/goods/get",
|
||||
* "httpMethod": "GET",
|
||||
* "contentType": "application/json",
|
||||
* "isFolder": "1",
|
||||
* "parentId": "",
|
||||
* "isShow": "1",
|
||||
*/
|
||||
methodApi = new Apis();
|
||||
methodApi.setIsFolder(TornaConstants.NO);
|
||||
methodApi.setName(apiMethodDoc.getDesc());
|
||||
methodApi.setUrl(hasDebugEnv ? apiMethodDoc.getPath() : apiMethodDoc.getUrl());
|
||||
methodApi.setHttpMethod(apiMethodDoc.getType());
|
||||
methodApi.setContentType(apiMethodDoc.getContentType());
|
||||
methodApi.setDescription(apiMethodDoc.getDetail());
|
||||
methodApi.setIsShow(TornaConstants.YES);
|
||||
|
||||
/**
|
||||
* {
|
||||
* "name": "goodsName",
|
||||
* "type": "string",
|
||||
* "required": "1",
|
||||
* "maxLength": "128",
|
||||
* "example": "iphone12",
|
||||
* "description": "商品名称描述",
|
||||
* "parentId": "",
|
||||
* "enumInfo": {
|
||||
* "name": "支付枚举",
|
||||
* "description": "支付状态",
|
||||
* "items": [
|
||||
* {
|
||||
* "name": "WAIT_PAY",
|
||||
* "type": "string",
|
||||
* "value": "0",
|
||||
* "description": "未支付"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
methodApi.setHeaderParams(buildHerder(apiMethodDoc.getRequestHeaders()));
|
||||
methodApi.setResponseParams(buildParams(apiMethodDoc.getResponseParams()));
|
||||
//Path
|
||||
if (CollectionUtil.isNotEmpty(apiMethodDoc.getPathParams())) {
|
||||
methodApi.setPathParams(buildParams(apiMethodDoc.getPathParams()));
|
||||
}
|
||||
//formData
|
||||
if (CollectionUtil.isNotEmpty(apiMethodDoc.getQueryParams())) {
|
||||
methodApi.setRequestParams(buildParams(apiMethodDoc.getQueryParams()));
|
||||
}
|
||||
//Json
|
||||
if (CollectionUtil.isNotEmpty(apiMethodDoc.getRequestParams())) {
|
||||
methodApi.setRequestParams(buildParams(apiMethodDoc.getRequestParams()));
|
||||
}
|
||||
apis.add(methodApi);
|
||||
}
|
||||
return apis;
|
||||
}
|
||||
|
||||
/**
|
||||
* build request header
|
||||
*
|
||||
* @param apiReqHeaders 请求头参数列表
|
||||
* @return List of HttpParam
|
||||
*/
|
||||
public static List<HttpParam> buildHerder(List<ApiReqHeader> apiReqHeaders) {
|
||||
/**
|
||||
* name": "token",
|
||||
* "required": "1",
|
||||
* "example": "iphone12",
|
||||
* "description": "商品名称描述"
|
||||
*/
|
||||
HttpParam httpParam;
|
||||
List<HttpParam> headers = new ArrayList<>();
|
||||
for (ApiReqHeader header : apiReqHeaders) {
|
||||
httpParam = new HttpParam();
|
||||
httpParam.setName(header.getName());
|
||||
httpParam.setRequired(header.isRequired() ? TornaConstants.YES : TornaConstants.NO);
|
||||
httpParam.setExample(StringUtil.removeQuotes(header.getValue()));
|
||||
httpParam.setDescription(header.getDesc());
|
||||
headers.add(httpParam);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* build request response params
|
||||
*
|
||||
* @param apiParams 参数列表
|
||||
* @return List of HttpParam
|
||||
*/
|
||||
public static List<HttpParam> buildParams(List<ApiParam> apiParams) {
|
||||
HttpParam httpParam;
|
||||
List<HttpParam> bodies = new ArrayList<>();
|
||||
/**
|
||||
* "name": "goodsName",
|
||||
* "type": "string",
|
||||
* "required": "1",
|
||||
* "maxLength": "128",
|
||||
* "example": "iphone12",
|
||||
* "description": "商品名称描述",
|
||||
* "parentId": "",
|
||||
* "enumInfo": {
|
||||
* "name": "支付枚举",
|
||||
* "description": "支付状态",
|
||||
* "items": [
|
||||
* {
|
||||
* "name": "WAIT_PAY",
|
||||
* "type": "string",
|
||||
* "value": "0",
|
||||
* "description": "未支付"
|
||||
*/
|
||||
for (ApiParam apiParam : apiParams) {
|
||||
httpParam = new HttpParam();
|
||||
httpParam.setName(apiParam.getField());
|
||||
httpParam.setMaxLength(apiParam.getMaxLength());
|
||||
httpParam.setType(apiParam.getType());
|
||||
httpParam.setRequired(apiParam.isRequired() ? TornaConstants.YES : TornaConstants.NO);
|
||||
httpParam.setExample(StringUtil.removeQuotes(apiParam.getValue()));
|
||||
httpParam.setDescription(apiParam.getDesc());
|
||||
if (apiParam.getChildren() != null) {
|
||||
httpParam.setChildren(buildParams(apiParam.getChildren()));
|
||||
}
|
||||
bodies.add(httpParam);
|
||||
}
|
||||
return bodies;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package com.power.doc.builder.rpc;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.power.common.util.OkHttp3Util;
|
||||
import com.power.doc.builder.DocBuilderTemplate;
|
||||
import com.power.doc.builder.ProjectDocConfigBuilder;
|
||||
import com.power.doc.constants.TornaConstants;
|
||||
import com.power.doc.model.ApiConfig;
|
||||
import com.power.doc.model.ApiDoc;
|
||||
import com.power.doc.model.rpc.RpcApiDoc;
|
||||
import com.power.doc.model.torna.Apis;
|
||||
import com.power.doc.model.torna.DubboInfo;
|
||||
import com.power.doc.model.torna.TornaApi;
|
||||
import com.power.doc.template.RpcDocBuildTemplate;
|
||||
import com.power.doc.template.SpringBootDocBuildTemplate;
|
||||
import com.power.doc.utils.TornaUtil;
|
||||
import com.thoughtworks.qdox.JavaProjectBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.power.doc.constants.TornaConstants.PUSH;
|
||||
import static com.power.doc.utils.TornaUtil.buildApis;
|
||||
import static com.power.doc.utils.TornaUtil.buildDubboApis;
|
||||
|
||||
/**
|
||||
* @author xingzi
|
||||
* @date 2021/4/28 16:14
|
||||
**/
|
||||
public class RpcTornaBuilder {
|
||||
/**
|
||||
* build controller api
|
||||
*
|
||||
* @param config config
|
||||
*/
|
||||
public static void buildApiDoc(ApiConfig config) {
|
||||
JavaProjectBuilder javaProjectBuilder = new JavaProjectBuilder();
|
||||
buildApiDoc(config, javaProjectBuilder);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Only for smart-doc maven plugin and gradle plugin.
|
||||
*
|
||||
* @param config ApiConfig
|
||||
* @param javaProjectBuilder ProjectDocConfigBuilder
|
||||
*/
|
||||
public static void buildApiDoc(ApiConfig config, JavaProjectBuilder javaProjectBuilder) {
|
||||
config.setParamsDataToTree(true);
|
||||
RpcDocBuilderTemplate builderTemplate = new RpcDocBuilderTemplate();
|
||||
builderTemplate.checkAndInit(config);
|
||||
ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder);
|
||||
RpcDocBuildTemplate docBuildTemplate = new RpcDocBuildTemplate();
|
||||
List<RpcApiDoc> apiDocList = docBuildTemplate.getApiData(configBuilder);
|
||||
buildTorna(apiDocList, config);
|
||||
}
|
||||
|
||||
public static void buildTorna(List<RpcApiDoc> apiDocs, ApiConfig apiConfig) {
|
||||
TornaApi tornaApi = new TornaApi();
|
||||
Apis api;
|
||||
List<Apis> apisList = new ArrayList<>();
|
||||
//添加接口数据
|
||||
for (RpcApiDoc a : apiDocs) {
|
||||
api = new Apis();
|
||||
api.setName(StringUtils.isBlank(a.getDesc()) ? a.getName() : a.getDesc());
|
||||
TornaUtil.setDebugEnv(apiConfig,tornaApi);
|
||||
api.setItems(buildDubboApis(a.getList()));
|
||||
api.setIsFolder(TornaConstants.YES);
|
||||
api.setDubboInfo(new DubboInfo().builder()
|
||||
.setAuthor(a.getAuthor())
|
||||
.setProtocol(a.getProtocol())
|
||||
.setVersion(a.getVersion())
|
||||
.setInterfaceName(a.getName()));
|
||||
apisList.add(api);
|
||||
}
|
||||
tornaApi.setApis(apisList);
|
||||
//推送文档信息
|
||||
Map<String, String> requestJson = TornaConstants.buildParams(PUSH, new Gson().toJson(tornaApi), apiConfig);
|
||||
//获取返回结果
|
||||
String responseMsg = OkHttp3Util.syncPostJson(apiConfig.getOpenUrl(), new Gson().toJson(requestJson));
|
||||
//开启调试时打印请求信息
|
||||
TornaUtil.printDebugInfo(apiConfig,responseMsg,requestJson);
|
||||
}
|
||||
}
|
|
@ -321,7 +321,7 @@ public class ApiConfig {
|
|||
/**
|
||||
* torna调试开关
|
||||
*/
|
||||
private boolean tornaDebug;
|
||||
private boolean tornaDebug = true;
|
||||
/**
|
||||
* 是否为dubbo
|
||||
*/
|
||||
|
|
|
@ -36,6 +36,7 @@ public class Apis {
|
|||
private String isFolder;
|
||||
private String parentId;
|
||||
private String isShow;
|
||||
private DubboInfo dubboInfo;
|
||||
private List<HttpParam> headerParams;
|
||||
private List<HttpParam> pathParams;
|
||||
private List<HttpParam> requestParams;
|
||||
|
@ -153,6 +154,14 @@ public class Apis {
|
|||
return items;
|
||||
}
|
||||
|
||||
public DubboInfo getDubboInfo() {
|
||||
return dubboInfo;
|
||||
}
|
||||
|
||||
public void setDubboInfo(DubboInfo dubboInfo) {
|
||||
this.dubboInfo = dubboInfo;
|
||||
}
|
||||
|
||||
public void setItems(List<Apis> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package com.power.doc.model.torna;
|
||||
|
||||
/**
|
||||
* @author xingzi
|
||||
* @date 2021/4/28 12:54
|
||||
**/
|
||||
public class DubboInfo {
|
||||
private String interfaceName;
|
||||
private String author;
|
||||
private String version;
|
||||
private String protocol;
|
||||
private String dependency;
|
||||
|
||||
public DubboInfo builder(){
|
||||
return new DubboInfo();
|
||||
}
|
||||
public String getInterfaceName() {
|
||||
return interfaceName;
|
||||
}
|
||||
|
||||
public DubboInfo setInterfaceName(String interfaceName) {
|
||||
this.interfaceName = interfaceName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public DubboInfo setAuthor(String author) {
|
||||
this.author = author;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public DubboInfo setVersion(String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public DubboInfo setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDependency() {
|
||||
return dependency;
|
||||
}
|
||||
|
||||
public DubboInfo setDependency(String dependency) {
|
||||
this.dependency = dependency;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DubboInfo{" +
|
||||
"interfaceName='" + interfaceName + '\'' +
|
||||
", author='" + author + '\'' +
|
||||
", version='" + version + '\'' +
|
||||
", protocol='" + protocol + '\'' +
|
||||
", dependency='" + dependency + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,273 @@
|
|||
package com.power.doc.utils;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.power.common.util.CollectionUtil;
|
||||
import com.power.common.util.StringUtil;
|
||||
import com.power.doc.constants.TornaConstants;
|
||||
import com.power.doc.model.*;
|
||||
import com.power.doc.model.torna.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.power.doc.constants.TornaConstants.PUSH;
|
||||
|
||||
/**
|
||||
* @author xingzi
|
||||
* @date 2021/4/28 16:15
|
||||
**/
|
||||
public class TornaUtil {
|
||||
|
||||
public static boolean setDebugEnv(ApiConfig apiConfig, TornaApi tornaApi) {
|
||||
//是否设置测试环境
|
||||
boolean hasDebugEnv = StringUtils.isNotBlank(apiConfig.getDebugEnvName())
|
||||
&&
|
||||
StringUtils.isNotBlank(apiConfig.getDebugEnvUrl());
|
||||
//设置测试环境
|
||||
List<DebugEnv> debugEnvs = new ArrayList<>();
|
||||
if (hasDebugEnv) {
|
||||
DebugEnv debugEnv = new DebugEnv();
|
||||
debugEnv.setName(apiConfig.getDebugEnvName());
|
||||
debugEnv.setUrl(apiConfig.getDebugEnvUrl());
|
||||
debugEnvs.add(debugEnv);
|
||||
}
|
||||
tornaApi.setDebugEnvs(debugEnvs);
|
||||
return hasDebugEnv;
|
||||
}
|
||||
|
||||
public static void printDebugInfo(ApiConfig apiConfig , String responseMsg, Map<String, String> requestJson) {
|
||||
if (apiConfig.isTornaDebug()) {
|
||||
String sb = "配置信息列表: \n" +
|
||||
"OpenUrl: " +
|
||||
apiConfig.getOpenUrl() +
|
||||
"\n" +
|
||||
"appToken: " +
|
||||
apiConfig.getAppToken() +
|
||||
"\n" +
|
||||
"appKey: " +
|
||||
apiConfig.getAppKey() +
|
||||
"\n" +
|
||||
"Secret: " +
|
||||
apiConfig.getSecret() +
|
||||
"\n";
|
||||
System.out.println(sb);
|
||||
JsonElement element = JsonParser.parseString(responseMsg);
|
||||
TornaRequestInfo info = new TornaRequestInfo()
|
||||
.of()
|
||||
.setCategory(PUSH)
|
||||
.setCode(element.getAsJsonObject().get(TornaConstants.CODE).getAsString())
|
||||
.setMessage(element.getAsJsonObject().get(TornaConstants.MESSAGE).getAsString())
|
||||
.setRequestInfo(requestJson)
|
||||
.setResponseInfo(responseMsg);
|
||||
System.out.println(info.buildInfo());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* build apis
|
||||
*
|
||||
* @param apiMethodDocs apiMethodDocs
|
||||
* @param hasDebugEnv has debug environment
|
||||
* @return List of Api
|
||||
*/
|
||||
public static List<Apis> buildApis(List<ApiMethodDoc> apiMethodDocs, boolean hasDebugEnv) {
|
||||
//参数列表
|
||||
List<Apis> apis = new ArrayList<>();
|
||||
Apis methodApi;
|
||||
//遍历分类接口
|
||||
for (ApiMethodDoc apiMethodDoc : apiMethodDocs) {
|
||||
/**
|
||||
* "name": "获取商品信息",
|
||||
* "description": "获取商品信息",
|
||||
* "url": "/goods/get",
|
||||
* "httpMethod": "GET",
|
||||
* "contentType": "application/json",
|
||||
* "isFolder": "1",
|
||||
* "parentId": "",
|
||||
* "isShow": "1",
|
||||
*/
|
||||
methodApi = new Apis();
|
||||
methodApi.setIsFolder(TornaConstants.NO);
|
||||
methodApi.setName(apiMethodDoc.getDesc());
|
||||
methodApi.setUrl(hasDebugEnv ? apiMethodDoc.getPath() : apiMethodDoc.getUrl());
|
||||
methodApi.setHttpMethod(apiMethodDoc.getType());
|
||||
methodApi.setContentType(apiMethodDoc.getContentType());
|
||||
methodApi.setDescription(apiMethodDoc.getDetail());
|
||||
methodApi.setIsShow(TornaConstants.YES);
|
||||
|
||||
/**
|
||||
* {
|
||||
* "name": "goodsName",
|
||||
* "type": "string",
|
||||
* "required": "1",
|
||||
* "maxLength": "128",
|
||||
* "example": "iphone12",
|
||||
* "description": "商品名称描述",
|
||||
* "parentId": "",
|
||||
* "enumInfo": {
|
||||
* "name": "支付枚举",
|
||||
* "description": "支付状态",
|
||||
* "items": [
|
||||
* {
|
||||
* "name": "WAIT_PAY",
|
||||
* "type": "string",
|
||||
* "value": "0",
|
||||
* "description": "未支付"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
methodApi.setHeaderParams(buildHerder(apiMethodDoc.getRequestHeaders()));
|
||||
methodApi.setResponseParams(buildParams(apiMethodDoc.getResponseParams()));
|
||||
//Path
|
||||
if (CollectionUtil.isNotEmpty(apiMethodDoc.getPathParams())) {
|
||||
methodApi.setPathParams(buildParams(apiMethodDoc.getPathParams()));
|
||||
}
|
||||
//formData
|
||||
if (CollectionUtil.isNotEmpty(apiMethodDoc.getQueryParams())) {
|
||||
methodApi.setRequestParams(buildParams(apiMethodDoc.getQueryParams()));
|
||||
}
|
||||
//Json
|
||||
if (CollectionUtil.isNotEmpty(apiMethodDoc.getRequestParams())) {
|
||||
methodApi.setRequestParams(buildParams(apiMethodDoc.getRequestParams()));
|
||||
}
|
||||
apis.add(methodApi);
|
||||
}
|
||||
return apis;
|
||||
}
|
||||
|
||||
/**
|
||||
* build apis
|
||||
*
|
||||
* @param apiMethodDocs apiMethodDocs
|
||||
* @return List of Api
|
||||
*/
|
||||
public static List<Apis> buildDubboApis(List<JavaMethodDoc> apiMethodDocs) {
|
||||
//参数列表
|
||||
List<Apis> apis = new ArrayList<>();
|
||||
Apis methodApi;
|
||||
//遍历分类接口
|
||||
for (JavaMethodDoc apiMethodDoc : apiMethodDocs) {
|
||||
/**
|
||||
* "name": "获取商品信息",
|
||||
* "description": "获取商品信息",
|
||||
* "url": "/goods/get",
|
||||
* "httpMethod": "GET",
|
||||
* "contentType": "application/json",
|
||||
* "isFolder": "1",
|
||||
* "parentId": "",
|
||||
* "isShow": "1",
|
||||
*/
|
||||
methodApi = new Apis();
|
||||
methodApi.setIsFolder(TornaConstants.NO);
|
||||
methodApi.setName(apiMethodDoc.getDesc());
|
||||
methodApi.setDescription(apiMethodDoc.getDetail());
|
||||
methodApi.setIsShow(TornaConstants.YES);
|
||||
methodApi.setUrl(apiMethodDoc.getMethodDefinition());
|
||||
|
||||
/**
|
||||
* {
|
||||
* "name": "goodsName",
|
||||
* "type": "string",
|
||||
* "required": "1",
|
||||
* "maxLength": "128",
|
||||
* "example": "iphone12",
|
||||
* "description": "商品名称描述",
|
||||
* "parentId": "",
|
||||
* "enumInfo": {
|
||||
* "name": "支付枚举",
|
||||
* "description": "支付状态",
|
||||
* "items": [
|
||||
* {
|
||||
* "name": "WAIT_PAY",
|
||||
* "type": "string",
|
||||
* "value": "0",
|
||||
* "description": "未支付"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
methodApi.setResponseParams(buildParams(apiMethodDoc.getResponseParams()));
|
||||
//Json
|
||||
if (CollectionUtil.isNotEmpty(apiMethodDoc.getRequestParams())) {
|
||||
methodApi.setRequestParams(buildParams(apiMethodDoc.getRequestParams()));
|
||||
}
|
||||
apis.add(methodApi);
|
||||
}
|
||||
return apis;
|
||||
}
|
||||
|
||||
/**
|
||||
* build request header
|
||||
*
|
||||
* @param apiReqHeaders 请求头参数列表
|
||||
* @return List of HttpParam
|
||||
*/
|
||||
public static List<HttpParam> buildHerder(List<ApiReqHeader> apiReqHeaders) {
|
||||
/**
|
||||
* name": "token",
|
||||
* "required": "1",
|
||||
* "example": "iphone12",
|
||||
* "description": "商品名称描述"
|
||||
*/
|
||||
HttpParam httpParam;
|
||||
List<HttpParam> headers = new ArrayList<>();
|
||||
for (ApiReqHeader header : apiReqHeaders) {
|
||||
httpParam = new HttpParam();
|
||||
httpParam.setName(header.getName());
|
||||
httpParam.setRequired(header.isRequired() ? TornaConstants.YES : TornaConstants.NO);
|
||||
httpParam.setExample(StringUtil.removeQuotes(header.getValue()));
|
||||
httpParam.setDescription(header.getDesc());
|
||||
headers.add(httpParam);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* build request response params
|
||||
*
|
||||
* @param apiParams 参数列表
|
||||
* @return List of HttpParam
|
||||
*/
|
||||
public static List<HttpParam> buildParams(List<ApiParam> apiParams) {
|
||||
HttpParam httpParam;
|
||||
List<HttpParam> bodies = new ArrayList<>();
|
||||
/**
|
||||
* "name": "goodsName",
|
||||
* "type": "string",
|
||||
* "required": "1",
|
||||
* "maxLength": "128",
|
||||
* "example": "iphone12",
|
||||
* "description": "商品名称描述",
|
||||
* "parentId": "",
|
||||
* "enumInfo": {
|
||||
* "name": "支付枚举",
|
||||
* "description": "支付状态",
|
||||
* "items": [
|
||||
* {
|
||||
* "name": "WAIT_PAY",
|
||||
* "type": "string",
|
||||
* "value": "0",
|
||||
* "description": "未支付"
|
||||
*/
|
||||
for (ApiParam apiParam : apiParams) {
|
||||
httpParam = new HttpParam();
|
||||
httpParam.setName(apiParam.getField());
|
||||
httpParam.setMaxLength(apiParam.getMaxLength());
|
||||
httpParam.setType(apiParam.getType());
|
||||
httpParam.setRequired(apiParam.isRequired() ? TornaConstants.YES : TornaConstants.NO);
|
||||
httpParam.setExample(StringUtil.removeQuotes(apiParam.getValue()));
|
||||
httpParam.setDescription(apiParam.getDesc());
|
||||
if (apiParam.getChildren() != null) {
|
||||
httpParam.setChildren(buildParams(apiParam.getChildren()));
|
||||
}
|
||||
bodies.add(httpParam);
|
||||
}
|
||||
return bodies;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue