Fix the bug that the file upload interface pushes to Torna

This commit is contained in:
shalousun 2021-10-30 17:20:48 +08:00
parent 6d993ed2a4
commit d65938c63e
3 changed files with 21 additions and 19 deletions

View File

@ -41,7 +41,6 @@ import java.util.*;
*/ */
public class OpenApiBuilder { public class OpenApiBuilder {
//过滤url中的特殊字符
private static final String PATH_REGEX = "[/{};\\t+]"; private static final String PATH_REGEX = "[/{};\\t+]";
/** /**
@ -95,9 +94,9 @@ public class OpenApiBuilder {
} }
/** /**
* info 信息 * Build openapi info
* *
* @param apiConfig 文档配置信息 * @param apiConfig ApiConfig
* @return * @return
*/ */
private static Map<String, Object> buildInfo(ApiConfig apiConfig) { private static Map<String, Object> buildInfo(ApiConfig apiConfig) {
@ -108,9 +107,9 @@ public class OpenApiBuilder {
} }
/** /**
* server 信息 * Build Servers
* *
* @param config 文档配置信息 * @param config ApiConfig
* @return * @return
*/ */
private static List<Map<String, Object>> buildServers(ApiConfig config) { private static List<Map<String, Object>> buildServers(ApiConfig config) {
@ -122,9 +121,9 @@ public class OpenApiBuilder {
} }
/** /**
* 构建path数据 url请求 * Build openapi paths
* *
* @param apiDocList api列表 * @param apiDocList List of api
* @return * @return
*/ */
private static Map<String, Object> buildPaths(List<ApiDoc> apiDocList) { private static Map<String, Object> buildPaths(List<ApiDoc> apiDocList) {
@ -134,7 +133,7 @@ public class OpenApiBuilder {
List<ApiMethodDoc> apiMethodDocs = a.getList(); List<ApiMethodDoc> apiMethodDocs = a.getList();
apiMethodDocs.forEach( apiMethodDocs.forEach(
method -> { method -> {
//设置paths的请求url 将双斜杠替换成单斜杠 //replace '//' to '/'
String url = method.getPath().replace("//", "/"); String url = method.getPath().replace("//", "/");
Map<String, Object> request = buildPathUrls(method, a); Map<String, Object> request = buildPathUrls(method, a);
//pathMap.put(method.getPath().replace("//", "/"), buildPathUrls(method, a)); //pathMap.put(method.getPath().replace("//", "/"), buildPathUrls(method, a));
@ -152,10 +151,10 @@ public class OpenApiBuilder {
} }
/** /**
* paths 设置url请求方式 * Build path urls
* *
* @param apiMethodDoc 方法参数 * @param apiMethodDoc Method
* @param apiDoc 类参数 * @param apiDoc ApiDoc
* @return * @return
*/ */
private static Map<String, Object> buildPathUrls(ApiMethodDoc apiMethodDoc, ApiDoc apiDoc) { private static Map<String, Object> buildPathUrls(ApiMethodDoc apiMethodDoc, ApiDoc apiDoc) {
@ -189,9 +188,9 @@ public class OpenApiBuilder {
} }
/** /**
* 请求体构建 只针对post请求 并且请求体不为null * Build request body
* *
* @param apiMethodDoc 方法参数 * @param apiMethodDoc ApiMethodDoc
* @return * @return
*/ */
private static Map<String, Object> buildRequestBody(ApiMethodDoc apiMethodDoc) { private static Map<String, Object> buildRequestBody(ApiMethodDoc apiMethodDoc) {
@ -199,7 +198,7 @@ public class OpenApiBuilder {
boolean isPost = (apiMethodDoc.getType().equals(Methods.POST.getValue()) boolean isPost = (apiMethodDoc.getType().equals(Methods.POST.getValue())
|| apiMethodDoc.getType().equals(Methods.PUT.getValue()) || || apiMethodDoc.getType().equals(Methods.PUT.getValue()) ||
apiMethodDoc.getType().equals(Methods.PATCH.getValue())); apiMethodDoc.getType().equals(Methods.PATCH.getValue()));
//如果是post请求 且包含请求体 //add content of post method
if (isPost) { if (isPost) {
requestBody.put("content", buildContent(apiMethodDoc, false)); requestBody.put("content", buildContent(apiMethodDoc, false));
return requestBody; return requestBody;

View File

@ -30,12 +30,10 @@ import com.power.doc.constants.TornaConstants;
import com.power.doc.factory.BuildTemplateFactory; import com.power.doc.factory.BuildTemplateFactory;
import com.power.doc.model.ApiConfig; import com.power.doc.model.ApiConfig;
import com.power.doc.model.ApiDoc; import com.power.doc.model.ApiDoc;
import com.power.doc.model.ApiGroup;
import com.power.doc.model.torna.Apis; import com.power.doc.model.torna.Apis;
import com.power.doc.model.torna.TornaApi; import com.power.doc.model.torna.TornaApi;
import com.power.doc.model.torna.TornaDic; import com.power.doc.model.torna.TornaDic;
import com.power.doc.template.IDocBuildTemplate; import com.power.doc.template.IDocBuildTemplate;
import com.power.doc.template.SpringBootDocBuildTemplate;
import com.power.doc.utils.DocUtil; import com.power.doc.utils.DocUtil;
import com.power.doc.utils.TornaUtil; import com.power.doc.utils.TornaUtil;
import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.JavaProjectBuilder;
@ -93,7 +91,7 @@ public class TornaBuilder {
* @param builder JavaProjectBuilder * @param builder JavaProjectBuilder
*/ */
public static void buildTorna(List<ApiDoc> apiDocs, ApiConfig apiConfig, JavaProjectBuilder builder) { public static void buildTorna(List<ApiDoc> apiDocs, ApiConfig apiConfig, JavaProjectBuilder builder) {
TornaApi tornaApi = new TornaApi(); TornaApi tornaApi = new TornaApi();
tornaApi.setAuthor(StringUtil.isEmpty(apiConfig.getAuthor()) ? System.getProperty("user.name") : apiConfig.getAuthor()); tornaApi.setAuthor(StringUtil.isEmpty(apiConfig.getAuthor()) ? System.getProperty("user.name") : apiConfig.getAuthor());
tornaApi.setIsReplace((apiConfig.getReplace() == null || apiConfig.getReplace()) ? 1 : 0); tornaApi.setIsReplace((apiConfig.getReplace() == null || apiConfig.getReplace()) ? 1 : 0);
Apis api; Apis api;

View File

@ -5,6 +5,7 @@ import com.google.gson.JsonParser;
import com.power.common.model.EnumDictionary; import com.power.common.model.EnumDictionary;
import com.power.common.util.CollectionUtil; import com.power.common.util.CollectionUtil;
import com.power.common.util.StringUtil; import com.power.common.util.StringUtil;
import com.power.doc.constants.DocGlobalConstants;
import com.power.doc.constants.TornaConstants; import com.power.doc.constants.TornaConstants;
import com.power.doc.model.*; import com.power.doc.model.*;
import com.power.doc.model.rpc.RpcApiDependency; import com.power.doc.model.rpc.RpcApiDependency;
@ -98,8 +99,12 @@ public class TornaUtil {
if (CollectionUtil.isNotEmpty(apiMethodDoc.getPathParams())) { if (CollectionUtil.isNotEmpty(apiMethodDoc.getPathParams())) {
methodApi.setPathParams(buildParams(apiMethodDoc.getPathParams())); methodApi.setPathParams(buildParams(apiMethodDoc.getPathParams()));
} }
//formData
if (CollectionUtil.isNotEmpty(apiMethodDoc.getQueryParams())) { if (CollectionUtil.isNotEmpty(apiMethodDoc.getQueryParams())
&& DocGlobalConstants.MULTIPART_TYPE.equals(apiMethodDoc.getContentType())) {
// file upload
methodApi.setRequestParams(buildParams(apiMethodDoc.getQueryParams()));
} else if (CollectionUtil.isNotEmpty(apiMethodDoc.getQueryParams())) {
methodApi.setQueryParams(buildParams(apiMethodDoc.getQueryParams())); methodApi.setQueryParams(buildParams(apiMethodDoc.getQueryParams()));
} }
//Json //Json