Skip to content

Commit 0e1d78d

Browse files
cconard96cedric-anne
authored andcommitted
add missing properties in HLAPI
1 parent ad0d1af commit 0e1d78d

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The present file will list all changes made to the project; according to the
1717
- New schemas/endpoints for Reminders, RSS Feeds, and Reservations in the High-Level API v2.1.
1818
- `date_password_change`, `location`, `authtype`, `last_login`, `default_profile` and `default_entity` properties for the User schema in the High-Level API v2.1.
1919
- New UserPreferences schema and endpoints in the High-Level API v2.1.
20+
- Some missing `completename` and `level` properties for some schemas in High-Level API v2.1.
2021

2122
### Changed
2223
- Fixed `id` property in dropdown/linked object properties in schemas in High-Level API showing as readOnly when they are writable.

src/Glpi/Api/HL/Controller/AssetController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,19 @@ class: User::class,
550550
}
551551
}
552552

553+
// Post v2 additions to general assets
554+
$schemas['SoftwareLicense']['properties']['completename'] = [
555+
'x-version-introduced' => '2.1.0',
556+
'type' => Doc\Schema::TYPE_STRING,
557+
'readOnly' => true,
558+
];
559+
$schemas['SoftwareLicense']['properties']['level'] = [
560+
'x-version-introduced' => '2.1.0',
561+
'type' => Doc\Schema::TYPE_INTEGER,
562+
'readOnly' => true,
563+
];
564+
565+
// Additional asset schemas
553566
$schemas['Cartridge'] = [
554567
'x-version-introduced' => '2.0',
555568
'x-itemtype' => Cartridge::class,

src/Glpi/Api/HL/Controller/ITILController.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public static function getRawKnownSchemas(): array
126126
'type' => Doc\Schema::TYPE_STRING,
127127
'readOnly' => true,
128128
],
129+
'level' => [
130+
'x-version-introduced' => '2.1.0',
131+
'type' => Doc\Schema::TYPE_INTEGER,
132+
'readOnly' => true,
133+
],
129134
'comment' => ['type' => Doc\Schema::TYPE_STRING],
130135
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
131136
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
@@ -697,6 +702,17 @@ public static function getRawKnownSchemas(): array
697702
],
698703
'name' => ['type' => Doc\Schema::TYPE_STRING],
699704
'is_active' => ['type' => Doc\Schema::TYPE_BOOLEAN],
705+
'completename' => [
706+
'x-version-introduced' => '2.1.0',
707+
'type' => Doc\Schema::TYPE_STRING,
708+
'readOnly' => true,
709+
],
710+
'parent' => self::getDropdownTypeSchema(class: TaskCategory::class, full_schema: 'TaskCategory') + ['x-version-introduced' => '2.1.0'],
711+
'level' => [
712+
'x-version-introduced' => '2.1.0',
713+
'type' => Doc\Schema::TYPE_INTEGER,
714+
'readOnly' => true,
715+
],
700716
],
701717
];
702718

src/Glpi/Api/HL/Controller/ManagementController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,23 @@ protected static function getRawKnownSchemas(): array
395395
],
396396
];
397397

398+
// Post v2 additions
399+
$schemas['License']['properties']['is_recursive'] = [
400+
'x-version-introduced' => '2.1.0',
401+
'type' => Doc\Schema::TYPE_BOOLEAN,
402+
'readOnly' => true,
403+
];
404+
$schemas['License']['properties']['completename'] = [
405+
'x-version-introduced' => '2.1.0',
406+
'type' => Doc\Schema::TYPE_STRING,
407+
'readOnly' => true,
408+
];
409+
$schemas['License']['properties']['level'] = [
410+
'x-version-introduced' => '2.1.0',
411+
'type' => Doc\Schema::TYPE_INTEGER,
412+
'readOnly' => true,
413+
];
414+
398415
$schemas['Infocom'] = [
399416
'x-version-introduced' => '2.0',
400417
'type' => Doc\Schema::TYPE_OBJECT,

tests/functional/Glpi/Api/HL/RouterTest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,83 @@ public function testAllSchemasHaveVersioningInfo()
8787
$this->assertEmpty($schemas_missing_versions, 'Schemas missing versioning info: ' . implode(', ', $schemas_missing_versions));
8888
}
8989

