修复文档显示BUG

1.x
tanghc 6 years ago
parent cb6bdcc22c
commit 0a7bd3d23e
  1. 8
      sop-website/website-front/pages/doc/doc.js
  2. 17
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/DocManagerImpl.java
  3. 6
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java

@ -183,7 +183,13 @@ layui.config({
function buildExample(parameter) { function buildExample(parameter) {
var refs = parameter.refs; var refs = parameter.refs;
if (refs) { if (refs) {
return '{' + buildResult(refs) + '}'; // {...}
var content = '{' + buildResult(refs) + '}';
if (parameter.type == 'array') {
// [{...}]
content = '[' + content + ']';
}
return content;
} else { } else {
return '\"' + parameter.example + '\"'; return '\"' + parameter.example + '\"';
} }

@ -2,6 +2,7 @@ package com.gitee.sop.websiteserver.manager;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.gitee.sop.websiteserver.bean.DocInfo; import com.gitee.sop.websiteserver.bean.DocInfo;
import com.gitee.sop.websiteserver.bean.DocItem; import com.gitee.sop.websiteserver.bean.DocItem;
import com.gitee.sop.websiteserver.bean.EurekaApplication; import com.gitee.sop.websiteserver.bean.EurekaApplication;
@ -76,13 +77,17 @@ public class DocManagerImpl implements DocManager {
@Override @Override
public void load() { public void load() {
try { try {
// {"STORY-SERVICE":[{"ipAddr":"10.1.30.54","name":"STORY-SERVICE","serverPort":"2222"}],"API-GATEWAY":[{"ipAddr":"10.1.30.54","name":"API-GATEWAY","serverPort":"8081"}]}
Map<String, List<ServiceInfoVO>> listMap = this.getAllServiceList(); Map<String, List<ServiceInfoVO>> listMap = this.getAllServiceList();
log.info("服务列表:{}", JSON.toJSONString(listMap.keySet())); log.info("服务列表:{}", JSON.toJSONString(listMap.keySet()));
// {"STORY-SERVICE":[{"ipAddr":"10.1.30.54","name":"STORY-SERVICE","serverPort":"2222"}],"API-GATEWAY":[{"ipAddr":"10.1.30.54","name":"API-GATEWAY","serverPort":"8081"}]} listMap.entrySet()
for (Map.Entry<String, List<ServiceInfoVO>> entry : listMap.entrySet()) { .stream()
ServiceInfoVO serviceInfoVo = entry.getValue().get(0); // 网关没有文档提供,需要排除
loadDocInfo(serviceInfoVo); .filter(entry -> !"API-GATEWAY".equalsIgnoreCase(entry.getKey()))
} .forEach(entry -> {
ServiceInfoVO serviceInfoVo = entry.getValue().get(0);
loadDocInfo(serviceInfoVo);
});
} catch (Exception e) { } catch (Exception e) {
log.error("加载失败", e); log.error("加载失败", e);
} }
@ -97,7 +102,7 @@ public class DocManagerImpl implements DocManager {
throw new IllegalAccessException("无权访问"); throw new IllegalAccessException("无权访问");
} }
String docInfoJson = entity.getBody(); String docInfoJson = entity.getBody();
JSONObject docRoot = JSON.parseObject(docInfoJson); JSONObject docRoot = JSON.parseObject(docInfoJson, Feature.OrderedField);
DocParser docParser = this.buildDocParser(docRoot); DocParser docParser = this.buildDocParser(docRoot);
DocInfo docInfo = docParser.parseJson(docRoot); DocInfo docInfo = docParser.parseJson(docRoot);
docDefinitionMap.put(docInfo.getTitle(), docInfo); docDefinitionMap.put(docInfo.getTitle(), docInfo);

@ -154,7 +154,7 @@ public class SwaggerDocParser implements DocParser {
DocParameter respParam = fieldInfo.toJavaObject(DocParameter.class); DocParameter respParam = fieldInfo.toJavaObject(DocParameter.class);
respParam.setName(fieldName); respParam.setName(fieldName);
docParameterList.add(respParam); docParameterList.add(respParam);
String originalRef = getRef(fieldInfo); String originalRef = isArray(fieldInfo) ? getRef(fieldInfo.getJSONObject(fieldName)) : getRef(fieldInfo);
if (StringUtils.isNotBlank(originalRef)) { if (StringUtils.isNotBlank(originalRef)) {
List<DocParameter> refs = buildDocParameters(originalRef, docRoot); List<DocParameter> refs = buildDocParameters(originalRef, docRoot);
respParam.setRefs(refs); respParam.setRefs(refs);
@ -163,6 +163,10 @@ public class SwaggerDocParser implements DocParser {
return docParameterList; return docParameterList;
} }
protected boolean isArray(JSONObject fieldInfo) {
return "array".equalsIgnoreCase(fieldInfo.getString("type"));
}
private String getRef(JSONObject fieldInfo) { private String getRef(JSONObject fieldInfo) {
return Optional.ofNullable(fieldInfo) return Optional.ofNullable(fieldInfo)
.map(jsonObject -> jsonObject.getString("originalRef")) .map(jsonObject -> jsonObject.getString("originalRef"))

Loading…
Cancel
Save