Skip to content

Commit 2ee6dbb

Browse files
committed
hlapi some schema validity fixes and changes
1 parent adf56be commit 2ee6dbb

File tree

14 files changed

+292
-27
lines changed

14 files changed

+292
-27
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ The present file will list all changes made to the project; according to the
66
## [11.0.2] unreleased
77

88
### Added
9+
- Some missing `readOnly` flags for properties for some schemas in High-Level API.
10+
- Some missing UUID and color pattern constraints for properties in some schemas in High-Level API.
11+
- Some missing `completename` and `level` properties for some schemas in High-Level API v2.1.
912

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

1216
### Deprecated
1317

1418
### Removed
19+
- Invalid `max_power` property in the `PassiveDCEquipmentModel` schema in High-Level API.
20+
- Invalid `chipset` property in the `SystemboardModel` schema in High-Level API.
21+
- Invalid `date_creation` and `date_mod` properties in the `GenericDeviceType` and `SensorType` schemas in High-Level API.
22+
- Invalid `completename` property in the `TicketTemplate`, `ChangeTemplate`, and `ProblemTemplate` schemas in High-Level API.
1523

1624
### API changes
1725

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,19 @@ public static function getDropdownTypeSchema(string $class, ?string $field = nul
154154
'id' => [
155155
'type' => Doc\Schema::TYPE_INTEGER,
156156
'format' => Doc\Schema::FORMAT_INTEGER_INT64,
157-
'readOnly' => $class !== Entity::class,
158157
],
159-
$name_field => ['type' => Doc\Schema::TYPE_STRING],
158+
$name_field => [
159+
'type' => Doc\Schema::TYPE_STRING,
160+
'readOnly' => true
161+
],
160162
],
161163
];
162164
if ($full_schema !== null) {
163165
$schema['x-full-schema'] = $full_schema;
164166
}
167+
if ($class === Entity::class) {
168+
$schema['properties']['id']['readOnly'] = true;
169+
}
165170
return $schema;
166171
}
167172

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public static function getRawKnownSchemas(): array
212212
'completename' => [
213213
'type' => Doc\Schema::TYPE_STRING,
214214
'description' => 'Complete name',
215+
'readOnly' => true,
215216
],
216217
'parent' => [
217218
'type' => Doc\Schema::TYPE_OBJECT,
@@ -238,6 +239,7 @@ public static function getRawKnownSchemas(): array
238239
'level' => [
239240
'type' => Doc\Schema::TYPE_INTEGER,
240241
'description' => 'Level',
242+
'readOnly' => true,
241243
],
242244
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
243245
],
@@ -264,6 +266,7 @@ public static function getRawKnownSchemas(): array
264266
'completename' => [
265267
'type' => Doc\Schema::TYPE_STRING,
266268
'description' => 'Complete name',
269+
'readOnly' => true,
267270
],
268271
'parent' => [
269272
'type' => Doc\Schema::TYPE_OBJECT,
@@ -290,6 +293,7 @@ public static function getRawKnownSchemas(): array
290293
'level' => [
291294
'type' => Doc\Schema::TYPE_INTEGER,
292295
'description' => 'Level',
296+
'readOnly' => true,
293297
],
294298
],
295299
],

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,16 @@ public static function getRawKnownSchemas(): array
173173
'readOnly' => true,
174174
],
175175
'name' => ['type' => Doc\Schema::TYPE_STRING],
176-
'completename' => ['type' => Doc\Schema::TYPE_STRING],
176+
'completename' => [
177+
'type' => Doc\Schema::TYPE_STRING,
178+
'readOnly' => true,
179+
],
177180
'comment' => ['type' => Doc\Schema::TYPE_STRING],
178181
'parent' => self::getDropdownTypeSchema(class: SoftwareCategory::class, full_schema: 'SoftwareCategory'),
179-
'level' => ['type' => Doc\Schema::TYPE_INTEGER],
182+
'level' => [
183+
'type' => Doc\Schema::TYPE_INTEGER,
184+
'readOnly' => true,
185+
],
180186
],
181187
];
182188

@@ -296,7 +302,6 @@ public static function getRawKnownSchemas(): array
296302
'depth' => ['type' => Doc\Schema::TYPE_NUMBER, 'format' => Doc\Schema::FORMAT_NUMBER_FLOAT],
297303
'power_connections' => ['type' => Doc\Schema::TYPE_INTEGER],
298304
'power_consumption' => ['type' => Doc\Schema::TYPE_INTEGER],
299-
'max_power' => ['type' => Doc\Schema::TYPE_INTEGER],
300305
'is_half_rack' => ['type' => Doc\Schema::TYPE_BOOLEAN],
301306
'date_creation' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
302307
'date_mod' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
@@ -530,7 +535,11 @@ class: User::class,
530535
}
531536

