Skip to content

Commit 1310437

Browse files
committed
fix: remove unnecessary fallback and add edge case tests
- Remove `?? false` fallback on `optional` key since ArrayShapeType::getShape() guarantees its presence - Add test cases for nested shapes, numeric keys, and nullable values - Regenerate fixture with new test entities
1 parent 392670a commit 1310437

3 files changed

Lines changed: 77 additions & 2 deletions

File tree

src/TypeDescriber/ArrayShapeDescriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function describe(Type $type, Schema $schema, array $context = []): void
3535
$property = Util::getProperty($schema, (string) $key);
3636
$this->describer->describe($shapeValue['type'], $property, $context);
3737

38-
if (!($shapeValue['optional'] ?? false)) {
38+
if (!$shapeValue['optional']) {
3939
$required[] = (string) $key;
4040
}
4141
}

tests/Functional/Entity/ArrayShapeTypes.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,13 @@ class ArrayShapeTypes
2020

2121
/** @var array{id: int, label: string, ...} */
2222
public array $unsealed;
23+
24+
/** @var array{user: array{name: string, age: int}, active: bool} */
25+
public array $nested;
26+
27+
/** @var array{0: string, 1: int} */
28+
public array $numericKeys;
29+
30+
/** @var array{name: ?string, email: ?string} */
31+
public array $nullableValues;
2332
}

tests/Functional/Fixtures/ArrayShapeController.json

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
"ArrayShapeTypes": {
2929
"required": [
3030
"sealed",
31-
"unsealed"
31+
"unsealed",
32+
"nested",
33+
"numericKeys",
34+
"nullableValues"
3235
],
3336
"properties": {
3437
"sealed": {
@@ -67,6 +70,69 @@
6770
"additionalProperties": {
6871
"nullable": true
6972
}
73+
},
74+
"nested": {
75+
"required": [
76+
"active",
77+
"user"
78+
],
79+
"properties": {
80+
"active": {
81+
"type": "boolean"
82+
},
83+
"user": {
84+
"required": [
85+
"age",
86+
"name"
87+
],
88+
"properties": {
89+
"age": {
90+
"type": "integer"
91+
},
92+
"name": {
93+
"type": "string"
94+
}
95+
},
96+
"type": "object",
97+
"additionalProperties": false
98+
}
99+
},
100+
"type": "object",
101+
"additionalProperties": false
102+
},
103+
"numericKeys": {
104+
"required": [
105+
"0",
106+
"1"
107+
],
108+
"properties": {
109+
"0": {
110+
"type": "string"
111+
},
112+
"1": {
113+
"type": "integer"
114+
}
115+
},
116+
"type": "object",
117+
"additionalProperties": false
118+
},
119+
"nullableValues": {
120+
"required": [
121+
"email",
122+
"name"
123+
],
124+
"properties": {
125+
"email": {
126+
"type": "string",
127+
"nullable": true
128+
},
129+
"name": {
130+
"type": "string",
131+
"nullable": true
132+
}
133+
},
134+
"type": "object",
135+
"additionalProperties": false
70136
}
71137
},
72138
"type": "object"

0 commit comments

Comments
 (0)