Commit 1d633da
committed
fix(python): Use exclude_unset=True for PATCH models to prevent sending default values
Fixes issue where PATCH requests were sending default values even when fields
were not explicitly set by the client, causing unintended field resets.
Changes:
- Add postProcessModels() override in PythonClientCodegen to detect PATCH models
(models starting with "Patched") and mark them with isPatchedModel vendor extension
- Update model_generic.mustache to use exclude_unset=True for PATCH models,
exclude_none=True for other models
- Only affects PythonClientCodegen, not other Python generators
- Maintains backward compatibility for non-PATCH models
Before: PatchedUser(name="John") would send {"name": "John", "status": "active", "priority": 0}
After: PatchedUser(name="John") sends {"name": "John"} (only explicitly set fields)
Fixes #12341 parent d27cc40 commit 1d633da
2 files changed
Lines changed: 5 additions & 6 deletions
File tree
- modules/openapi-generator/src/main
- java/org/openapitools/codegen/languages
- resources/python
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
442 | 442 | | |
443 | 443 | | |
444 | 444 | | |
| 445 | + | |
445 | 446 | | |
446 | 447 | | |
447 | 448 | | |
| |||
Lines changed: 4 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
168 | | - | |
| 167 | + | |
169 | 168 | | |
170 | 169 | | |
171 | 170 | | |
172 | 171 | | |
173 | 172 | | |
174 | | - | |
175 | | - | |
| 173 | + | |
| 174 | + | |
176 | 175 | | |
177 | 176 | | |
178 | 177 | | |
179 | 178 | | |
180 | 179 | | |
181 | | - | |
182 | | - | |
| 180 | + | |
183 | 181 | | |
184 | 182 | | |
185 | 183 | | |
| |||
0 commit comments