Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ The present file will list all changes made to the project; according to the
## [11.0.2] unreleased

### Added
- Some missing `readOnly` flags for properties for some schemas in High-Level API.
- Some missing UUID and color pattern constraints for properties in some schemas in High-Level API.

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

### Deprecated

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

### API changes

Expand Down
9 changes: 7 additions & 2 deletions src/Glpi/Api/HL/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,19 @@ public static function getDropdownTypeSchema(string $class, ?string $field = nul
'id' => [
'type' => Doc\Schema::TYPE_INTEGER,
'format' => Doc\Schema::FORMAT_INTEGER_INT64,
'readOnly' => $class !== Entity::class,
],
$name_field => ['type' => Doc\Schema::TYPE_STRING],
$name_field => [
'type' => Doc\Schema::TYPE_STRING,
'readOnly' => true,
],
],
];
if ($full_schema !== null) {
$schema['x-full-schema'] = $full_schema;
}
if ($class === Entity::class) {
$schema['properties']['id']['readOnly'] = true;
}
return $schema;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Glpi/Api/HL/Controller/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public static function getRawKnownSchemas(): array
'completename' => [
'type' => Doc\Schema::TYPE_STRING,
'description' => 'Complete name',
'readOnly' => true,
],
'parent' => [
'type' => Doc\Schema::TYPE_OBJECT,
Expand All @@ -238,6 +239,7 @@ public static function getRawKnownSchemas(): array
'level' => [
'type' => Doc\Schema::TYPE_INTEGER,
'description' => 'Level',
'readOnly' => true,
],
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
],
Expand All @@ -264,6 +266,7 @@ public static function getRawKnownSchemas(): array
'completename' => [
'type' => Doc\Schema::TYPE_STRING,
'description' => 'Complete name',
'readOnly' => true,
],
'parent' => [
'type' => Doc\Schema::TYPE_OBJECT,
Expand All @@ -290,6 +293,7 @@ public static function getRawKnownSchemas(): array
'level' => [
'type' => Doc\Schema::TYPE_INTEGER,
'description' => 'Level',
'readOnly' => true,
],
],
],
Expand Down
33 changes: 26 additions & 7 deletions src/Glpi/Api/HL/Controller/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,16 @@ public static function getRawKnownSchemas(): array
'readOnly' => true,
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
'completename' => ['type' => Doc\Schema::TYPE_STRING],
'completename' => [
'type' => Doc\Schema::TYPE_STRING,
'readOnly' => true,
],
'comment' => ['type' => Doc\Schema::TYPE_STRING],
'parent' => self::getDropdownTypeSchema(class: SoftwareCategory::class, full_schema: 'SoftwareCategory'),
'level' => ['type' => Doc\Schema::TYPE_INTEGER],
'level' => [
'type' => Doc\Schema::TYPE_INTEGER,
'readOnly' => true,
],
],
];

Expand Down Expand Up @@ -296,7 +302,6 @@ public static function getRawKnownSchemas(): array
'depth' => ['type' => Doc\Schema::TYPE_NUMBER, 'format' => Doc\Schema::FORMAT_NUMBER_FLOAT],
'power_connections' => ['type' => Doc\Schema::TYPE_INTEGER],
'power_consumption' => ['type' => Doc\Schema::TYPE_INTEGER],
'max_power' => ['type' => Doc\Schema::TYPE_INTEGER],
'is_half_rack' => ['type' => Doc\Schema::TYPE_BOOLEAN],
'date_creation' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
'date_mod' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
Expand Down Expand Up @@ -530,7 +535,11 @@ class: User::class,
}

