diff --git a/.gitignore b/.gitignore index 1a5f4b5..a2b1aef 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,6 @@ build/ .DS_Store ### Other Stuff ### -**/resources/config*.json \ No newline at end of file +**/resources/config*.json +!**/resources/config.example.json +!**/resources/config.schema.json \ No newline at end of file diff --git a/src/main/java/net/hypr/doki/Config.java b/src/main/java/net/hypr/doki/Config.java index dd9e7af..da1e92d 100644 --- a/src/main/java/net/hypr/doki/Config.java +++ b/src/main/java/net/hypr/doki/Config.java @@ -19,12 +19,11 @@ public class Config { * @throws IOException if the config JSON could not be read */ public static Config readConfig() throws IOException { - System.out.println(Path.of("config.json")); try (InputStream in=Thread.currentThread().getContextClassLoader().getResourceAsStream("config.json")) { assert in != null; Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8); return new Gson().fromJson(reader, Config.class); - } catch (IOException e) { + } catch (IOException | NullPointerException e) { throw new IOException(""" config.json was not found in the root folder (of the project), did you forget to put it ? Example structure: diff --git a/src/main/resources/config.schema.json b/src/main/resources/config.schema.json new file mode 100644 index 0000000..8649af9 --- /dev/null +++ b/src/main/resources/config.schema.json @@ -0,0 +1,42 @@ + + +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "token": { + "type": "string" + }, + "prefix": { + "type": "string" + }, + "mariadb": { + "type": "object", + "properties": { + "host": { + "type": "string" + }, + "user": { + "type": "string" + }, + "password": { + "type": "string" + }, + "database": { + "type": "string" + } + }, + "required": [ + "host", + "user", + "password", + "database" + ] + } + }, + "required": [ + "token", + "prefix", + "mariadb" + ] +} \ No newline at end of file