Skip to content

Commit

Permalink
- 新增实体分开呈现
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzhihang committed Mar 25, 2024
1 parent 1ab4f3f commit a519fbf
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 655 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## [Unreleased]

## 1.3.7
## 1.3.8

### Added

- 参数类分开展示

### Changed

### Deprecated
Expand All @@ -12,6 +14,4 @@

### Fixed

- IDEA-2023.3 ReadWriteLock 异常

### Security
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.caching=true
# ????
pluginGroup=com.liuzhihang.toolkit
pluginName=Doc View
pluginVersion=1.3.7
pluginVersion=1.3.8
pluginSinceBuild=223.0
pluginUntilBuild=
pluginDescription=parts/description.html
Expand Down
14 changes: 2 additions & 12 deletions parts/description.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ <h1>Generate Markdown documents based on the interface</h1>
<br/>

<ul>
<li>Controller/Dubbo interface to generate Markdown documents</li>
<li>Supports viewing Markdown source code, previewing Markdown, editing interface fields, etc.</li>
<li>Support custom configuration Markdown template</li>
<li>Support exporting Markdown files to local</li>
<li>Support uploading interface documents to YApi,ShowDoc,Yuque</li>
<li>Generate Http Client</li>
<li>Supports separate display of parameter classes</li>
</ul>
<br/>

Expand All @@ -36,12 +31,7 @@ <h1>Generate Markdown documents based on the interface</h1>
<br/>
<br/>
<ul>
<li>Controller/Dubbo 接口生成Markdown文档</li>
<li>支持查看 Markdown 源码, 预览 Markdown, 编辑接口字段等</li>
<li>支持自定义配置 Markdown 模版</li>
<li>支持导出 Markdown 文件到本地</li>
<li>支持上传到 YApi、ShowDoc、语雀</li>
<li>生成 Http Client</li>
<li>支持参数类分开展示</li>
</ul>
<br/>

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/liuzhihang/doc/view/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public class Settings implements PersistentStateComponent<Settings> {
private String prefixSymbol1 = "";
private String prefixSymbol2 = "-->";

/**
* 实体独立
*/
private Boolean separateParam = false;


public static Settings getInstance(@NotNull Project project) {
return project.getService(Settings.class);
Expand Down
52 changes: 49 additions & 3 deletions src/main/java/com/liuzhihang/doc/view/dto/DocViewData.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class DocViewData {
* 返回参数
*/
private final List<DocViewParamData> responseParamDataList;
private final String responseParam;
private final String responseParam;

/**
* 返回示例
Expand All @@ -95,6 +95,8 @@ public class DocViewData {

public DocViewData(DocView docView) {

Settings settings = Settings.getInstance(docView.getPsiClass().getProject());

this.name = docView.getName();
this.desc = docView.getDesc();
this.path = docView.getPath();
Expand All @@ -108,11 +110,11 @@ public DocViewData(DocView docView) {
this.requestParam = paramMarkdown(requestParamDataList);

this.requestBodyDataList = buildBodyDataList(docView.getReqBody().getChildList());
this.requestBody = paramMarkdown(requestBodyDataList);
this.requestBody = settings.getSeparateParam() ? separateParamMarkdown(requestBodyDataList) : paramMarkdown(requestBodyDataList);
this.requestExample = requestExample(docView);

this.responseParamDataList = buildBodyDataList(docView.getRespBody().getChildList());
this.responseParam = paramMarkdown(responseParamDataList);
this.responseParam = settings.getSeparateParam() ? separateParamMarkdown(responseParamDataList) : paramMarkdown(responseParamDataList);
this.responseExample = respBodyExample(docView.getRespExample());

}
Expand Down Expand Up @@ -153,6 +155,50 @@ private static String paramMarkdown(List<DocViewParamData> dataList) {
+ paramMarkdownContent(dataList);
}

/**
* 切分多个展示
*/
private static String separateParamMarkdown(List<DocViewParamData> dataList) {
if (CollectionUtils.isEmpty(dataList)) {
return "";
}
List<DocViewParamData> paramDataList = new ArrayList<>();

StringBuilder builder = new StringBuilder();
builder.append("|参数名|类型|必选|描述|\n")
.append("|:-----|:-----|:-----|:-----|\n");
for (DocViewParamData data : dataList) {
builder.append("|").append(data.getName())
.append("|").append(data.getType())
.append("|").append(data.getRequired() ? "Y" : "N")
.append("|").append(data.getDesc())
.append("|").append("\n");
if (CollectionUtils.isNotEmpty(data.getChildList())) {
paramDataList.add(data);
}
}
builder.append(separateSubParamMarkdown(paramDataList));
return builder.toString();
}

/**
* 构造子的参数 Markdown 实体
*/
private static String separateSubParamMarkdown(List<DocViewParamData> dataList) {
if (CollectionUtils.isEmpty(dataList)) {
return "";
}

StringBuilder builder = new StringBuilder();
for (DocViewParamData data : dataList) {
builder.append("\n- ").append(data.getType()).append(" ").append(data.getName()).append("\n\n");
builder.append(separateParamMarkdown(data.getChildList()));
}

return builder.toString();
}


/**
* 表格内数据
*/
Expand Down
171 changes: 0 additions & 171 deletions src/main/java/com/liuzhihang/doc/view/ui/DocEditor.form

This file was deleted.

Loading

0 comments on commit a519fbf

Please sign in to comment.