90+
/**
91+
* Ensure all schemas for CommonTreeDropdown itemtypes have the correct readonly properties such as completename and level
92+
* @return void
93+
*/
94+
public function testAllTreeSchemasHaveReadonlyProps()
95+
{
96+
$router = Router::getInstance();
97+
$controllers = $router->getControllers();
98+
99+
$schemas_errors = [];
100+
$required_readonly_props = ['completename', 'level'];
101+
foreach ($controllers as $controller) {
102+
$schemas = $controller::getKnownSchemas(null);
103+
foreach ($schemas as $schema_name => $schema) {
104+
if (!isset($schema['x-itemtype']) || !is_subclass_of($schema['x-itemtype'], \CommonTreeDropdown::class)) {
105+
continue;
106+
}
107+
foreach ($required_readonly_props as $prop) {
108+
if (!isset($schema['properties'][$prop])) {
109+
$schemas_errors[] = "Schema $schema_name in " . $controller::class . " is missing property '$prop'";
110+
} else {
111+
if (!isset($schema['properties'][$prop]['readOnly']) || $schema['properties'][$prop]['readOnly'] !== true) {
112+
$schemas_errors[] = "Property '$prop' in schema $schema_name in " . $controller::class . " is not marked as readOnly";
113+
}
114+
}
115+
}
116+
}
117+
}
118+
$this->assertEmpty($schemas_errors, "Tree schemas with errors: \n" . implode("\n", $schemas_errors));
119+
}
120+
121+
/**
122+
* Ensure there are not multiple schemas for the same itemtype (identified by x-itemtype).
123+
* In some cases, like user preferences, we may have multiple schemas for the same itemtype, but those extra schemas
124+
* should use x-table instead to point to the table directly.
125+
* @return void
126+
*/
127+
public function testNoDuplicateItemtypeSchemas()
128+
{
129+
$router = Router::getInstance();
130+
$controllers = $router->getControllers();
131+
132+
$seen_itemtypes = [];
133+
$duplicate_schemas = [];
134+
$all_schemas = [];
135+
foreach ($controllers as $controller) {
136+
/** @noinspection SlowArrayOperationsInLoopInspection */
137+
$all_schemas = array_merge($all_schemas, $controller::getKnownSchemas(null));
138+
}
139+
foreach ($all_schemas as $schema_name => $schema) {
140+
// Ignore known duplicate. Cannot fix until v3
141+
if ($schema_name === 'SoftwareLicense') {
142+
continue;
143+
}
144+
if (isset($schema['x-itemtype'])) {
145+
$itemtype = $schema['x-itemtype'];
146+
if (isset($seen_itemtypes[$itemtype])) {
147+
$duplicate_schemas[] = "Itemtype $itemtype has multiple schemas: " . $seen_itemtypes[$itemtype] . " and $schema_name";
148+
} else {
149+
$seen_itemtypes[$itemtype] = $schema_name;
150+
}
151+
}
152+
}
153+
ksort($all_schemas['SoftwareLicense']['properties']);
154+
ksort($all_schemas['License']['properties']);
155+
$this->assertEquals(
156+
array_keys($all_schemas['SoftwareLicense']['properties']),
157+
array_keys($all_schemas['License']['properties']),
158+
'Schemas SoftwareLicense and License should have the same properties',
159+
);
160+
// Ensure the duplication gets removed in v3
161+
if (version_compare(Router::API_VERSION, '3.0.0', '>=')) {
162+
$this->assertNotContains('SoftwareLicense', $seen_itemtypes, 'Schema SoftwareLicense should be removed in v3');
163+
}
164+
$this->assertEmpty($duplicate_schemas, "Duplicate itemtype schemas found: \n" . implode("\n", $duplicate_schemas));
165+
}
166+
90167
public function testHLAPIDisabled()
91168
{
92169
global $CFG_GLPI;

0 commit comments

Comments
 (0)