Skip to content

Commit

Permalink
Merge pull request #59 from liuzhihang/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
liuzhihang authored Jul 10, 2022
2 parents 9846615 + acfa666 commit 9ce7fc2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.intellij.psi.util.PsiTreeUtil;
import com.liuzhihang.doc.view.DocViewBundle;
import com.liuzhihang.doc.view.config.Settings;
import com.liuzhihang.doc.view.dto.Body;
import com.liuzhihang.doc.view.dto.DocView;
import com.liuzhihang.doc.view.notification.DocViewNotification;
import com.liuzhihang.doc.view.service.DocViewService;
Expand Down Expand Up @@ -89,13 +90,42 @@ private LineMarkerInfo<PsiElement> createMethodLineMarker(PsiElement element) {
// 在点击图标时再解析 doc
DocView docView = docViewService.buildClassMethodDoc(project, psiClass, psiMethod);
List<DocView> docViewList = new LinkedList<>();
cleanElement(docView);
docViewList.add(docView);
PreviewForm.getInstance(project, psiFile, psiClass, docViewList).popup();
},
GutterIconRenderer.Alignment.LEFT,
() -> "Doc View");
}

private void cleanElement(DocView docView) {
Body respBody = docView.getRespBody();
doCleanElement(respBody, null);
}

/**
* 实现删除{@code element}元素,
* 并将{@code element}元素的子元素添加到{@code element}的{@code parent}下面。
* <p>
* 按照目前实现逻辑{@code element}元素不会有其他兄弟。
* 避免{@code element}会有兄弟接口使用先删除{@code element}然后将{@code element}的子元素添加到其所在集合
*/
private void doCleanElement(Body body, Body parent) {
String name = body.getName();
if ("element".equals(name)) {
List<Body> newChildList = body.getChildList();
parent.getChildList().remove(body);
parent.getChildList().addAll(newChildList);
}
List<Body> curChildList = body.getChildList();
if (null == curChildList || curChildList.size() == 0) {
return;
}
for (int i = 0; i < body.getChildList().size(); i++) {
doCleanElement(body.getChildList().get(i), body);
}
}

@Nullable
private DocViewService checkShowLineMarker(Project project, PsiClass psiClass) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void doUpload(@NotNull Project project, @NotNull DocView docView) {
save.setPath(docView.getPath());
}
// 枚举: raw,form,json
save.setReqBodyType(docView.getContentType().toString());
save.setReqBodyType(docView.getContentType().toString().toLowerCase());
save.setReqBodyForm(new ArrayList<>());
save.setReqParams(new ArrayList<>());
save.setReqHeaders(buildReqHeaders(docView.getHeaderList()));
Expand Down Expand Up @@ -124,9 +124,6 @@ public void doUpload(@NotNull Project project, @NotNull DocView docView) {

/**
* 构造描述信息
*
* @param docView
* @return
*/
@NotNull
private String buildDesc(DocView docView) {
Expand Down Expand Up @@ -156,9 +153,6 @@ private String buildDesc(DocView docView) {
* properties: 字段列表
* <p>
* items: 数组类型时内部元素
*
* @param bodyList
* @return
*/
private String buildJsonSchema(List<Body> bodyList) {

Expand Down

0 comments on commit 9ce7fc2

Please sign in to comment.