532537
if ($asset->isField('uuid')) {
533-
$schemas[$schema_name]['properties']['uuid'] = ['type' => Doc\Schema::TYPE_STRING];
538+
$schemas[$schema_name]['properties']['uuid'] = [
539+
'type' => Doc\Schema::TYPE_STRING,
540+
'pattern' => Doc\Schema::PATTERN_UUIDV4,
541+
'readOnly' => true,
542+
];
534543
}
535544
if ($asset->isField('autoupdatesystems_id')) {
536545
$schemas[$schema_name]['properties']['autoupdatesystem'] = self::getDropdownTypeSchema(AutoUpdateSystem::class);
@@ -541,6 +550,19 @@ class: User::class,
541550
}
542551
}
543552

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
544566
$schemas['Cartridge'] = [
545567
'x-version-introduced' => '2.0',
546568
'x-itemtype' => Cartridge::class,
@@ -820,7 +842,10 @@ class: User::class,
820842
],
821843
'is_deleted' => ['type' => Doc\Schema::TYPE_BOOLEAN],
822844
'is_update' => ['type' => Doc\Schema::TYPE_BOOLEAN],
823-
'is_valid' => ['type' => Doc\Schema::TYPE_BOOLEAN],
845+
'is_valid' => [
846+
'type' => Doc\Schema::TYPE_BOOLEAN,
847+
'readOnly' => true,
848+
],
824849
'date_creation' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
825850
'date_mod' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
826851
],
@@ -939,7 +964,10 @@ class: User::class,
939964
'room' => self::getDropdownTypeSchema(class: DCRoom::class, full_schema: 'DCRoom'),
940965
'room_orientation' => ['type' => Doc\Schema::TYPE_INTEGER, 'format' => Doc\Schema::FORMAT_INTEGER_INT32],
941966
'position' => ['type' => Doc\Schema::TYPE_STRING],
942-
'bgcolor' => ['type' => Doc\Schema::TYPE_STRING],
967+
'bgcolor' => [
968+
'type' => Doc\Schema::TYPE_STRING,
969+
'pattern' => Doc\Schema::PATTERN_COLOR_HEX,
970+
],
943971
'max_power' => ['type' => Doc\Schema::TYPE_INTEGER, 'format' => Doc\Schema::FORMAT_INTEGER_INT32],
944972
'measured_power' => [
945973
'type' => Doc\Schema::TYPE_INTEGER,
@@ -999,7 +1027,10 @@ class: User::class,
9991027
- 1: Rear
10001028
EOT,
10011029
],
1002-
'bgcolor' => ['type' => Doc\Schema::TYPE_STRING],
1030+
'bgcolor' => [
1031+
'type' => Doc\Schema::TYPE_STRING,
1032+
'pattern' => Doc\Schema::PATTERN_COLOR_HEX,
1033+
],
10031034
'position_horizontal' => [
10041035
'type' => Doc\Schema::TYPE_INTEGER,
10051036
'format' => Doc\Schema::FORMAT_INTEGER_INT32,
@@ -1411,6 +1442,7 @@ public static function getAssetTypes(bool $types_only = true): array
14111442

14121443
if ($assets === null) {
14131444
$assets = [];
1445+
//TODO remove SoftwareLicense in v3 as it is a duplicate of License in the Management Controller
14141446
$types = ['Computer', 'Monitor', 'NetworkEquipment',
14151447
'Peripheral', 'Phone', 'Printer', 'SoftwareLicense',
14161448
'Certificate', 'Unmanaged', 'Appliance',

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected static function getRawKnownSchemas(): array
190190
'product_number' => ['type' => Doc\Schema::TYPE_STRING],
191191
];
192192

193-
return [
193+
$schemas = [
194194
'BatteryType' => [
195195
'x-version-introduced' => '2.0',
196196
'x-itemtype' => DeviceBatteryType::class,
@@ -517,9 +517,7 @@ protected static function getRawKnownSchemas(): array
517517
'x-version-introduced' => '2.0',
518518
'x-itemtype' => DeviceMotherboardModel::class,
519519
'type' => Doc\Schema::TYPE_OBJECT,
520-
'properties' => $common_device_model_properties + [
521-
'chipset' => ['type' => Doc\Schema::TYPE_STRING],
522-
],
520+
'properties' => $common_device_model_properties,
523521
],
524522
'Systemboard' => [
525523
'x-version-introduced' => '2.0',
@@ -706,6 +704,16 @@ protected static function getRawKnownSchemas(): array
706704
],
707705
],
708706
];
707+
708+
// Remove some properties that refer to missing fields in the database, but should be added later
709+
unset(
710+
$schemas['GenericDeviceType']['properties']['date_creation'],
711+
$schemas['GenericDeviceType']['properties']['date_mod'],
712+
$schemas['SensorType']['properties']['date_creation'],
713+
$schemas['SensorType']['properties']['date_mod']
714+
);
715+
716+
return $schemas;
709717
}
710718

711719
public static function getComponentTypes(): array

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,20 @@ protected static function getRawKnownSchemas(): array
8888
'readOnly' => true,
8989
],
9090
'name' => ['type' => Doc\Schema::TYPE_STRING],
91-
'completename' => ['type' => Doc\Schema::TYPE_STRING],
91+
'completename' => [
92+
'type' => Doc\Schema::TYPE_STRING,
93+
'readOnly' => true,
94+
],
9295
'code' => ['type' => Doc\Schema::TYPE_STRING],
9396
'alias' => ['type' => Doc\Schema::TYPE_STRING],
9497
'comment' => ['type' => Doc\Schema::TYPE_STRING],
9598
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
9699
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
97100
'parent' => self::getDropdownTypeSchema(class: Location::class, full_schema: 'Location'),
98-
'level' => ['type' => Doc\Schema::TYPE_INTEGER],
101+
'level' => [
102+
'type' => Doc\Schema::TYPE_INTEGER,
103+
'readOnly' => true,
104+
],
99105
'room' => ['type' => Doc\Schema::TYPE_STRING],
100106
'building' => ['type' => Doc\Schema::TYPE_STRING],
101107
'address' => ['type' => Doc\Schema::TYPE_STRING],
@@ -123,12 +129,18 @@ protected static function getRawKnownSchemas(): array
123129
'readOnly' => true,
124130
],
125131
'name' => ['type' => Doc\Schema::TYPE_STRING],
126-
'completename' => ['type' => Doc\Schema::TYPE_STRING],
132+
'completename' => [
133+
'type' => Doc\Schema::TYPE_STRING,
134+
'readOnly' => true,
135+
],
127136
'comment' => ['type' => Doc\Schema::TYPE_STRING],
128137
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
129138
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
130139
'parent' => self::getDropdownTypeSchema(class: State::class, full_schema: 'State'),
131-
'level' => ['type' => Doc\Schema::TYPE_INTEGER],
140+
'level' => [
141+
'type' => Doc\Schema::TYPE_INTEGER,
142+
'readOnly' => true,
143+
],
132144
'is_visible_helpdesk' => ['x-field' => 'is_helpdesk_visible', 'type' => Doc\Schema::TYPE_BOOLEAN],
133145
'date_creation' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
134146
'date_mod' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,15 @@ public static function getRawKnownSchemas(): array
118118
'readOnly' => true,
119119
],
120120
'name' => ['type' => Doc\Schema::TYPE_STRING],
121-
'completename' => ['type' => Doc\Schema::TYPE_STRING],
121+
'completename' => [
122+
'type' => Doc\Schema::TYPE_STRING,
123+
'readOnly' => true,
124+
],
125+
'level' => [
126+
'x-version-introduced' => '2.1.0',
127+
'type' => Doc\Schema::TYPE_INTEGER,
128+
'readOnly' => true,
129+
],
122130
'comment' => ['type' => Doc\Schema::TYPE_STRING],
123131
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
124132
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
@@ -135,7 +143,6 @@ public static function getRawKnownSchemas(): array
135143
'readOnly' => true,
136144
],
137145
'name' => ['type' => Doc\Schema::TYPE_STRING],
138-
'completename' => ['type' => Doc\Schema::TYPE_STRING],
139146
'comment' => ['type' => Doc\Schema::TYPE_STRING],
140147
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
141148
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
@@ -494,6 +501,17 @@ public static function getRawKnownSchemas(): array
494501
],
495502
'name' => ['type' => Doc\Schema::TYPE_STRING],
496503
'is_active' => ['type' => Doc\Schema::TYPE_BOOLEAN],
504+
'completename' => [
505+
'x-version-introduced' => '2.1.0',
506+
'type' => Doc\Schema::TYPE_STRING,
507+
'readOnly' => true,
508+
],
509+
'parent' => self::getDropdownTypeSchema(class: TaskCategory::class, full_schema: 'TaskCategory') + ['x-version-introduced' => '2.1.0'],
510+
'level' => [
511+
'x-version-introduced' => '2.1.0',
512+
'type' => Doc\Schema::TYPE_INTEGER,
513+
'readOnly' => true,
514+
],
497515
],
498516
];
499517

@@ -781,7 +799,10 @@ public static function getRawKnownSchemas(): array
781799
],
782800
'name' => ['type' => Doc\Schema::TYPE_STRING],
783801
'comment' => ['type' => Doc\Schema::TYPE_STRING],
784-
'color' => ['type' => Doc\Schema::TYPE_STRING],
802+
'color' => [
803+
'type' => Doc\Schema::TYPE_STRING,
804+
'pattern' => Doc\Schema::PATTERN_COLOR_HEX,
805+
],
785806
'date_creation' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
786807
'date_mod' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
787808
],
@@ -798,7 +819,11 @@ public static function getRawKnownSchemas(): array
798819
'format' => Doc\Schema::FORMAT_INTEGER_INT64,
799820
'readOnly' => true,
800821
],
801-
'uuid' => ['type' => Doc\Schema::TYPE_STRING, 'pattern' => Doc\Schema::PATTERN_UUIDV4],
822+
'uuid' => [
823+
'type' => Doc\Schema::TYPE_STRING,
824+
'pattern' => Doc\Schema::PATTERN_UUIDV4,
825+
'readOnly' => true,
826+
],
802827
'name' => ['type' => Doc\Schema::TYPE_STRING],
803828
'text' => ['type' => Doc\Schema::TYPE_STRING],
804829
'template' => self::getDropdownTypeSchema(class: PlanningExternalEventTemplate::class, full_schema: 'ExternalEventTemplate'),

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,11 @@ protected static function getRawKnownSchemas(): array
304304
}
305305

