Hello config schema
This commit is contained in:
parent
e4de0998d3
commit
27fe67062b
3 changed files with 46 additions and 3 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -38,4 +38,6 @@ build/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
### Other Stuff ###
|
### Other Stuff ###
|
||||||
**/resources/config*.json
|
**/resources/config*.json
|
||||||
|
!**/resources/config.example.json
|
||||||
|
!**/resources/config.schema.json
|
|
@ -19,12 +19,11 @@ public class Config {
|
||||||
* @throws IOException if the config JSON could not be read
|
* @throws IOException if the config JSON could not be read
|
||||||
*/
|
*/
|
||||||
public static Config readConfig() throws IOException {
|
public static Config readConfig() throws IOException {
|
||||||
System.out.println(Path.of("config.json"));
|
|
||||||
try (InputStream in=Thread.currentThread().getContextClassLoader().getResourceAsStream("config.json")) {
|
try (InputStream in=Thread.currentThread().getContextClassLoader().getResourceAsStream("config.json")) {
|
||||||
assert in != null;
|
assert in != null;
|
||||||
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
|
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
|
||||||
return new Gson().fromJson(reader, Config.class);
|
return new Gson().fromJson(reader, Config.class);
|
||||||
} catch (IOException e) {
|
} catch (IOException | NullPointerException e) {
|
||||||
throw new IOException("""
|
throw new IOException("""
|
||||||
config.json was not found in the root folder (of the project), did you forget to put it ?
|
config.json was not found in the root folder (of the project), did you forget to put it ?
|
||||||
Example structure:
|
Example structure:
|
||||||
|
|
42
src/main/resources/config.schema.json
Normal file
42
src/main/resources/config.schema.json
Normal file
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in a new issue