Skip to content

Commit e16d13d

Browse files
authored
[HLAPI] Some schema validity fixes and changes
1 parent ae9d950 commit e16d13d

File tree

12 files changed

+166
-26
lines changed

12 files changed

+166
-26
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ 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.
911

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

1215
### Deprecated
1316

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

1623
### API changes
1724

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: 26 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);
@@ -820,7 +829,10 @@ class: User::class,
820829
],
821830
'is_deleted' => ['type' => Doc\Schema::TYPE_BOOLEAN],
822831
'is_update' => ['type' => Doc\Schema::TYPE_BOOLEAN],
823-
'is_valid' => ['type' => Doc\Schema::TYPE_BOOLEAN],
832+
'is_valid' => [
833+
'type' => Doc\Schema::TYPE_BOOLEAN,
834+
'readOnly' => true,
835+
],
824836
'date_creation' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
825837
'date_mod' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
826838
],
@@ -939,7 +951,10 @@ class: User::class,
939951
'room' => self::getDropdownTypeSchema(class: DCRoom::class, full_schema: 'DCRoom'),
940952
'room_orientation' => ['type' => Doc\Schema::TYPE_INTEGER, 'format' => Doc\Schema::FORMAT_INTEGER_INT32],
941953
'position' => ['type' => Doc\Schema::TYPE_STRING],
942-
'bgcolor' => ['type' => Doc\Schema::TYPE_STRING],
954+
'bgcolor' => [
955+
'type' => Doc\Schema::TYPE_STRING,
956+
'pattern' => Doc\Schema::PATTERN_COLOR_HEX,
957+
],
943958
'max_power' => ['type' => Doc\Schema::TYPE_INTEGER, 'format' => Doc\Schema::FORMAT_INTEGER_INT32],
944959
'measured_power' => [
945960
'type' => Doc\Schema::TYPE_INTEGER,
@@ -999,7 +1014,10 @@ class: User::class,
9991014
- 1: Rear
10001015
EOT,
10011016
],
1002-
'bgcolor' => ['type' => Doc\Schema::TYPE_STRING],
1017+
'bgcolor' => [
1018+
'type' => Doc\Schema::TYPE_STRING,
1019+
'pattern' => Doc\Schema::PATTERN_COLOR_HEX,
1020+
],
10031021
'position_horizontal' => [
10041022
'type' => Doc\Schema::TYPE_INTEGER,
10051023
'format' => Doc\Schema::FORMAT_INTEGER_INT32,
@@ -1411,6 +1429,7 @@ public static function getAssetTypes(bool $types_only = true): array
14111429

14121430
if ($assets === null) {
14131431
$assets = [];
1432+
//TODO remove SoftwareLicense in v3 as it is a duplicate of License in the Management Controller
14141433
$types = ['Computer', 'Monitor', 'NetworkEquipment',
14151434
'Peripheral', 'Phone', 'Printer', 'SoftwareLicense',
14161435
'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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ 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+
],
122125
'comment' => ['type' => Doc\Schema::TYPE_STRING],
123126
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
124127
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
@@ -135,7 +138,6 @@ public static function getRawKnownSchemas(): array
135138
'readOnly' => true,
136139
],
137140
'name' => ['type' => Doc\Schema::TYPE_STRING],
138-
'completename' => ['type' => Doc\Schema::TYPE_STRING],
139141
'comment' => ['type' => Doc\Schema::TYPE_STRING],
140142
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
141143
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
@@ -781,7 +783,10 @@ public static function getRawKnownSchemas(): array
781783
],
782784
'name' => ['type' => Doc\Schema::TYPE_STRING],
783785
'comment' => ['type' => Doc\Schema::TYPE_STRING],
784-
'color' => ['type' => Doc\Schema::TYPE_STRING],
786+
'color' => [
787+
'type' => Doc\Schema::TYPE_STRING,
788+
'pattern' => Doc\Schema::PATTERN_COLOR_HEX,
789+
],
785790
'date_creation' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
786791
'date_mod' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
787792
],
@@ -798,7 +803,11 @@ public static function getRawKnownSchemas(): array
798803
'format' => Doc\Schema::FORMAT_INTEGER_INT64,
799804
'readOnly' => true,
800805
],
801-
'uuid' => ['type' => Doc\Schema::TYPE_STRING, 'pattern' => Doc\Schema::PATTERN_UUIDV4],
806+
'uuid' => [
807+
'type' => Doc\Schema::TYPE_STRING,
808+
'pattern' => Doc\Schema::PATTERN_UUIDV4,
809+
'readOnly' => true,
810+
],
802811
'name' => ['type' => Doc\Schema::TYPE_STRING],
803812
'text' => ['type' => Doc\Schema::TYPE_STRING],
804813
'template' => self::getDropdownTypeSchema(class: PlanningExternalEventTemplate::class, full_schema: 'ExternalEventTemplate'),

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

Lines changed: 5 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);

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)