[OPB-38] fixing json validation

This commit is contained in:
Sheldan
2021-08-22 18:39:41 +02:00
parent bf98d5db3a
commit d7f5fc21d6
2 changed files with 136 additions and 139 deletions

View File

@@ -66,6 +66,7 @@ public class ImportFAQ extends AbstractConditionableCommand {
AServer server = serverManagementService.loadServer(commandContext.getGuild()); AServer server = serverManagementService.loadServer(commandContext.getGuild());
List<FaqCommandConfig> commands = faqServiceBean.loadFAQCommandsFromJson(jsonContent); List<FaqCommandConfig> commands = faqServiceBean.loadFAQCommandsFromJson(jsonContent);
faqServiceBean.createOrUpdateFAQCommands(commands, server); faqServiceBean.createOrUpdateFAQCommands(commands, server);
return CompletableFuture.completedFuture(CommandResult.fromSuccess());
} else { } else {
List<String> errors = jsonValidationService.getDetailedException(result.getExceptions()) List<String> errors = jsonValidationService.getDetailedException(result.getExceptions())
@@ -73,8 +74,8 @@ public class ImportFAQ extends AbstractConditionableCommand {
.map(ValidationException::getMessage) .map(ValidationException::getMessage)
.collect(Collectors.toList()); .collect(Collectors.toList());
channelService.sendTextToChannel(String.join("\n", errors), commandContext.getChannel()); channelService.sendTextToChannel(String.join("\n", errors), commandContext.getChannel());
return CompletableFuture.completedFuture(CommandResult.fromError("Incorrect faq config."));
} }
return CompletableFuture.completedFuture(CommandResult.fromSuccess());
} catch (IOException e) { } catch (IOException e) {
log.error("IO Exception when loading input file.", e); log.error("IO Exception when loading input file.", e);
throw new AbstractoTemplatedException("Failed to load json config.", "failed_to_set_template_exception", e); throw new AbstractoTemplatedException("Failed to load json config.", "failed_to_set_template_exception", e);

View File

@@ -3,8 +3,7 @@
"type": "array", "type": "array",
"minItems": 1, "minItems": 1,
"maxItems": 30, "maxItems": 30,
"items": [ "items": {
{
"type": "object", "type": "object",
"properties": { "properties": {
"faqCommandName": { "faqCommandName": {
@@ -45,8 +44,7 @@
"type": "array", "type": "array",
"minItems": 1, "minItems": 1,
"maxItems": 3, "maxItems": 3,
"items": [ "items": {
{
"type": "object", "type": "object",
"properties": { "properties": {
"position": { "position": {
@@ -168,7 +166,6 @@
} }
] ]
} }
]
} }
}, },
"additionalProperties": false, "additionalProperties": false,
@@ -185,5 +182,4 @@
"responses" "responses"
] ]
} }
]
} }