|
|
@ -8,11 +8,14 @@ import com.gitee.sop.websiteserver.bean.DocModule; |
|
|
|
import com.gitee.sop.websiteserver.bean.DocParameter; |
|
|
|
import com.gitee.sop.websiteserver.bean.DocParameter; |
|
|
|
import com.gitee.sop.websiteserver.bean.DocParserContext; |
|
|
|
import com.gitee.sop.websiteserver.bean.DocParserContext; |
|
|
|
import com.google.common.collect.Sets; |
|
|
|
import com.google.common.collect.Sets; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.math.NumberUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
@ -55,20 +58,30 @@ public class SwaggerDocParser implements DocParser { |
|
|
|
.entrySet() |
|
|
|
.entrySet() |
|
|
|
.stream() |
|
|
|
.stream() |
|
|
|
.map(entry -> { |
|
|
|
.map(entry -> { |
|
|
|
|
|
|
|
List<DocItem> docItemList = entry.getValue(); |
|
|
|
DocModule docModule = new DocModule(); |
|
|
|
DocModule docModule = new DocModule(); |
|
|
|
docModule.setModule(entry.getKey()); |
|
|
|
docModule.setModule(entry.getKey()); |
|
|
|
docModule.setDocItems(entry.getValue()); |
|
|
|
docModule.setDocItems(docItemList); |
|
|
|
|
|
|
|
docModule.setOrder(getMuduleOrder(docItemList)); |
|
|
|
return docModule; |
|
|
|
return docModule; |
|
|
|
}) |
|
|
|
}).sorted(Comparator.comparing(DocModule::getOrder)) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DocInfo docInfo = new DocInfo(); |
|
|
|
DocInfo docInfo = new DocInfo(); |
|
|
|
docInfo.setTitle(title); |
|
|
|
docInfo.setTitle(title); |
|
|
|
docInfo.setDocModuleList(docModuleList); |
|
|
|
docInfo.setDocModuleList(docModuleList); |
|
|
|
return docInfo; |
|
|
|
return docInfo; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getMuduleOrder(List<DocItem> items) { |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(items)) { |
|
|
|
|
|
|
|
return Integer.MAX_VALUE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<DocItem> docItemList = new ArrayList<>(items); |
|
|
|
|
|
|
|
docItemList.sort(Comparator.comparing(DocItem::getModuleOrder)); |
|
|
|
|
|
|
|
return docItemList.get(0).getModuleOrder(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Collection<String> getHttpMethods(JSONObject pathInfo) { |
|
|
|
protected Collection<String> getHttpMethods(JSONObject pathInfo) { |
|
|
|
// key: get,post,head...
|
|
|
|
// key: get,post,head...
|
|
|
|
List<String> retList; |
|
|
|
List<String> retList; |
|
|
@ -93,6 +106,7 @@ public class SwaggerDocParser implements DocParser { |
|
|
|
docItem.setDescription(docInfo.getString("description")); |
|
|
|
docItem.setDescription(docInfo.getString("description")); |
|
|
|
docItem.setMultiple(docInfo.getString("multiple") != null); |
|
|
|
docItem.setMultiple(docInfo.getString("multiple") != null); |
|
|
|
docItem.setProduces(docInfo.getJSONArray("produces").toJavaList(String.class)); |
|
|
|
docItem.setProduces(docInfo.getJSONArray("produces").toJavaList(String.class)); |
|
|
|
|
|
|
|
docItem.setModuleOrder(NumberUtils.toInt(docInfo.getString("module_order"), 0)); |
|
|
|
String moduleName = this.buildModuleName(docInfo, docRoot); |
|
|
|
String moduleName = this.buildModuleName(docInfo, docRoot); |
|
|
|
docItem.setModule(moduleName); |
|
|
|
docItem.setModule(moduleName); |
|
|
|
List<DocParameter> docParameterList = this.buildRequestParameterList(docInfo, docRoot); |
|
|
|
List<DocParameter> docParameterList = this.buildRequestParameterList(docInfo, docRoot); |
|
|
|