Repository navigation
fix: default missing required collections when filling response defaults - #2016
Conversation
The spec gives a model collection no default, and models only filled required fields that carry one, so a response that omitted a required collection left it undefined (JS) or failed to decode (every other SDK). An empty list is the one value a collection's type always admits, so required collections now fill with it; nested models stay absent.
🟢 Tier S · Ready to merge
Adds shared model-default handling so generated SDKs fill omitted required collection fields with empty arrays, while leaving optional fields and nested models absent. It adds an empty-presets mock plus generation and e2e coverage, and updates language templates and fixtures to support the behavior consistently. Latest changes: The Swift model template now reuses the escaped field name and emits
📂 Walkthrough · 9
Merged |
Required collections give most list models a defaults entry, which surfaced three generator gaps: the JS services imported applyDefaults for upload methods that never call it, Swift wrote a trailing comma in a one-entry literal and a long decode fallback, and the Node service tests keyed their mock data with an escaped dollar sign.
…collections # Conflicts: # tests/e2e/languages/node/test.js # tests/e2e/languages/react-native/browser.js # tests/e2e/languages/web/index.html # tests/e2e/languages/web/node.js
A required collection the spec gives no default stayed missing when a response omitted it.
Models only filled required fields that carry a spec default, and the spec never gives one to a collection.
Language::getModelDefault()now fills a required collection with[], the one value its type always admits. Every SDK that fills defaults reads it through the newmodelDefaultfilter. Optional fields stay absent. Nested models stay absent too, because an empty object may not satisfy the fields they require. Go is unchanged: a nil slice already reads as empty, and adding the defaultsUnmarshalJSONto every list model would decode each response twice.E2E: a new
listEmptyPresetsmock returns{"total": 0}and every SDK printsempty presets: 0.Now that list models carry defaults, three existing generator gaps showed up, and this PR fixes them too:
applyDefaultsfor upload methods that never call it. The import is now skipped for those methods.[].'\\$id', so the response never actually carried$id.Closes #2017