Skip to content

Default missing required collections when filling response defaults #2017

Closed

Description

@ChiragAgg5k

Tracks PR #2016.

Plan

Goal: When a response omits a required collection field that the spec gives no default, generated SDK models should fill it with an empty list instead of leaving it undefined (JS TypeError) or throwing (PHP Missing required field "presets"). Follow-up to #2007 (spec defaults for missing model fields).

What changes (from PR #2016):

  • src/SDK/Language.php: new getModelDefault() returns the spec default for a required field, or [] for a required array schema with no default; optional fields and nested models stay absent.
  • src/SDK/SDK.php: new modelDefault Twig filter; emitters in src/SDK/Language/ (Dart, DotNet, JS, Kotlin, Ruby, Rust, Swift) read defaults through it (Rust's old helper renamed to getRustDefault).
  • Model templates for Dart, .NET, PHP, Python, Ruby, Rust and Swift switch from schemaDefault to modelDefault. Go is unchanged, since a nil slice already reads as empty.
  • Tests: new mock GET /v1/mock/tests/general/presets/empty returning {"total": 0} in mock-server/app/http.php, tests/resources/spec-openapi3.json, tests/generation/GenerationTest.php, and e2e checks in every language under tests/e2e/languages/ expecting empty presets: 0.

Remaining steps: None beyond review and merge; the linked PR is the full change.

Done when:

Update (2026-10-13): Related fix #2020 (merged) keeps the JSON toString on JS responses after fillDefaults spreads in model defaults, in templates/web/src/client.ts.twig, templates/node/src/client.ts.twig and templates/react-native/src/client.ts.twig, with e2e checks under tests/e2e/.

Activity

  1. self-assigned this
    on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions