pull/1/head
tanghc 5 years ago
parent efaf35ea7c
commit 1b30e5ae97
  1. 14
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/DocumentationPluginsManagerExt.java
  2. 2
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/DownloadController.java
  3. 2
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/FileUploadDemoController.java
  4. 2
      sop-website/src/main/java/com/gitee/sop/websiteserver/bean/DocItem.java
  5. 1
      sop-website/src/main/java/com/gitee/sop/websiteserver/bean/DocModule.java
  6. 20
      sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java
  7. 2
      sop-website/src/main/resources/public/pages/doc/doc.js

@ -5,6 +5,8 @@ import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.servercommon.bean.ServiceConfig; import com.gitee.sop.servercommon.bean.ServiceConfig;
import com.gitee.sop.servercommon.mapping.RouteUtil; import com.gitee.sop.servercommon.mapping.RouteUtil;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import io.swagger.annotations.Api;
import org.springframework.core.annotation.Order;
import springfox.documentation.service.Operation; import springfox.documentation.service.Operation;
import springfox.documentation.service.StringVendorExtension; import springfox.documentation.service.StringVendorExtension;
import springfox.documentation.service.VendorExtension; import springfox.documentation.service.VendorExtension;
@ -20,6 +22,7 @@ public class DocumentationPluginsManagerExt extends DocumentationPluginsManager
public static final String SOP_NAME = "sop_name"; public static final String SOP_NAME = "sop_name";
public static final String SOP_VERSION = "sop_version"; public static final String SOP_VERSION = "sop_version";
public static final String MODULE_ORDER = "module_order";
@Override @Override
public Operation operation(OperationContext operationContext) { public Operation operation(OperationContext operationContext) {
@ -48,6 +51,17 @@ public class DocumentationPluginsManagerExt extends DocumentationPluginsManager
vendorExtensions.add(new StringVendorExtension(SOP_VERSION, version)); vendorExtensions.add(new StringVendorExtension(SOP_VERSION, version));
} }
} }
Optional<Api> apiOptional = operationContext.findControllerAnnotation(Api.class);
int order = 0;
if (apiOptional.isPresent()) {
order = apiOptional.get().position();
} else {
Optional<Order> orderOptional = operationContext.findControllerAnnotation(Order.class);
if (orderOptional.isPresent()) {
order = orderOptional.get().value();
}
}
vendorExtensions.add(new StringVendorExtension(MODULE_ORDER, String.valueOf(order)));
} }
private String buildVersion(String version) { private String buildVersion(String version) {

@ -18,7 +18,7 @@ import java.io.IOException;
* *
* @author tanghc * @author tanghc
*/ */
@Api(tags = "文件下载") @Api(tags = "文件下载", position = 3)
@Controller @Controller
public class DownloadController { public class DownloadController {

@ -23,7 +23,7 @@ import java.util.Collection;
* @author tanghc * @author tanghc
*/ */
@RestController @RestController
@Api(tags = "文件上传") @Api(tags = "文件上传", position = 2)
public class FileUploadDemoController { public class FileUploadDemoController {
/** /**

@ -22,7 +22,7 @@ public class DocItem {
private Collection<String> produces; private Collection<String> produces;
private int moduleOrder;
List<DocParameter> requestParameters; List<DocParameter> requestParameters;
List<DocParameter> responseParameters; List<DocParameter> responseParameters;

@ -11,4 +11,5 @@ import java.util.List;
public class DocModule { public class DocModule {
private String module; private String module;
private List<DocItem> docItems; private List<DocItem> docItems;
private int order;
} }

@ -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);

@ -48,7 +48,7 @@ layui.config({
html.push('<li><h2>' + module.module + '</h2></li>'); html.push('<li><h2>' + module.module + '</h2></li>');
for (var i = 0; i < docItems.length; i++) { for (var i = 0; i < docItems.length; i++) {
var docItem = docItems[i]; var docItem = docItems[i];
var first = j == 0 && j == 0; var first = j === 0 && i === 0;
if (first) { if (first) {
firstItem = docItem; firstItem = docItem;
} }

Loading…
Cancel
Save