[tests-only][full-ci]Refactor check for no of items in json schema (#8632)

* Refactor check for no of items in json schema

* test(api): fix json schema

---------

Co-authored-by: Saw-jan <saw.jan.grg3e@gmail.com>
This commit is contained in:
Sagar Gurung
2024-03-13 16:54:40 +05:45
committed by GitHub
co-authored by Saw-jan
parent 0e83859abf
commit dc98e7a6b9
3 changed files with 141 additions and 141 deletions
@@ -1252,15 +1252,16 @@ class FeatureContext extends BehatVariablesContext {
$propNames = $schemaObj->getPropertyNames();
$props = $schemaObj->getProperties();
foreach ($propNames as $propName) {
switch ($props->type) {
$schema = $props->$propName;
switch ($schema->type) {
case "array":
$this->validateSchemaArray($props->$propName);
$this->validateSchemaArray($schema);
break;
default:
break;
}
// traverse for nested properties
$this->validateSchemaObject($props->$propName);
$this->validateSchemaObject($schema);
}
}
@@ -1318,12 +1319,11 @@ class FeatureContext extends BehatVariablesContext {
Assert::assertNotNull($element->oneOf, "'oneOf' is required to assert more than one elements");
}
Assert::fail("'$validator' should be an object not an array");
break;
}
Assert::assertFalse($value->allOf || $value->anyOf, "'allOf' and 'anyOf' are not allowed in array");
Assert::assertNotNull($value->oneOf, "'oneOf' is required to assert more than one elements");
Assert::assertTrue(\is_array($value->oneOf), "'oneOf' should be an array");
Assert::assertEquals($schemaObj->maxItems, \count($value->oneOf), "There are more 'oneOf' elements than expected by 'maxItems'");
Assert::assertEquals($schemaObj->maxItems, \count($value->oneOf), "Expected " . $schemaObj->maxItems . " 'oneOf' items but got " . \count($value->oneOf));
}
Assert::assertTrue(\is_object($value), "'$validator' should be an object when expecting 1 element");
break;