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

View File

@@ -3,143 +3,124 @@
"type": "array",
"minItems": 1,
"maxItems": 30,
"items": [
{
"type": "object",
"properties": {
"faqCommandName": {
"items": {
"type": "object",
"properties": {
"faqCommandName": {
"type": "string",
"minLength": 1,
"maxLength": 30,
"pattern": "\\w*"
},
"global": {
"default": false,
"type": "boolean"
},
"aliases": {
"type": "array",
"minItems": 1,
"maxItems": 20,
"items": {
"type": "string",
"minLength": 1,
"maxLength": 30,
"pattern": "\\w*"
},
"global": {
"default": false,
"type": "boolean"
},
"aliases": {
"type": "array",
"minItems": 1,
"maxItems": 20,
"items": {
"type": "string",
"minLength": 1,
"maxLength": 30,
"pattern": "\\w*"
}
},
"responses": {
"type": "array",
"minItems": 1,
"maxItems": 255,
"items": {
"type": "object",
"properties": {
"channelGroupName": {
"type": "string",
"minLength": 1,
"maxLength": 20,
"pattern": "\\w*"
},
"messages": {
"type": "array",
"minItems": 1,
"maxItems": 3,
"items": [
{
}
},
"responses": {
"type": "array",
"minItems": 1,
"maxItems": 255,
"items": {
"type": "object",
"properties": {
"channelGroupName": {
"type": "string",
"minLength": 1,
"maxLength": 20,
"pattern": "\\w*"
},
"messages": {
"type": "array",
"minItems": 1,
"maxItems": 3,
"items": {
"type": "object",
"properties": {
"position": {
"type": "number",
"minimum": 0,
"maximum": 2
},
"additionalMessage": {
"type": "string",
"minLength": 1,
"maxLength": 2000
},
"embed": {
"type": "object",
"properties": {
"position": {
"type": "number",
"minimum": 0,
"maximum": 2
},
"additionalMessage": {
"description": {
"type": "string",
"minLength": 1,
"maxLength": 2000
},
"embed": {
"imageUrl": {
"type": "string",
"minLength": 1,
"maxLength": 2000,
"pattern": "\\s*https?:\/\/\\S+"
},
"color": {
"type": "object",
"properties": {
"description": {
"type": "string",
"minLength": 1,
"maxLength": 2000
"red": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
},
"imageUrl": {
"type": "string",
"minLength": 1,
"maxLength": 2000,
"pattern": "\\s*https?:\/\/\\S+"
"green": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
},
"color": {
"type": "object",
"properties": {
"red": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
},
"green": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
},
"blue": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
}
},
"required": [
"red",
"green",
"blue"
]
"blue": {
"type": "integer",
"minimum": 0,
"default": 0,
"maximum": 255
}
},
"required": [
"red",
"green",
"blue"
]
},
"author": {
"type": "object",
"properties": {
"userId": {
"minimum": 1,
"maximum": 18446744073709551615,
"type": "integer"
},
"author": {
"type": "object",
"properties": {
"userId": {
"minimum": 1,
"maximum": 18446744073709551615,
"type": "integer"
},
"useBot": {
"type": "boolean"
}
},
"additionalProperties": false,
"anyOf": [
{
"required": [
"userId"
]
},
{
"required": [
"useBot"
]
}
]
"useBot": {
"type": "boolean"
}
},
"additionalProperties": false,
"anyOf": [
{
"required": [
"description",
"author"
"userId"
]
},
{
"required": [
"imageUrl",
"author"
"useBot"
]
}
]
@@ -149,41 +130,56 @@
"anyOf": [
{
"required": [
"additionalMessage",
"position"
"description",
"author"
]
},
{
"required": [
"embed",
"position"
]
},
{
"required": [
"additionalMessage",
"embed",
"position"
"imageUrl",
"author"
]
}
]
}
},
"additionalProperties": false,
"anyOf": [
{
"required": [
"additionalMessage",
"position"
]
},
{
"required": [
"embed",
"position"
]
},
{
"required": [
"additionalMessage",
"embed",
"position"
]
}
]
}
},
"additionalProperties": false,
"required": [
"channelGroupName",
"messages"
]
}
}
},
"additionalProperties": false,
"required": [
"channelGroupName",
"messages"
]
}
},
"additionalProperties": false,
"required": [
"faqCommandName",
"responses"
]
}
]
}
},
"additionalProperties": false,
"required": [
"faqCommandName",
"responses"
]
}
}