if ($asset->isField('uuid')) {
$schemas[$schema_name]['properties']['uuid'] = ['type' => Doc\Schema::TYPE_STRING];
$schemas[$schema_name]['properties']['uuid'] = [
'type' => Doc\Schema::TYPE_STRING,
'pattern' => Doc\Schema::PATTERN_UUIDV4,
'readOnly' => true,
];
}
if ($asset->isField('autoupdatesystems_id')) {
$schemas[$schema_name]['properties']['autoupdatesystem'] = self::getDropdownTypeSchema(AutoUpdateSystem::class);
Expand Down Expand Up @@ -820,7 +829,10 @@ class: User::class,
],
'is_deleted' => ['type' => Doc\Schema::TYPE_BOOLEAN],
'is_update' => ['type' => Doc\Schema::TYPE_BOOLEAN],
'is_valid' => ['type' => Doc\Schema::TYPE_BOOLEAN],
'is_valid' => [
'type' => Doc\Schema::TYPE_BOOLEAN,
'readOnly' => true,
],
'date_creation' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
'date_mod' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
],
Expand Down Expand Up @@ -939,7 +951,10 @@ class: User::class,
'room' => self::getDropdownTypeSchema(class: DCRoom::class, full_schema: 'DCRoom'),
'room_orientation' => ['type' => Doc\Schema::TYPE_INTEGER, 'format' => Doc\Schema::FORMAT_INTEGER_INT32],
'position' => ['type' => Doc\Schema::TYPE_STRING],
'bgcolor' => ['type' => Doc\Schema::TYPE_STRING],
'bgcolor' => [
'type' => Doc\Schema::TYPE_STRING,
'pattern' => Doc\Schema::PATTERN_COLOR_HEX,
],
'max_power' => ['type' => Doc\Schema::TYPE_INTEGER, 'format' => Doc\Schema::FORMAT_INTEGER_INT32],
'measured_power' => [
'type' => Doc\Schema::TYPE_INTEGER,
Expand Down Expand Up @@ -999,7 +1014,10 @@ class: User::class,
- 1: Rear
EOT,
],
'bgcolor' => ['type' => Doc\Schema::TYPE_STRING],
'bgcolor' => [
'type' => Doc\Schema::TYPE_STRING,
'pattern' => Doc\Schema::PATTERN_COLOR_HEX,
],
'position_horizontal' => [
'type' => Doc\Schema::TYPE_INTEGER,
'format' => Doc\Schema::FORMAT_INTEGER_INT32,
Expand Down Expand Up @@ -1411,6 +1429,7 @@ public static function getAssetTypes(bool $types_only = true): array

if ($assets === null) {
$assets = [];
//TODO remove SoftwareLicense in v3 as it is a duplicate of License in the Management Controller
$types = ['Computer', 'Monitor', 'NetworkEquipment',
'Peripheral', 'Phone', 'Printer', 'SoftwareLicense',
'Certificate', 'Unmanaged', 'Appliance',
Expand Down
16 changes: 12 additions & 4 deletions src/Glpi/Api/HL/Controller/ComponentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected static function getRawKnownSchemas(): array
'product_number' => ['type' => Doc\Schema::TYPE_STRING],
];

return [
$schemas = [
'BatteryType' => [
'x-version-introduced' => '2.0',
'x-itemtype' => DeviceBatteryType::class,
Expand Down Expand Up @@ -517,9 +517,7 @@ protected static function getRawKnownSchemas(): array
'x-version-introduced' => '2.0',
'x-itemtype' => DeviceMotherboardModel::class,
'type' => Doc\Schema::TYPE_OBJECT,
'properties' => $common_device_model_properties + [
'chipset' => ['type' => Doc\Schema::TYPE_STRING],
],
'properties' => $common_device_model_properties,
],
'Systemboard' => [
'x-version-introduced' => '2.0',
Expand Down Expand Up @@ -706,6 +704,16 @@ protected static function getRawKnownSchemas(): array
],
],
];

// Remove some properties that refer to missing fields in the database, but should be added later
unset(
$schemas['GenericDeviceType']['properties']['date_creation'],
$schemas['GenericDeviceType']['properties']['date_mod'],
$schemas['SensorType']['properties']['date_creation'],
$schemas['SensorType']['properties']['date_mod']
);

return $schemas;
}

public static function getComponentTypes(): array
Expand Down
20 changes: 16 additions & 4 deletions src/Glpi/Api/HL/Controller/DropdownController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,20 @@ protected static function getRawKnownSchemas(): array
'readOnly' => true,
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
'completename' => ['type' => Doc\Schema::TYPE_STRING],
'completename' => [
'type' => Doc\Schema::TYPE_STRING,
'readOnly' => true,
],
'code' => ['type' => Doc\Schema::TYPE_STRING],
'alias' => ['type' => Doc\Schema::TYPE_STRING],
'comment' => ['type' => Doc\Schema::TYPE_STRING],
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
'parent' => self::getDropdownTypeSchema(class: Location::class, full_schema: 'Location'),
'level' => ['type' => Doc\Schema::TYPE_INTEGER],
'level' => [
'type' => Doc\Schema::TYPE_INTEGER,
'readOnly' => true,
],
'room' => ['type' => Doc\Schema::TYPE_STRING],
'building' => ['type' => Doc\Schema::TYPE_STRING],
'address' => ['type' => Doc\Schema::TYPE_STRING],
Expand Down Expand Up @@ -123,12 +129,18 @@ protected static function getRawKnownSchemas(): array
'readOnly' => true,
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
'completename' => ['type' => Doc\Schema::TYPE_STRING],
'completename' => [
'type' => Doc\Schema::TYPE_STRING,
'readOnly' => true,
],
'comment' => ['type' => Doc\Schema::TYPE_STRING],
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
'parent' => self::getDropdownTypeSchema(class: State::class, full_schema: 'State'),
'level' => ['type' => Doc\Schema::TYPE_INTEGER],
'level' => [
'type' => Doc\Schema::TYPE_INTEGER,
'readOnly' => true,
],
'is_visible_helpdesk' => ['x-field' => 'is_helpdesk_visible', 'type' => Doc\Schema::TYPE_BOOLEAN],
'date_creation' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
'date_mod' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
Expand Down
17 changes: 13 additions & 4 deletions src/Glpi/Api/HL/Controller/ITILController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public static function getRawKnownSchemas(): array
'readOnly' => true,
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
'completename' => ['type' => Doc\Schema::TYPE_STRING],
'completename' => [
'type' => Doc\Schema::TYPE_STRING,
'readOnly' => true,
],
'comment' => ['type' => Doc\Schema::TYPE_STRING],
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
Expand All @@ -135,7 +138,6 @@ public static function getRawKnownSchemas(): array
'readOnly' => true,
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
'completename' => ['type' => Doc\Schema::TYPE_STRING],
'comment' => ['type' => Doc\Schema::TYPE_STRING],
'entity' => self::getDropdownTypeSchema(class: Entity::class, full_schema: 'Entity'),
'is_recursive' => ['type' => Doc\Schema::TYPE_BOOLEAN],
Expand Down Expand Up @@ -781,7 +783,10 @@ public static function getRawKnownSchemas(): array
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
'comment' => ['type' => Doc\Schema::TYPE_STRING],
'color' => ['type' => Doc\Schema::TYPE_STRING],
'color' => [
'type' => Doc\Schema::TYPE_STRING,
'pattern' => Doc\Schema::PATTERN_COLOR_HEX,
],
'date_creation' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
'date_mod' => ['type' => Doc\Schema::TYPE_STRING, 'format' => Doc\Schema::FORMAT_STRING_DATE_TIME],
],
Expand All @@ -798,7 +803,11 @@ public static function getRawKnownSchemas(): array
'format' => Doc\Schema::FORMAT_INTEGER_INT64,
'readOnly' => true,
],
'uuid' => ['type' => Doc\Schema::TYPE_STRING, 'pattern' => Doc\Schema::PATTERN_UUIDV4],
'uuid' => [
'type' => Doc\Schema::TYPE_STRING,
'pattern' => Doc\Schema::PATTERN_UUIDV4,
'readOnly' => true,
],
'name' => ['type' => Doc\Schema::TYPE_STRING],
'text' => ['type' => Doc\Schema::TYPE_STRING],
'template' => self::getDropdownTypeSchema(class: PlanningExternalEventTemplate::class, full_schema: 'ExternalEventTemplate'),
Expand Down
6 changes: 5 additions & 1 deletion src/Glpi/Api/HL/Controller/ManagementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ protected static function getRawKnownSchemas(): array
}

