diff --git a/src/main/java/com/liuzhihang/doc/view/provider/DocViewLineMarkerProvider.java b/src/main/java/com/liuzhihang/doc/view/provider/DocViewLineMarkerProvider.java index 1d45f91..aebf180 100644 --- a/src/main/java/com/liuzhihang/doc/view/provider/DocViewLineMarkerProvider.java +++ b/src/main/java/com/liuzhihang/doc/view/provider/DocViewLineMarkerProvider.java @@ -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; @@ -89,6 +90,7 @@ private LineMarkerInfo createMethodLineMarker(PsiElement element) { // 在点击图标时再解析 doc DocView docView = docViewService.buildClassMethodDoc(project, psiClass, psiMethod); List docViewList = new LinkedList<>(); + cleanElement(docView); docViewList.add(docView); PreviewForm.getInstance(project, psiFile, psiClass, docViewList).popup(); }, @@ -96,6 +98,34 @@ private LineMarkerInfo createMethodLineMarker(PsiElement element) { () -> "Doc View"); } + private void cleanElement(DocView docView) { + Body respBody = docView.getRespBody(); + doCleanElement(respBody, null); + } + + /** + * 实现删除{@code element}元素, + * 并将{@code element}元素的子元素添加到{@code element}的{@code parent}下面。 + *

+ * 按照目前实现逻辑{@code element}元素不会有其他兄弟。 + * 避免{@code element}会有兄弟接口使用先删除{@code element}然后将{@code element}的子元素添加到其所在集合 + */ + private void doCleanElement(Body body, Body parent) { + String name = body.getName(); + if ("element".equals(name)) { + List newChildList = body.getChildList(); + parent.getChildList().remove(body); + parent.getChildList().addAll(newChildList); + } + List 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) { diff --git a/src/main/java/com/liuzhihang/doc/view/service/impl/YApiServiceImpl.java b/src/main/java/com/liuzhihang/doc/view/service/impl/YApiServiceImpl.java index fc6de58..78f400d 100644 --- a/src/main/java/com/liuzhihang/doc/view/service/impl/YApiServiceImpl.java +++ b/src/main/java/com/liuzhihang/doc/view/service/impl/YApiServiceImpl.java @@ -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())); @@ -124,9 +124,6 @@ public void doUpload(@NotNull Project project, @NotNull DocView docView) { /** * 构造描述信息 - * - * @param docView - * @return */ @NotNull private String buildDesc(DocView docView) { @@ -156,9 +153,6 @@ private String buildDesc(DocView docView) { * properties: 字段列表 *

* items: 数组类型时内部元素 - * - * @param bodyList - * @return */ private String buildJsonSchema(List bodyList) {