Skip to content

Commit

Permalink
fix(eolink): repair upload to eolink
Browse files Browse the repository at this point in the history
  • Loading branch information
lkqm committed Oct 10, 2023
1 parent 5c8d7d4 commit 1279549
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 84 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
<img src="docs/screenshots.gif" height="360">

## 使用
1. 安装: 打开Idea -> File -> Settings -> Plugins, 搜索: Apidocx(原名: Yapi X)

1. 安装: 打开Idea -> File -> Settings -> Plugins, 搜索: Apidocx
2. 配置: 项目根目录创建".yapix"文件, 内容: yapiProjectId=110
3. 上传: 光标放置在你的控制类或方法,右键执行: Upload To YApi ( 提示:如果未填登录信息,会弹窗提示 )

更多:[十分钟使用指南](docs/GUIDE.md)

## 交流
欢迎提出您的发现问题、需求、建议、以及提交代码来参与贡献。
- QQ交流群:860701800

提示:如果您准备为该插件开发一个新功能,请先通过issues讨论,避免重复开发。

Expand Down
2 changes: 1 addition & 1 deletion docs/GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
|:---------------------|:------------------|:------------------------------------------------|:-----------------------------------------------|
| yapiProjectId | integer | YApi项目id |
| rap2ProjectId | integer | Rap2项目id |
| eolinkerProjectId | string | Eolinker项目id |
| eolinkProjectId | string | Eolink项目id |
| showdocProjectId | string | ShowDoc项目id |
| | | |
| yapiUrl | string | YApi服务地址 | 场景:插件无法支持YApi统一登录方式,此时可使用项目token方式 |
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/apidocx/action/AbstractAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void run(@NotNull ProgressIndicator indicator) {
if (urls != null && !urls.isEmpty()) {
ApiUploadResult uploadResult = urls.get(0);
String url = urls.size() == 1 ? uploadResult.getApiUrl() : uploadResult.getCategoryUrl();
if (url != null && url.length() > 0) {
if (url != null && !url.isEmpty()) {
notifyInfo("Upload successful", format("<a href=\"%s\">%s</a>", url, url));
} else {
notifyInfo("Upload successful");
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/io/apidocx/base/sdk/eolink/EolinkApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.apidocx.base.sdk.eolink.request.LoginRequest;
import io.apidocx.base.sdk.eolink.request.LoginResponseData;
import io.apidocx.base.sdk.eolink.request.SsoResponse;
import java.net.URI;
import java.util.Map;


Expand All @@ -35,9 +34,9 @@ static Feign.Builder feignBuilder() {
/**
* 登录
*/
@RequestLine("POST")
@RequestLine("POST /userCenter/common/sso/login")
@Headers("Content-Type: application/json")
SsoResponse<LoginResponseData> login(URI uri, LoginRequest request);
SsoResponse<LoginResponseData> login(LoginRequest request);

/**
* 获取当前登录用户信息
Expand All @@ -54,13 +53,13 @@ static Feign.Builder feignBuilder() {
/**
* 获取分组列表
*/
@RequestLine("GET /api/apiManagementPro/ApiGroup/getApiGroupData")
@RequestLine("POST /api/apiManagementPro/ApiGroup/getApiGroupData")
GroupListResponse getGroupList(GroupListRequest request);

/**
* 获取接口列表
*/
@RequestLine("GET /api/apiManagementPro/Api/getApiListByCondition")
@RequestLine("POST /api/apiManagementPro/Api/getApiListByCondition")
ApiListResponse getApiList(ApiListRequest request);

/**
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/io/apidocx/base/sdk/eolink/EolinkClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.apidocx.base.sdk.eolink.request.TestResult;
import io.apidocx.base.sdk.eolink.request.TestResult.Code;
import io.apidocx.base.sdk.eolink.util.ApiConverter;
import java.net.URI;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -38,7 +37,6 @@ public class EolinkClient {

private final EolinkApi eolinkApi;

private final String loginUrl;

/**
* 服务地址
Expand All @@ -60,11 +58,10 @@ public class EolinkClient {

private UserInfo userInfo;

public EolinkClient(String url, String loginUrl, String account, String password, String accessToken) {
public EolinkClient(String url, String account, String password, String accessToken) {
checkArgument(StringUtils.isNotEmpty(url), "url can't be null");
checkArgument(StringUtils.isNotEmpty(account), "account can't be null");
checkArgument(StringUtils.isNotEmpty(password), "password can't be null");
this.loginUrl = loginUrl;
this.url = url;
this.account = account;
this.password = password;
Expand Down Expand Up @@ -171,7 +168,7 @@ public ApiSaveResponse saveApi(String projectHashKey, ApiInfo api) {
}
}

private String getSpaceKey() {
public String getSpaceKey() {
if (this.userInfo != null) {
return this.userInfo.getSpaceKey();
}
Expand Down Expand Up @@ -203,7 +200,8 @@ private EolinkApi createApiClient(String url) {
if (value instanceof Response) {
Response responseValue = (Response) value;
if (!responseValue.isSuccess()) {
throw new EolinkException(path, responseValue.getStatusCode());
String errorMsg = StringUtils.defaultIfEmpty(responseValue.getErrorMsg(), responseValue.getStatusCode());
throw new EolinkException(path, responseValue.getStatusCode(), errorMsg);
}
}
return value;
Expand All @@ -229,8 +227,7 @@ private LoginResponseData doLogin() {
loginREquest.setPassword(this.password);
loginREquest.setUsername(this.account);

URI loginUri = URI.create(this.loginUrl + EolinkConstants.Login);
SsoResponse<LoginResponseData> response = eolinkApi.login(loginUri, loginREquest);
SsoResponse<LoginResponseData> response = eolinkApi.login(loginREquest);
return response.getData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public interface EolinkConstants {

String Login = "/userCenter/common/sso/login";
String PageApiList = "/home/api_studio/inside/api/list";

static boolean isLoginPath(String path) {
return path != null && path.contains(Login);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ public EolinkWebUrlCalculator(String url) {
/**
* 计算页面接口列表地址
*/
public String calculateApiListUrl(String projectHashKey, Long groupId) {
String query = String.format("?projectHashKey=%s&groupID=%d", projectHashKey, groupId);
return url + EolinkConstants.PageApiList + query;
public String calculateApiListUrl(String spaceKey, String projectHashKey, Long groupId, Long apiId) {
if (groupId == null) {
groupId = -1L;
}
if (apiId != null) {
String pageTpl = "/home/api-studio/inside/%s/api/%s/detail/%s?spaceKey=%s";
String page = String.format(pageTpl, projectHashKey, groupId, apiId, spaceKey);
return url + page;
} else {
String pageTpl = "/home/api-studio/inside/%s/api/%s/list?spaceKey=%s";
String page = String.format(pageTpl, projectHashKey, groupId, spaceKey);
return url + page;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,4 @@ public class GroupListRequest {
*/
private String spaceKey;

/**
* 模块
*/
private Long module = 2L;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Response {

protected String statusCode;

protected String errorMsg;

private static final Set<String> SUCCESS_CODES;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public static ApiSaveRequest convertApiSaveRequest(String projectHashKey, ApiInf
data.setTagID(api.getTagID());
data.setApiType(api.getApiType());
data.setFileList(api.getFileList());

if (data.getApiNoteType() == null) {
// 兼容处理
data.setApiNoteType(1);
}
return data;
}
}
5 changes: 4 additions & 1 deletion src/main/java/io/apidocx/config/ApidocxConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ public static ApidocxConfig fromProperties(Properties properties) {
String yapiUrl = properties.getProperty("yapiUrl", "");
String yapiProjectToken = properties.getProperty("yapiProjectToken", "");
String rap2ProjectId = properties.getProperty("rap2ProjectId", "");
String eolinkProjectId = properties.getProperty("eolinkerProjectId", "");
String eolinkProjectId = properties.getProperty("eolinkProjectId", "");
if (StringUtils.isEmpty(eolinkProjectId)) {
eolinkProjectId = properties.getProperty("eolinkerProjectId", "");
}
String showdocProjectId = properties.getProperty("showdocProjectId", "");
String apifoxProjectId = properties.getProperty("apifoxProjectId", "");
String returnWrapType = properties.getProperty("returnWrapType", "");
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/io/apidocx/handle/eolink/EolinkUploadAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class EolinkUploadAction extends AbstractAction {
public boolean before(AnActionEvent event, ApidocxConfig config) {
String projectId = config.getEolinkProjectId();
if (StringUtils.isEmpty(projectId)) {
notifyError("Config file error", "eolinkerProjectId must not be empty.");
notifyError("Config file error", "eolinkProjectId must not be empty.");
return false;
}

Expand All @@ -49,18 +49,17 @@ public void handle(AnActionEvent event, ApidocxConfig config, List<Api> apis) {
Project project = event.getData(CommonDataKeys.PROJECT);

EolinkSettings settings = EolinkSettings.getInstance();
EolinkClient client = new EolinkClient(settings.getUrl(), settings.getLoginUrl(), settings.getAccount(), settings.getPassword(), settings.getAccessToken());
EolinkClient client = new EolinkClient(settings.getUrl(), settings.getAccount(), settings.getPassword(), settings.getAccessToken());
EolinkUploader uploader = new EolinkUploader(client);
EolinkWebUrlCalculator urlCalculator = new EolinkWebUrlCalculator(settings.getWebUrl());

super.handleUploadAsync(project, apis,
api -> {
ApiInfo eapi = uploader.upload(projectId, api);

String spaceKey = client.getSpaceKey();
ApiUploadResult result = new ApiUploadResult();
result.setCategoryUrl(urlCalculator.calculateApiListUrl(projectId,
eapi.getBaseInfo().getGroupID()));
result.setApiUrl(result.getCategoryUrl());
result.setCategoryUrl(urlCalculator.calculateApiListUrl(spaceKey, projectId, eapi.getBaseInfo().getGroupID(), null));
result.setApiUrl(urlCalculator.calculateApiListUrl(spaceKey, projectId, eapi.getBaseInfo().getGroupID(), eapi.getBaseInfo().getApiID()));
return result;
}, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public class EolinkSettings implements PersistentStateComponent<EolinkSettings>

private static final String PASSWORD_KEY = "eolinker";

/**
* 登录地址
*/
private String loginUrl;

/**
* 服务页面地址
*/
Expand Down Expand Up @@ -88,14 +83,13 @@ public void loadState(@NotNull EolinkSettings state) {
public boolean isValidate() {
return StringUtils.isNotEmpty(url)
&& StringUtils.isNotEmpty(webUrl)
&& StringUtils.isNotEmpty(loginUrl)
&& StringUtils.isNotEmpty(account) && StringUtils.isNotEmpty(password);
}

public TestResult testSettings() {
EolinkSettings settings = this;
// 测试账户
EolinkClient client = new EolinkClient(settings.getUrl(), settings.loginUrl, settings.getAccount(),
EolinkClient client = new EolinkClient(settings.getUrl(), settings.getAccount(),
settings.getPassword(), settings.getAccessToken());
TestResult testResult = client.test();
Code code = testResult.getCode();
Expand All @@ -122,9 +116,6 @@ public boolean equals(Object o) {
if (webUrl != null ? !webUrl.equals(that.webUrl) : that.webUrl != null) {
return false;
}
if (loginUrl != null ? !loginUrl.equals(that.loginUrl) : that.loginUrl != null) {
return false;
}
if (account != null ? !account.equals(that.account) : that.account != null) {
return false;
}
Expand All @@ -134,7 +125,6 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = url != null ? url.hashCode() : 0;
result = 31 * result + (loginUrl != null ? loginUrl.hashCode() : 0);
result = 31 * result + (webUrl != null ? webUrl.hashCode() : 0);
result = 31 * result + (account != null ? account.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ protected ValidationInfo doValidate() {
if (StringUtils.isEmpty(data.getWebUrl())) {
return new ValidationInfo("webUrl must not be empty", form.getWebUrlField());
}
if (StringUtils.isEmpty(data.getLoginUrl())) {
return new ValidationInfo("loginUrl must not be empty", form.getLoginUrlField());
}
if (StringUtils.isEmpty(data.getAccount())) {
return new ValidationInfo("account must not be empty", form.getAccountField());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="198"/>
<xy x="20" y="20" width="500" height="199"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="cb0a7" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="cb0a7" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
Expand All @@ -20,31 +20,31 @@
<children>
<component id="4c7d2" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Password:"/>
</properties>
</component>
<component id="4a5e" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Account:"/>
</properties>
</component>
<component id="ccd3f" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Api URL:"/>
</properties>
</component>
<component id="d44eb" class="javax.swing.JTextField" binding="urlField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
Expand All @@ -54,7 +54,7 @@
</component>
<component id="1246f" class="javax.swing.JFormattedTextField" binding="accountField" default-binding="true">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
Expand All @@ -64,41 +64,23 @@
</component>
<component id="764a9" class="javax.swing.JPasswordField" binding="passwordField">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="5ecf2" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Web URL:"/>
</properties>
</component>
<component id="142f2" class="javax.swing.JTextField" binding="webUrlField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="421c8" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Login URL:"/>
</properties>
</component>
<component id="38b32" class="javax.swing.JTextField" binding="loginUrlField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
Expand Down
Loading

0 comments on commit 1279549

Please sign in to comment.