306306
if ($item->isField('uuid')) {
307-
$schemas[$m_name]['properties']['uuid'] = ['type' => Doc\Schema::TYPE_STRING];
307+
$schemas[$m_name]['properties']['uuid'] = [
308+
'type' => Doc\Schema::TYPE_STRING,
309+
'pattern' => Doc\Schema::PATTERN_UUIDV4,
310+
'readOnly' => true,
311+
];
308312
}
309313
if ($item->isField('autoupdatesystems_id')) {
310314
$schemas[$m_name]['properties']['autoupdatesystem'] = self::getDropdownTypeSchema(AutoUpdateSystem::class);
@@ -369,6 +373,23 @@ protected static function getRawKnownSchemas(): array
369373
],
370374
];
371375

376+
// Post v2 additions
377+
$schemas['License']['properties']['is_recursive'] = [
378+
'x-version-introduced' => '2.1.0',
379+
'type' => Doc\Schema::TYPE_BOOLEAN,
380+
'readOnly' => true,
381+
];
382+
$schemas['License']['properties']['completename'] = [
383+
'x-version-introduced' => '2.1.0',
384+
'type' => Doc\Schema::TYPE_STRING,
385+
'readOnly' => true,
386+
];
387+
$schemas['License']['properties']['level'] = [
388+
'x-version-introduced' => '2.1.0',
389+
'type' => Doc\Schema::TYPE_INTEGER,
390+
'readOnly' => true,
391+
];
392+
372393
$schemas['Infocom'] = [
373394
'x-version-introduced' => '2.0',
374395
'type' => Doc\Schema::TYPE_OBJECT,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ protected static function getRawKnownSchemas(): array
201201
],
202202
'uuid' => [
203203
'type' => Doc\Schema::TYPE_STRING,
204+
'pattern' => Doc\Schema::PATTERN_UUIDV4,
204205
'readOnly' => true,
205206
],
206207
'sub_type' => [

src/Glpi/Api/HL/Doc/Schema.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Schema implements ArrayAccess
6868
public const FORMAT_BOOLEAN_BOOLEAN = 'boolean';
6969

7070
public const PATTERN_UUIDV4 = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i';
71+
public const PATTERN_COLOR_HEX = '/^#([A-Fa-f0-9]{6})$/';
7172

7273
public function __construct(
7374
private string $type,

0 commit comments

Comments
 (0)