Repository navigation
feat(specs): emit response model defaults - #14357
Conversation
The server fills a field a document lacks from its rule's default, but the spec dropped those defaults, so SDK models could only treat a missing field as an error. A server older than the field never sends it: sdk-for-php 28+ cannot read a file from a 1.x server because File.folder arrived in 2.0. Scalar and scalar-array properties now carry the default so generated models can fall back to it. Model references keep none.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
The change emits property-level
Reviewed commit: d581860 |
🟢 Tier S · Ready to merge
OpenAPI 3 response model schemas now include compatible non-null defaults so generated clients can populate fields omitted by older servers. Scalar, scalar-array, and empty JSON-object defaults are represented, while model references and defaults that do not match the property schema are excluded; dynamic datetime defaults are also skipped. The unit tests cover these default-emission cases and schema compatibility. Latest changes: The new commit adds Topic to the schema test setup and asserts that its valid scalar-array default is emitted.
📂 Walkthrough · 2
✅ Fixed since the last review · 2
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 32 existing findings tracked in
|
There was a problem hiding this comment.
This PR adds default values to OpenAPI 3 component schemas for response model properties, with unit test coverage.
Key findings
- 🟡 Model
defaultemitted on enum schemas without membership guard — OpenAPI3.php:1334
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Enum rules default to '' outside their members, array rules declare a scalar '' default, and Message.scheduledAt defaults to the current time, which would change the spec on every build. Defaults now pass the same shouldEmitDefaultForSchema check request parameters use, and datetime defaults other than '' are left out.
The OpenAPI 3 spec now includes each response model property's
default, so SDK models can fill in a field that an older server doesn't return.Why
When a document lacks a field, the server fills it from the rule's default. The spec dropped those defaults, so a generated model can only treat a missing required field as an error. A server older than the field never sends it.
This breaks utopia-php/migration, which reads from older self-hosted servers. sdk-for-php 28+ requires
File.folderandFile.key, which only exist from 2.0.0. With those versions, listing files from a 1.6–1.9 source throwsMissing required field "folder". Migration needs sdk-for-php 30.2 to carry function intervals, so it can't take that SDK until models accept a missing field.Changes
defaultemit it. This covers scalars, scalar arrays andjsonobjects (an emptyjsondefault is emitted as{}).$ref,oneOf, arrays of models) get no default, so nested models keep their existing handling.shouldEmitDefaultForSchemacheck as request parameters. Enum rules that default to''and array rules that declare a scalar''get none.''are skipped, becauseMessage.scheduledAtdefaults to the current time and would change the spec on every build.Tests
testModelPropertiesEmitTheirDefaultschecks scalar defaults, and that a model reference gets none.testModelDefaultsMustMatchTheirSchemacovers an empty JSON object (emitted as{}), an array with a scalar default, the time-dependentscheduledAt, and an enum default outside its members.Both fail without the change.
Closes #14358