|
11 | 11 | use function end; |
12 | 12 | use function is_array; |
13 | 13 | use function json_encode; |
14 | | -use function strtoupper; |
15 | 14 |
|
16 | 15 | trait HandleStructured |
17 | 16 | { |
@@ -54,37 +53,25 @@ protected function adaptSchema(array $schema): array |
54 | 53 | unset($schema['additionalProperties']); |
55 | 54 | } |
56 | 55 |
|
57 | | - if (array_key_exists('type', $schema)) { |
58 | | - if (is_array($schema['type'])) { |
59 | | - foreach ($schema['type'] as $type) { |
60 | | - if ($type !== 'null') { |
61 | | - $schema['type'] = strtoupper((string) $type); |
62 | | - break; |
63 | | - } |
64 | | - } |
65 | | - } else { |
66 | | - $schema['type'] = strtoupper((string) $schema['type']); |
| 56 | + foreach ($schema as $key => $value) { |
| 57 | + if (is_array($value)) { |
| 58 | + $schema[$key] = $this->adaptSchema($value); |
67 | 59 | } |
68 | | - |
69 | | - $schema['type'] = match ($schema['type']) { |
70 | | - 'INT' => 'INTEGER', |
71 | | - 'BOOL' => 'BOOLEAN', |
72 | | - 'DOUBLE', 'FLOAT' => 'NUMBER', |
73 | | - default => $schema['type'] |
74 | | - }; |
75 | 60 | } |
76 | 61 |
|
| 62 | + // Always an object also if it's empty |
77 | 63 | if (array_key_exists('properties', $schema) && is_array($schema['properties'])) { |
78 | | - foreach ($schema['properties'] as $key => $value) { |
79 | | - if (is_array($value)) { |
80 | | - $schema['properties'][$key] = $this->adaptSchema($value); |
81 | | - } |
82 | | - } |
83 | 64 | $schema['properties'] = (object) $schema['properties']; |
84 | 65 | } |
85 | 66 |
|
86 | | - if (array_key_exists('items', $schema) && is_array($schema['items'])) { |
87 | | - $schema['items'] = $this->adaptSchema($schema['items']); |
| 67 | + // Reduce the array type to a single not-nullable type |
| 68 | + if (isset($schema['type']) && is_array($schema['type'])) { |
| 69 | + foreach ($schema['type'] as $type) { |
| 70 | + if ($type !== 'null') { |
| 71 | + $schema['type'] = $type; |
| 72 | + break; |
| 73 | + } |
| 74 | + } |
88 | 75 | } |
89 | 76 |
|
90 | 77 | return $schema; |
|
0 commit comments