Make sure the LAX_SCHEMA handling disables required/additionalProperties as it used to do but strict schema requires properties only for the composer schema

main
Jordi Boggiano 3 years ago committed by GitHub
parent 7366b8e362
commit 1bfec451e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -180,15 +180,15 @@ class JsonFile
{ {
$content = file_get_contents($this->path); $content = file_get_contents($this->path);
$data = json_decode($content); $data = json_decode($content);
$requiredSchemaData = array();
if (null === $data && 'null' !== $content) { if (null === $data && 'null' !== $content) {
self::validateSyntax($content, $this->path); self::validateSyntax($content, $this->path);
} }
$isComposerSchemaFile = false;
if (null === $schemaFile) { if (null === $schemaFile) {
$isComposerSchemaFile = true;
$schemaFile = __DIR__ . self::COMPOSER_SCHEMA_PATH; $schemaFile = __DIR__ . self::COMPOSER_SCHEMA_PATH;
$requiredSchemaData = array('name', 'description');
} }
// Prepend with file:// only when not using a special schema already (e.g. in the phar) // Prepend with file:// only when not using a special schema already (e.g. in the phar)
@ -198,16 +198,17 @@ class JsonFile
$schemaData = (object) array('$ref' => $schemaFile); $schemaData = (object) array('$ref' => $schemaFile);
if ($schema !== self::LAX_SCHEMA) { if ($schema === self::LAX_SCHEMA) {
$schemaData->additionalProperties = true;
$schemaData->required = array();
} elseif ($schema === self::STRICT_SCHEMA && $isComposerSchemaFile) {
$schemaData->additionalProperties = false; $schemaData->additionalProperties = false;
$schemaData->required = $requiredSchemaData; $schemaData->required = array('name', 'description');
} }
$validator = new Validator(); $validator = new Validator();
$validator->check($data, $schemaData); $validator->check($data, $schemaData);
// TODO add more validation like check version constraints and such, perhaps build that into the arrayloader?
if (!$validator->isValid()) { if (!$validator->isValid()) {
$errors = array(); $errors = array();
foreach ((array) $validator->getErrors() as $error) { foreach ((array) $validator->getErrors() as $error) {

Loading…
Cancel
Save