From 2791d2f0e57c4e1a070888c31ab1b1310ec3d943 Mon Sep 17 00:00:00 2001
From: guqing <38999863+guqing@users.noreply.github.com>
Date: Mon, 26 Jun 2023 22:33:58 +0800
Subject: [PATCH] refactor: uinify some properties of plugins and themes
(#4061)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.7.x
/kind api-change
#### What this PR does / why we need it:
统一主题和插件描述文件的部分字段
1. 统一网站字段为 homepage,将主题的 website 标记为过时并兼容为 homepage
2. 主题添加 license 字段
3. 插件添加 repo
#### Which issue(s) this PR fixes:
Fixes #4011
#### Does this PR introduce a user-facing change?
```release-note
统一主题和插件描述文件的部分字段
```
---
.../run/halo/app/core/extension/Plugin.java | 8 +++++-
.../run/halo/app/core/extension/Theme.java | 25 ++++++++++++++-----
.../run/halo/app/infra/model/License.java | 12 +++++++++
.../halo/app/core/extension/ThemeTest.java | 4 +--
.../api-client/src/models/plugin-spec.ts | 6 +++++
.../api-client/src/models/theme-spec.ts | 16 ++++++++++++
6 files changed, 62 insertions(+), 9 deletions(-)
create mode 100644 api/src/main/java/run/halo/app/infra/model/License.java
diff --git a/api/src/main/java/run/halo/app/core/extension/Plugin.java b/api/src/main/java/run/halo/app/core/extension/Plugin.java
index c54f534a4..e4cf014cc 100644
--- a/api/src/main/java/run/halo/app/core/extension/Plugin.java
+++ b/api/src/main/java/run/halo/app/core/extension/Plugin.java
@@ -61,7 +61,7 @@ public class Plugin extends AbstractExtension {
*
* @see semantic version
*/
- @Schema(required = true, pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-("
+ @Schema(requiredMode = REQUIRED, pattern = "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-("
+ "(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\."
+ "(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\"
+ ".[0-9a-zA-Z-]+)*))?$")
@@ -75,6 +75,8 @@ public class Plugin extends AbstractExtension {
private String homepage;
+ private String repo;
+
private String description;
private List license;
@@ -94,6 +96,10 @@ public class Plugin extends AbstractExtension {
private String configMapName;
}
+ /**
+ * In the future, we may consider using {@link run.halo.app.infra.model.License} instead of it.
+ * But now, replace it will lead to incompatibility with downstream.
+ */
@Data
public static class License {
private String name;
diff --git a/api/src/main/java/run/halo/app/core/extension/Theme.java b/api/src/main/java/run/halo/app/core/extension/Theme.java
index 37f51f8f9..07e39d971 100644
--- a/api/src/main/java/run/halo/app/core/extension/Theme.java
+++ b/api/src/main/java/run/halo/app/core/extension/Theme.java
@@ -1,6 +1,7 @@
package run.halo.app.core.extension;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
+import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
@@ -14,6 +15,7 @@ import org.springframework.util.Assert;
import run.halo.app.extension.AbstractExtension;
import run.halo.app.extension.GVK;
import run.halo.app.infra.ConditionList;
+import run.halo.app.infra.model.License;
/**
* Theme extension.
@@ -42,18 +44,21 @@ public class Theme extends AbstractExtension {
public static class ThemeSpec {
private static final String WILDCARD = "*";
- @Schema(required = true, minLength = 1)
+ @Schema(requiredMode = REQUIRED, minLength = 1)
private String displayName;
- @Schema(required = true)
+ @Schema(requiredMode = REQUIRED)
private Author author;
private String description;
private String logo;
+ @Deprecated(forRemoval = true, since = "2.7.0")
private String website;
+ private String homepage;
+
private String repo;
private String version;
@@ -69,6 +74,8 @@ public class Theme extends AbstractExtension {
private String configMapName;
+ private List license;
+
@Schema
private CustomTemplates customTemplates;
@@ -89,6 +96,13 @@ public class Theme extends AbstractExtension {
}
return StringUtils.defaultString(this.require, WILDCARD);
}
+
+ /**
+ * Compatible with {@link #website} property.
+ */
+ public String getHomepage() {
+ return StringUtils.defaultString(this.homepage, this.website);
+ }
}
@Data
@@ -125,7 +139,7 @@ public class Theme extends AbstractExtension {
@ToString
public static class Author {
- @Schema(required = true, minLength = 1)
+ @Schema(requiredMode = REQUIRED, minLength = 1)
private String name;
private String website;
@@ -138,7 +152,6 @@ public class Theme extends AbstractExtension {
private List page;
}
-
/**
* Type used to describe custom template page.
*
@@ -148,14 +161,14 @@ public class Theme extends AbstractExtension {
@Data
public static class TemplateDescriptor {
- @Schema(required = true, minLength = 1)
+ @Schema(requiredMode = REQUIRED, minLength = 1)
private String name;
private String description;
private String screenshot;
- @Schema(required = true, minLength = 1)
+ @Schema(requiredMode = REQUIRED, minLength = 1)
private String file;
}
diff --git a/api/src/main/java/run/halo/app/infra/model/License.java b/api/src/main/java/run/halo/app/infra/model/License.java
new file mode 100644
index 000000000..2caa9493f
--- /dev/null
+++ b/api/src/main/java/run/halo/app/infra/model/License.java
@@ -0,0 +1,12 @@
+package run.halo.app.infra.model;
+
+import lombok.Data;
+
+/**
+ * Common data objects for license.
+ */
+@Data
+public class License {
+ private String name;
+ private String url;
+}
diff --git a/application/src/test/java/run/halo/app/core/extension/ThemeTest.java b/application/src/test/java/run/halo/app/core/extension/ThemeTest.java
index 20c8a52d8..3492d9ed4 100644
--- a/application/src/test/java/run/halo/app/core/extension/ThemeTest.java
+++ b/application/src/test/java/run/halo/app/core/extension/ThemeTest.java
@@ -39,7 +39,7 @@ class ThemeTest {
themeSpec.setRepo("https://test.com");
themeSpec.setLogo("https://test.com");
- themeSpec.setWebsite("https://test.com");
+ themeSpec.setHomepage("https://test.com");
themeSpec.setDescription("test-description");
themeSpec.setConfigMapName("test-config-map");
themeSpec.setSettingName("test-setting");
@@ -56,7 +56,7 @@ class ThemeTest {
},
"description": "test-description",
"logo": "https://test.com",
- "website": "https://test.com",
+ "homepage": "https://test.com",
"repo": "https://test.com",
"version": "*",
"requires": "*",
diff --git a/console/packages/api-client/src/models/plugin-spec.ts b/console/packages/api-client/src/models/plugin-spec.ts
index df6a51692..2f26f3785 100644
--- a/console/packages/api-client/src/models/plugin-spec.ts
+++ b/console/packages/api-client/src/models/plugin-spec.ts
@@ -86,6 +86,12 @@ export interface PluginSpec {
* @memberof PluginSpec
*/
pluginDependencies?: { [key: string]: string };
+ /**
+ *
+ * @type {string}
+ * @memberof PluginSpec
+ */
+ repo?: string;
/**
*
* @type {string}
diff --git a/console/packages/api-client/src/models/theme-spec.ts b/console/packages/api-client/src/models/theme-spec.ts
index 520427a01..ead1396cc 100644
--- a/console/packages/api-client/src/models/theme-spec.ts
+++ b/console/packages/api-client/src/models/theme-spec.ts
@@ -18,6 +18,9 @@ import { Author } from "./author";
// May contain unused imports in some cases
// @ts-ignore
import { CustomTemplates } from "./custom-templates";
+// May contain unused imports in some cases
+// @ts-ignore
+import { License } from "./license";
/**
*
@@ -55,6 +58,18 @@ export interface ThemeSpec {
* @memberof ThemeSpec
*/
displayName: string;
+ /**
+ *
+ * @type {string}
+ * @memberof ThemeSpec
+ */
+ homepage?: string;
+ /**
+ *
+ * @type {Array}
+ * @memberof ThemeSpec
+ */
+ license?: Array;
/**
*
* @type {string}
@@ -96,6 +111,7 @@ export interface ThemeSpec {
*
* @type {string}
* @memberof ThemeSpec
+ * @deprecated
*/
website?: string;
}