Skip to content

Commit fde5588

Browse files
cconard96cedric-anne
authored andcommitted
add missing completename and level properties in HLAPI
1 parent c72e92f commit fde5588

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

CHANGELOG.md

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

1920
### Changed
2021
- Added High-Level API version 2.1. Make sure you are pinning your requests to a specific version (Ex: `/api.php/v2.0`) if needed to exclude endpoints/properties added in later versions. See version pinning in the getting started documentation `/api.php/getting-started`.

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,19 @@ class: User::class,
541541
}
542542
}
543543

544+
// Post v2 additions to general assets
545+
$schemas['SoftwareLicense']['properties']['completename'] = [
546+
'x-version-introduced' => '2.1.0',
547+
'type' => Doc\Schema::TYPE_STRING,
548+
'readOnly' => true,
549+
];
550+
$schemas['SoftwareLicense']['properties']['level'] = [
551+
'x-version-introduced' => '2.1.0',
552+
'type' => Doc\Schema::TYPE_INTEGER,
553+
'readOnly' => true,
554+
];
555+
556+
// Additional asset schemas
544557
$schemas['Cartridge'] = [
545558
'x-version-introduced' => '2.0',
546559
'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
@@ -123,6 +123,11 @@ public static function getRawKnownSchemas(): array
123123
],
124124
'name' => ['type' => Doc\Schema::TYPE_STRING],
125125
'completename' => ['type' => Doc\Schema::TYPE_STRING],
126+
'level' => [
127+
'x-version-introduced' => '2.1.0',
128+
'type' => Doc\Schema::TYPE_INTEGER,
129+
'readOnly' => true,
130+
],
126131
'comment' => ['type' => Doc\Schema::TYPE_STRING],
127132
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
128133
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
@@ -695,6 +700,17 @@ public static function getRawKnownSchemas(): array
695700
],
696701
'name' => ['type' => Doc\Schema::TYPE_STRING],
697702
'is_active' => ['type' => Doc\Schema::TYPE_BOOLEAN],
703+
'completename' => [
704+
'x-version-introduced' => '2.1.0',
705+
'type' => Doc\Schema::TYPE_STRING,
706+
'readOnly' => true,
707+
],
708+
'parent' => self::getDropdownTypeSchema(class: TaskCategory::class, full_schema: 'TaskCategory') + ['x-version-introduced' => '2.1.0'],
709+
'level' => [
710+
'x-version-introduced' => '2.1.0',
711+
'type' => Doc\Schema::TYPE_INTEGER,
712+
'readOnly' => true,
713+
],
698714
],
699715
];
700716

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,23 @@ protected static function getRawKnownSchemas(): array
391391
],
392392
];
393393

394+
// Post v2 additions
395+
$schemas['License']['properties']['is_recursive'] = [
396+
'x-version-introduced' => '2.1.0',
397+
'type' => Doc\Schema::TYPE_BOOLEAN,
398+
'readOnly' => true,
399+
];
400+
$schemas['License']['properties']['completename'] = [
401+
'x-version-introduced' => '2.1.0',
402+
'type' => Doc\Schema::TYPE_STRING,
403+
'readOnly' => true,
404+
];
405+
$schemas['License']['properties']['level'] = [
406+
'x-version-introduced' => '2.1.0',
407+
'type' => Doc\Schema::TYPE_INTEGER,
408+
'readOnly' => true,
409+
];
410+
394411
$schemas['Infocom'] = [
395412
'x-version-introduced' => '2.0',
396413
'type' => Doc\Schema::TYPE_OBJECT,

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,37 @@ 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+
90121
public function testHLAPIDisabled()
91122
{
92123
global $CFG_GLPI;

0 commit comments

Comments
 (0)