if ($item->isField('uuid')) {
$schemas[$m_name]['properties']['uuid'] = ['type' => Doc\Schema::TYPE_STRING];
$schemas[$m_name]['properties']['uuid'] = [
'type' => Doc\Schema::TYPE_STRING,
'pattern' => Doc\Schema::PATTERN_UUIDV4,
'readOnly' => true,
];
}
if ($item->isField('autoupdatesystems_id')) {
$schemas[$m_name]['properties']['autoupdatesystem'] = self::getDropdownTypeSchema(AutoUpdateSystem::class);
Expand Down
1 change: 1 addition & 0 deletions src/Glpi/Api/HL/Controller/RuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ protected static function getRawKnownSchemas(): array
],
'uuid' => [
'type' => Doc\Schema::TYPE_STRING,
'pattern' => Doc\Schema::PATTERN_UUIDV4,
'readOnly' => true,
],
'sub_type' => [
Expand Down
1 change: 1 addition & 0 deletions src/Glpi/Api/HL/Doc/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Schema implements ArrayAccess
public const FORMAT_BOOLEAN_BOOLEAN = 'boolean';

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';
public const PATTERN_COLOR_HEX = '/^#([A-Fa-f0-9]{6})$/';

public function __construct(
private string $type,
Expand Down
8 changes: 4 additions & 4 deletions src/Glpi/Api/HL/OpenAPIGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private function getPublicVendorExtensions(): array
return ['writeOnly', 'readOnly', 'x-full-schema', 'x-introduced', 'x-deprecated', 'x-removed'];
}

private function cleanVendorExtensions(array $schema, ?string $parent_key = null): array
private function cleanVendorExtensions(array $schema, ?string $parent_key = null, ?array $parent_schema = null): array
{
$to_keep = $this->getPublicVendorExtensions();
// Recursively walk through every key of the schema
Expand All @@ -103,15 +103,15 @@ private function cleanVendorExtensions(array $schema, ?string $parent_key = null
continue;
}
if ($parent_key === 'properties') {
if ($key === 'id') {
//Implicitly set the id property as read-only
if (!array_key_exists('x-full-schema', $parent_schema) && $key === 'id') {
// Implicitly set the id property as read-only but not for partials
$value['readOnly'] = true;
}
}
// If the value is an array
if (is_array($value)) {
// Clean the value
$schema[$key] = $this->cleanVendorExtensions($value, $key);
$schema[$key] = $this->cleanVendorExtensions($value, $key, $schema);
}
}
return $schema;
Expand Down
Loading