mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-20 14:36:52 +00:00
validate json against json schema
Signed-off-by: Simon L <szaimen@e.mail.de>
This commit is contained in:
parent
3e04dd5c2e
commit
66dfd9df8e
3 changed files with 90 additions and 3 deletions
|
|
@ -12,6 +12,7 @@ use AIO\Container\State\RunningState;
|
|||
use AIO\Data\ConfigurationManager;
|
||||
use AIO\Data\DataConst;
|
||||
use AIO\Docker\DockerActionManager;
|
||||
use JsonSchema\Validator;
|
||||
|
||||
class ContainerDefinitionFetcher
|
||||
{
|
||||
|
|
@ -40,12 +41,27 @@ class ContainerDefinitionFetcher
|
|||
throw new \Exception("The provided id " . $id . " was not found in the container definition.");
|
||||
}
|
||||
|
||||
private function validateJson(object $data): void {
|
||||
// Validate against json schema
|
||||
$validator = new Validator;
|
||||
$validator->validate($data, (object)[file_get_contents(__DIR__ . '/../containers-schema.json')]);
|
||||
if (!$validator->isValid()) {
|
||||
error_log("JSON does not validate. Violations:");
|
||||
foreach ($validator->getErrors() as $error) {
|
||||
error_log(printf("[%s] %s\n", $error['property'], $error['message']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function GetDefinition(bool $latest): array
|
||||
{
|
||||
$data = json_decode(file_get_contents(__DIR__ . '/../containers.json'), true);
|
||||
$rawData = file_get_contents(__DIR__ . '/../containers.json');
|
||||
$objectData = json_decode($rawData, false);
|
||||
$this->validateJson($objectData);
|
||||
$data = json_decode($rawData, true);
|
||||
|
||||
$containers = [];
|
||||
foreach ($data['aio_services_v1'] as $entry) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue