From e7635483dc8ce22f46cfb495adacfb35279708ca Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 11 Jan 2024 16:06:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=9A=E6=97=B6=E5=90=8C=E6=AD=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/domain/ApiDefinitionSwagger.java | 30 ++- .../domain/ApiDefinitionSwaggerExample.java | 234 ++++++++++++++---- .../mapper/ApiDefinitionSwaggerMapper.java | 6 - .../api/mapper/ApiDefinitionSwaggerMapper.xml | 183 ++++++-------- .../3.0.0/ddl/V3.0.0_5__api_test.sql | 19 +- .../src/main/resources/i18n/api.properties | 2 + .../main/resources/i18n/api_en_US.properties | 3 +- .../main/resources/i18n/api_zh_CN.properties | 1 + .../main/resources/i18n/api_zh_TW.properties | 1 + .../definition/ApiDefinitionController.java | 2 +- .../ApiDefinitionScheduleController.java | 68 +++++ .../api/dto/definition/ApiScheduleDTO.java | 36 +++ .../api/dto/definition/SwaggerBasicAuth.java | 10 + .../api/dto/definition/SwaggerUrlCheck.java | 12 + .../importdto/ApiScheduleRequest.java | 54 ++++ .../definition/importdto/ScheduleRequest.java | 40 --- .../api/dto/request/ImportRequest.java | 37 ++- .../api/mapper/ExtApiDefinitionMapper.xml | 1 + .../api/mapper/ExtApiTestCaseMapper.xml | 1 + .../api/parser/api/Swagger3Parser.java | 44 +--- .../ApiDefinitionImportUtilService.java | 8 +- .../ApiDefinitionScheduleService.java | 189 ++++++++++++++ .../definition/ApiDefinitionService.java | 13 +- .../service/schedule/SwaggerUrlImportJob.java | 48 ++++ .../ApiDefinitionScheduleControllerTests.java | 168 +++++++++++++ 25 files changed, 922 insertions(+), 288 deletions(-) create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionScheduleController.java create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiScheduleDTO.java create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/SwaggerBasicAuth.java create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/SwaggerUrlCheck.java create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ApiScheduleRequest.java delete mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/importdto/ScheduleRequest.java create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/service/schedule/SwaggerUrlImportJob.java create mode 100644 backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionScheduleControllerTests.java diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionSwagger.java b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionSwagger.java index 3bea3f432f..0ebb3ba911 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionSwagger.java +++ b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionSwagger.java @@ -15,6 +15,11 @@ public class ApiDefinitionSwagger implements Serializable { @Size(min = 1, max = 50, message = "{api_definition_swagger.id.length_range}", groups = {Created.class, Updated.class}) private String id; + @Schema(description = "定时任务名称", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{api_definition_swagger.name.not_blank}", groups = {Created.class}) + @Size(min = 1, max = 255, message = "{api_definition_swagger.name.length_range}", groups = {Created.class, Updated.class}) + private String name; + @Schema(description = "url地址", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{api_definition_swagger.swagger_url.not_blank}", groups = {Created.class}) @Size(min = 1, max = 500, message = "{api_definition_swagger.swagger_url.length_range}", groups = {Created.class, Updated.class}) @@ -23,32 +28,35 @@ public class ApiDefinitionSwagger implements Serializable { @Schema(description = "模块fk") private String moduleId; - @Schema(description = "模块路径") - private String modulePath; + @Schema(description = "鉴权配置信息") + private String config; @Schema(description = "导入模式/覆盖/不覆盖") - private Boolean mode; + private Boolean coverData; - @Schema(description = "项目fk") + @Schema(description = "是否覆盖模块") + private Boolean coverModule; + + @Schema(description = "项目fk", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{api_definition_swagger.project_id.not_blank}", groups = {Created.class}) + @Size(min = 1, max = 50, message = "{api_definition_swagger.project_id.length_range}", groups = {Created.class, Updated.class}) private String projectId; @Schema(description = "导入版本") private String versionId; - @Schema(description = "鉴权配置信息") - private byte[] config; - private static final long serialVersionUID = 1L; public enum Column { id("id", "id", "VARCHAR", false), + name("name", "name", "VARCHAR", true), swaggerUrl("swagger_url", "swaggerUrl", "VARCHAR", false), moduleId("module_id", "moduleId", "VARCHAR", false), - modulePath("module_path", "modulePath", "VARCHAR", false), - mode("mode", "mode", "BIT", true), + config("config", "config", "VARCHAR", false), + coverData("cover_data", "coverData", "BIT", false), + coverModule("cover_module", "coverModule", "BIT", false), projectId("project_id", "projectId", "VARCHAR", false), - versionId("version_id", "versionId", "VARCHAR", false), - config("config", "config", "LONGVARBINARY", false); + versionId("version_id", "versionId", "VARCHAR", false); private static final String BEGINNING_DELIMITER = "`"; diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionSwaggerExample.java b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionSwaggerExample.java index 4248c708dc..30013b5c60 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionSwaggerExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDefinitionSwaggerExample.java @@ -174,6 +174,76 @@ public class ApiDefinitionSwaggerExample { return (Criteria) this; } + public Criteria andNameIsNull() { + addCriterion("`name` is null"); + return (Criteria) this; + } + + public Criteria andNameIsNotNull() { + addCriterion("`name` is not null"); + return (Criteria) this; + } + + public Criteria andNameEqualTo(String value) { + addCriterion("`name` =", value, "name"); + return (Criteria) this; + } + + public Criteria andNameNotEqualTo(String value) { + addCriterion("`name` <>", value, "name"); + return (Criteria) this; + } + + public Criteria andNameGreaterThan(String value) { + addCriterion("`name` >", value, "name"); + return (Criteria) this; + } + + public Criteria andNameGreaterThanOrEqualTo(String value) { + addCriterion("`name` >=", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLessThan(String value) { + addCriterion("`name` <", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLessThanOrEqualTo(String value) { + addCriterion("`name` <=", value, "name"); + return (Criteria) this; + } + + public Criteria andNameLike(String value) { + addCriterion("`name` like", value, "name"); + return (Criteria) this; + } + + public Criteria andNameNotLike(String value) { + addCriterion("`name` not like", value, "name"); + return (Criteria) this; + } + + public Criteria andNameIn(List values) { + addCriterion("`name` in", values, "name"); + return (Criteria) this; + } + + public Criteria andNameNotIn(List values) { + addCriterion("`name` not in", values, "name"); + return (Criteria) this; + } + + public Criteria andNameBetween(String value1, String value2) { + addCriterion("`name` between", value1, value2, "name"); + return (Criteria) this; + } + + public Criteria andNameNotBetween(String value1, String value2) { + addCriterion("`name` not between", value1, value2, "name"); + return (Criteria) this; + } + public Criteria andSwaggerUrlIsNull() { addCriterion("swagger_url is null"); return (Criteria) this; @@ -314,133 +384,193 @@ public class ApiDefinitionSwaggerExample { return (Criteria) this; } - public Criteria andModulePathIsNull() { - addCriterion("module_path is null"); + public Criteria andConfigIsNull() { + addCriterion("config is null"); return (Criteria) this; } - public Criteria andModulePathIsNotNull() { - addCriterion("module_path is not null"); + public Criteria andConfigIsNotNull() { + addCriterion("config is not null"); return (Criteria) this; } - public Criteria andModulePathEqualTo(String value) { - addCriterion("module_path =", value, "modulePath"); + public Criteria andConfigEqualTo(String value) { + addCriterion("config =", value, "config"); return (Criteria) this; } - public Criteria andModulePathNotEqualTo(String value) { - addCriterion("module_path <>", value, "modulePath"); + public Criteria andConfigNotEqualTo(String value) { + addCriterion("config <>", value, "config"); return (Criteria) this; } - public Criteria andModulePathGreaterThan(String value) { - addCriterion("module_path >", value, "modulePath"); + public Criteria andConfigGreaterThan(String value) { + addCriterion("config >", value, "config"); return (Criteria) this; } - public Criteria andModulePathGreaterThanOrEqualTo(String value) { - addCriterion("module_path >=", value, "modulePath"); + public Criteria andConfigGreaterThanOrEqualTo(String value) { + addCriterion("config >=", value, "config"); return (Criteria) this; } - public Criteria andModulePathLessThan(String value) { - addCriterion("module_path <", value, "modulePath"); + public Criteria andConfigLessThan(String value) { + addCriterion("config <", value, "config"); return (Criteria) this; } - public Criteria andModulePathLessThanOrEqualTo(String value) { - addCriterion("module_path <=", value, "modulePath"); + public Criteria andConfigLessThanOrEqualTo(String value) { + addCriterion("config <=", value, "config"); return (Criteria) this; } - public Criteria andModulePathLike(String value) { - addCriterion("module_path like", value, "modulePath"); + public Criteria andConfigLike(String value) { + addCriterion("config like", value, "config"); return (Criteria) this; } - public Criteria andModulePathNotLike(String value) { - addCriterion("module_path not like", value, "modulePath"); + public Criteria andConfigNotLike(String value) { + addCriterion("config not like", value, "config"); return (Criteria) this; } - public Criteria andModulePathIn(List values) { - addCriterion("module_path in", values, "modulePath"); + public Criteria andConfigIn(List values) { + addCriterion("config in", values, "config"); return (Criteria) this; } - public Criteria andModulePathNotIn(List values) { - addCriterion("module_path not in", values, "modulePath"); + public Criteria andConfigNotIn(List values) { + addCriterion("config not in", values, "config"); return (Criteria) this; } - public Criteria andModulePathBetween(String value1, String value2) { - addCriterion("module_path between", value1, value2, "modulePath"); + public Criteria andConfigBetween(String value1, String value2) { + addCriterion("config between", value1, value2, "config"); return (Criteria) this; } - public Criteria andModulePathNotBetween(String value1, String value2) { - addCriterion("module_path not between", value1, value2, "modulePath"); + public Criteria andConfigNotBetween(String value1, String value2) { + addCriterion("config not between", value1, value2, "config"); return (Criteria) this; } - public Criteria andModeIsNull() { - addCriterion("`mode` is null"); + public Criteria andCoverDataIsNull() { + addCriterion("cover_data is null"); return (Criteria) this; } - public Criteria andModeIsNotNull() { - addCriterion("`mode` is not null"); + public Criteria andCoverDataIsNotNull() { + addCriterion("cover_data is not null"); return (Criteria) this; } - public Criteria andModeEqualTo(Boolean value) { - addCriterion("`mode` =", value, "mode"); + public Criteria andCoverDataEqualTo(Boolean value) { + addCriterion("cover_data =", value, "coverData"); return (Criteria) this; } - public Criteria andModeNotEqualTo(Boolean value) { - addCriterion("`mode` <>", value, "mode"); + public Criteria andCoverDataNotEqualTo(Boolean value) { + addCriterion("cover_data <>", value, "coverData"); return (Criteria) this; } - public Criteria andModeGreaterThan(Boolean value) { - addCriterion("`mode` >", value, "mode"); + public Criteria andCoverDataGreaterThan(Boolean value) { + addCriterion("cover_data >", value, "coverData"); return (Criteria) this; } - public Criteria andModeGreaterThanOrEqualTo(Boolean value) { - addCriterion("`mode` >=", value, "mode"); + public Criteria andCoverDataGreaterThanOrEqualTo(Boolean value) { + addCriterion("cover_data >=", value, "coverData"); return (Criteria) this; } - public Criteria andModeLessThan(Boolean value) { - addCriterion("`mode` <", value, "mode"); + public Criteria andCoverDataLessThan(Boolean value) { + addCriterion("cover_data <", value, "coverData"); return (Criteria) this; } - public Criteria andModeLessThanOrEqualTo(Boolean value) { - addCriterion("`mode` <=", value, "mode"); + public Criteria andCoverDataLessThanOrEqualTo(Boolean value) { + addCriterion("cover_data <=", value, "coverData"); return (Criteria) this; } - public Criteria andModeIn(List values) { - addCriterion("`mode` in", values, "mode"); + public Criteria andCoverDataIn(List values) { + addCriterion("cover_data in", values, "coverData"); return (Criteria) this; } - public Criteria andModeNotIn(List values) { - addCriterion("`mode` not in", values, "mode"); + public Criteria andCoverDataNotIn(List values) { + addCriterion("cover_data not in", values, "coverData"); return (Criteria) this; } - public Criteria andModeBetween(Boolean value1, Boolean value2) { - addCriterion("`mode` between", value1, value2, "mode"); + public Criteria andCoverDataBetween(Boolean value1, Boolean value2) { + addCriterion("cover_data between", value1, value2, "coverData"); return (Criteria) this; } - public Criteria andModeNotBetween(Boolean value1, Boolean value2) { - addCriterion("`mode` not between", value1, value2, "mode"); + public Criteria andCoverDataNotBetween(Boolean value1, Boolean value2) { + addCriterion("cover_data not between", value1, value2, "coverData"); + return (Criteria) this; + } + + public Criteria andCoverModuleIsNull() { + addCriterion("cover_module is null"); + return (Criteria) this; + } + + public Criteria andCoverModuleIsNotNull() { + addCriterion("cover_module is not null"); + return (Criteria) this; + } + + public Criteria andCoverModuleEqualTo(Boolean value) { + addCriterion("cover_module =", value, "coverModule"); + return (Criteria) this; + } + + public Criteria andCoverModuleNotEqualTo(Boolean value) { + addCriterion("cover_module <>", value, "coverModule"); + return (Criteria) this; + } + + public Criteria andCoverModuleGreaterThan(Boolean value) { + addCriterion("cover_module >", value, "coverModule"); + return (Criteria) this; + } + + public Criteria andCoverModuleGreaterThanOrEqualTo(Boolean value) { + addCriterion("cover_module >=", value, "coverModule"); + return (Criteria) this; + } + + public Criteria andCoverModuleLessThan(Boolean value) { + addCriterion("cover_module <", value, "coverModule"); + return (Criteria) this; + } + + public Criteria andCoverModuleLessThanOrEqualTo(Boolean value) { + addCriterion("cover_module <=", value, "coverModule"); + return (Criteria) this; + } + + public Criteria andCoverModuleIn(List values) { + addCriterion("cover_module in", values, "coverModule"); + return (Criteria) this; + } + + public Criteria andCoverModuleNotIn(List values) { + addCriterion("cover_module not in", values, "coverModule"); + return (Criteria) this; + } + + public Criteria andCoverModuleBetween(Boolean value1, Boolean value2) { + addCriterion("cover_module between", value1, value2, "coverModule"); + return (Criteria) this; + } + + public Criteria andCoverModuleNotBetween(Boolean value1, Boolean value2) { + addCriterion("cover_module not between", value1, value2, "coverModule"); return (Criteria) this; } diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionSwaggerMapper.java b/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionSwaggerMapper.java index 04808cfcc2..851fd9f514 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionSwaggerMapper.java +++ b/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionSwaggerMapper.java @@ -16,22 +16,16 @@ public interface ApiDefinitionSwaggerMapper { int insertSelective(ApiDefinitionSwagger record); - List selectByExampleWithBLOBs(ApiDefinitionSwaggerExample example); - List selectByExample(ApiDefinitionSwaggerExample example); ApiDefinitionSwagger selectByPrimaryKey(String id); int updateByExampleSelective(@Param("record") ApiDefinitionSwagger record, @Param("example") ApiDefinitionSwaggerExample example); - int updateByExampleWithBLOBs(@Param("record") ApiDefinitionSwagger record, @Param("example") ApiDefinitionSwaggerExample example); - int updateByExample(@Param("record") ApiDefinitionSwagger record, @Param("example") ApiDefinitionSwaggerExample example); int updateByPrimaryKeySelective(ApiDefinitionSwagger record); - int updateByPrimaryKeyWithBLOBs(ApiDefinitionSwagger record); - int updateByPrimaryKey(ApiDefinitionSwagger record); int batchInsert(@Param("list") List list); diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionSwaggerMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionSwaggerMapper.xml index 5649c24cf4..27c9cfa8f3 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionSwaggerMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDefinitionSwaggerMapper.xml @@ -3,16 +3,15 @@ + - - + + + - - - @@ -72,27 +71,9 @@ - id, swagger_url, module_id, module_path, `mode`, project_id, version_id + id, `name`, swagger_url, module_id, config, cover_data, cover_module, project_id, + version_id - - config - - - select - , - from api_definition_swagger where id = #{id,jdbcType=VARCHAR} @@ -126,12 +105,14 @@ - insert into api_definition_swagger (id, swagger_url, module_id, - module_path, `mode`, project_id, - version_id, config) - values (#{id,jdbcType=VARCHAR}, #{swaggerUrl,jdbcType=VARCHAR}, #{moduleId,jdbcType=VARCHAR}, - #{modulePath,jdbcType=VARCHAR}, #{mode,jdbcType=BIT}, #{projectId,jdbcType=VARCHAR}, - #{versionId,jdbcType=VARCHAR}, #{config,jdbcType=LONGVARBINARY}) + insert into api_definition_swagger (id, `name`, swagger_url, + module_id, config, cover_data, + cover_module, project_id, version_id + ) + values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{swaggerUrl,jdbcType=VARCHAR}, + #{moduleId,jdbcType=VARCHAR}, #{config,jdbcType=VARCHAR}, #{coverData,jdbcType=BIT}, + #{coverModule,jdbcType=BIT}, #{projectId,jdbcType=VARCHAR}, #{versionId,jdbcType=VARCHAR} + ) insert into api_definition_swagger @@ -139,17 +120,23 @@ id, + + `name`, + swagger_url, module_id, - - module_path, + + config, - - `mode`, + + cover_data, + + + cover_module, project_id, @@ -157,25 +144,28 @@ version_id, - - config, - #{id,jdbcType=VARCHAR}, + + #{name,jdbcType=VARCHAR}, + #{swaggerUrl,jdbcType=VARCHAR}, #{moduleId,jdbcType=VARCHAR}, - - #{modulePath,jdbcType=VARCHAR}, + + #{config,jdbcType=VARCHAR}, - - #{mode,jdbcType=BIT}, + + #{coverData,jdbcType=BIT}, + + + #{coverModule,jdbcType=BIT}, #{projectId,jdbcType=VARCHAR}, @@ -183,9 +173,6 @@ #{versionId,jdbcType=VARCHAR}, - - #{config,jdbcType=LONGVARBINARY}, -