Commit 633b26f
Doug Borg
fix: correct array item type wrapping for reference items
Address review comment about array type handling. The previous implementation
incorrectly used _wrap_optional on the entire List[...] after already handling
optionality for reference items, which would produce incorrect types.
## Problem
For arrays with Reference items:
- Required array with items: `List[ItemType]` ✅
- Optional array with items: should be `Optional[List[Optional[ItemType]]]` ✅
(not `Optional[List[ItemType]]` ❌)
## Solution
Build the Optional[List[...]] wrapper explicitly and pass the array's required
status to _generate_property_from_reference's force_required parameter. This
preserves the original behavior where reference items inherit the array's
required status.
For schema items (non-reference), always pass True since items are always
required within the array.
## Testing
- All 55 model_generator tests pass
- All 250 project tests pass
- Preserves original behavior for Optional[List[Optional[Type]]] pattern
Co-authored-by: copilot-pull-request-reviewer1 parent 6f8ecb2 commit 633b26f
File tree
1 file changed
+15
-6
lines changed- src/openapi_python_generator/language_converters/python
1 file changed
+15
-6
lines changedLines changed: 15 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
211 | 219 | | |
212 | 220 | | |
| 221 | + | |
| 222 | + | |
213 | 223 | | |
214 | 224 | | |
215 | 225 | | |
216 | 226 | | |
217 | 227 | | |
218 | | - | |
219 | | - | |
220 | | - | |
| 228 | + | |
221 | 229 | | |
| 230 | + | |
222 | 231 | | |
223 | 232 | | |
224 | 233 | | |
225 | | - | |
| 234 | + | |
226 | 235 | | |
227 | 236 | | |
228 | 237 | | |
229 | | - | |
| 238 | + | |
230 | 239 | | |
231 | 240 | | |
232 | 241 | | |
| |||
0 commit comments