Skip to content

Commit eb3ed16

Browse files
[tool] Support for blank properties in json schema (#345)
1 parent 450cf64 commit eb3ed16

File tree

5 files changed

+262
-305
lines changed

5 files changed

+262
-305
lines changed

store/plugins/store-tool-uploader/src/main/java/modelengine/jade/store/tool/upload/support/processor/Processor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import static modelengine.fitframework.inspection.Validation.notNull;
2626
import static modelengine.fitframework.util.ObjectUtils.cast;
2727
import static modelengine.jade.store.tool.upload.support.BasicValidator.buildBlankParserException;
28-
import static modelengine.jade.store.tool.upload.support.BasicValidator.buildEmptyParserException;
2928
import static modelengine.jade.store.tool.upload.support.BasicValidator.buildNullParserException;
3029
import static modelengine.jade.store.tool.upload.support.BasicValidator.buildParserException;
3130

@@ -134,14 +133,14 @@ private void validateParams(ParameterEntity param, String fileName) {
134133
if (!param.getType().equals(OBJECT)) {
135134
throw buildParserException("The type of the field 'parameters' in 'tools.json' must is: 'object'.");
136135
}
137-
this.validateProperties(param.getProperties());
138-
this.validateRequired(param, fileName);
136+
Map<String, Object> properties = param.getProperties();
137+
if (MapUtils.isNotEmpty(properties)) {
138+
this.validateProperties(properties);
139+
this.validateRequired(param, fileName);
140+
}
139141
}
140142

141143
private void validateProperties(Map<String, Object> properties) {
142-
if (MapUtils.isEmpty(properties)) {
143-
throw buildEmptyParserException(TOOLS_JSON, SCHEMA + DOT + PARAMETERS);
144-
}
145144
properties.forEach((key, value) -> validateProperty(cast(value), PARAMETERS, key));
146145
}
147146

store/plugins/store-tool-uploader/src/test/java/modelengine/jade/store/tool/upload/service/PluginUploadServiceImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ void testUploadPluginsWithWrongName() throws IOException {
184184
@DisplayName("当选择部分工具上传时,成功")
185185
void shouldOkWhenValidateSelectTools() {
186186
List<String> selectTools = Arrays.asList(
187-
"defGroup-weather-Rain.implGroup-weather-Rain-A.rain_today.a_rain_today",
188-
"defGroup-weather-Rain.implGroup-weather-Rain-A.rain_tomorrow.a_rain_today");
187+
"defGroup_weather_Rain.implGroup_weather_rain_city_a.rain_today.city_a_rain_tomorrow",
188+
"defGroup_weather_Rain.implGroup_weather_rain_city_b.rain_tomorrow.city_b_rain_tomorrow");
189189
ToolProcessor toolProcessor = new ToolProcessor(this.serializer);
190190
DefinitionProcessor defProcessor = new DefinitionProcessor(this.serializer);
191191
ToolJsonEntity toolJsonEntity = getFileInfo(new File(NEW_TOOL_JSON), serializer, ToolJsonEntity.class);

store/plugins/store-tool-uploader/src/test/java/modelengine/jade/store/tool/upload/support/BasicValidatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void setup() {
213213
@Test
214214
@DisplayName("当定义组存在重复时,删除定义组")
215215
void shouldExWhenDefGroupRepeat() {
216-
when(this.defGroupService.findExistDefGroups(anySet())).thenReturn(Arrays.asList("defGroup-weather-Rain"));
216+
when(this.defGroupService.findExistDefGroups(anySet())).thenReturn(Arrays.asList("defGroup_weather_Rain"));
217217
int size = this.defGroups.size();
218218
validateDefAndToolRepeat(this.defGroups, this.toolGroups, this.toolGroupService, this.defGroupService);
219219
assertThat(this.defGroups.size()).isEqualTo(size - 1);
@@ -243,7 +243,7 @@ void shouldExWhenToolNameInToolGroupRepeat() {
243243
validateDefAndToolRepeat(this.defGroups, this.toolGroups, this.toolGroupService, this.defGroupService);
244244
}).isInstanceOf(ModelEngineException.class)
245245
.hasMessageContaining("The current operation has duplicate property. [property='toolName', "
246-
+ "value='implGroup-weather-Rain-A.a_rain_today']");
246+
+ "value='implGroup_weather_rain_city_a.city_a_rain_today']");
247247
}
248248

249249
@Test

store/plugins/store-tool-uploader/src/test/java/modelengine/jade/store/tool/upload/utils/FormatFileUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void shouldOkWhenObjToMap() {
118118
void shouldOkWhenBuildDefGroupMap() {
119119
ToolJsonEntity toolJsonEntity = getFileInfo(new File(NEW_TOOL_JSON), serializer, ToolJsonEntity.class);
120120
Map<String, Object> defGroupMap = buildDefGroupMap(toolJsonEntity);
121-
assertThat(defGroupMap.size()).isEqualTo(2);
121+
assertThat(defGroupMap.size()).isEqualTo(1);
122122
}
123123

124124
@Test

0 commit comments

Comments
 (0)