Skip to content

Commit

Permalink
add yaml validation for litcaltest server
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed May 2, 2024
1 parent a359952 commit 02b7398
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions LitCalHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,37 @@ private function validateCalendar( string $Calendar, int $Year, string $category
$this->sendMessage( $to, $message );
}
break;
case "YAML":
try {
$yamlData = yaml_parse( $data );
if( $yamlData ) {
$message = new stdClass();
$message->type = "success";
$message->text = "The $category of $Calendar for the year $Year was successfully decoded as YAML";
$message->classes = ".calendar-$Calendar.json-valid.year-$Year";
$this->sendMessage( $to, $message );

$validationResult = $this->validateDataAgainstSchema( $yamlData, LitSchema::LITCAL );
if( gettype( $validationResult ) === 'boolean' && $validationResult === true ) {
$message = new stdClass();
$message->type = "success";
$message->text = "The $category of $Calendar for the year $Year was successfully validated against the Schema " . LitSchema::LITCAL;
$message->classes = ".calendar-$Calendar.schema-valid.year-$Year";
$this->sendMessage( $to, $message );
}
else if( gettype( $validationResult === 'object' ) ) {
$validationResult->classes = ".calendar-$Calendar.schema-valid.year-$Year";
$this->sendMessage( $to, $validationResult );
}
}
} catch (Exception $ex) {
$message = new stdClass();
$message->type = "error";
$message->text = "There was an error decoding the $category of $Calendar for the year $Year from the URL " . self::LitCalBaseUrl . $req . " as YAML: " . $ex->getMessage();
$message->classes = ".calendar-$Calendar.json-valid.year-$Year";
$this->sendMessage( $to, $message );
}
break;
case "JSON":
default:
$jsonData = json_decode( $data );
Expand Down

0 comments on commit 02b7398

Please sign in to comment.