Skip to content

feat(specs): emit response model defaults - #14357

Merged
ChiragAgg5k merged 3 commits into
mainfrom
feat/spec-model-defaults
Oct 12, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
feat/spec-model-defaults

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

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.folder and File.key, which only exist from 2.0.0. With those versions, listing files from a 1.6–1.9 source throws Missing 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

  • Model properties with a non-null default emit it. This covers scalars, scalar arrays and json objects (an empty json default is emitted as {}).
  • Model references ($ref, oneOf, arrays of models) get no default, so nested models keep their existing handling.
  • A default is emitted only if the property schema accepts it, using the same shouldEmitDefaultForSchema check as request parameters. Enum rules that default to '' and array rules that declare a scalar '' get none.
  • Datetime defaults other than '' are skipped, because Message.scheduledAt defaults to the current time and would change the spec on every build.
  • Only the Ruby model template reads model-property defaults today. The matching sdk-generator PR quotes them in Ruby and makes PHP models fall back to them.

Tests

  • testModelPropertiesEmitTheirDefaults checks scalar defaults, and that a model reference gets none.
  • testModelDefaultsMustMatchTheirSchema covers an empty JSON object (emitted as {}), an array with a scalar default, the time-dependent scheduledAt, and an enum default outside its members.

Both fail without the change.

Closes #14358

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.
@luxor-code-review

luxor-code-review Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Model default emitted on enum schemas without membership guard — OpenAPI3.php:1334

The change emits property-level default values into the OpenAPI 3 component schemas during spec formatting, and adds unit tests covering the new default emission behavior. One issue remains around non-member enum defaults.

Files Change
src/Appwrite/SDK/Specification/Format/OpenAPI3.php Emits rule default values into model component schemas.
tests/unit/SDK/Specification/FormatTest.php Adds unit tests for the new default emission.

Reviewed commit: d581860

@ghost

ghost commented Oct 12, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The added assertion exercises valid scalar-array default emission, while the existing assertions cover JSON conversion and rejected defaults.

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.

Verdict New comments Fixed Still open
✅ Approved 0 2 0
📂 Walkthrough · 2
File Change
src/Appwrite/SDK/Specification/Format/OpenAPI3.php Emits compatible non-null response model defaults, including scalar arrays and empty JSON objects, while excluding model references and unsuitable defaults.
tests/unit/SDK/Specification/FormatTest.php Covers scalar, JSON, valid and invalid array, datetime, enum, and model-reference default behavior.
✅ Fixed since the last review · 2
  • Cover array and JSON default emission · src/Appwrite/SDK/Specification/Format/OpenAPI3.php:1295
  • Test emission of a valid scalar-array default · tests/unit/SDK/Specification/FormatTest.php:856

Reviewed the commits since c9c43ba · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 12, 2026
3 tasks
@ChiragAgg5k ChiragAgg5k self-assigned this Oct 12, 2026

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds default values to OpenAPI 3 component schemas for response model properties, with unit test coverage.

Key findings

  • 🟡 Model default emitted on enum schemas without membership guard — OpenAPI3.php:1334

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/spec-model-defaults (after).

Metric Before After Change
🚀 Requests/sec 220.34 224.57 ⚪ +1.9%
⏱️ Latency P50 78.22 ms 77.21 ms ⚪ -1.3%
⏱️ Latency P95 184.03 ms 178.62 ms ⚪ -2.9%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 77.21 178.62 13,965 224.57 -5.41
Account 149.79 268.03 735 12.17 +10.65
TablesDB 74.48 131.62 7,595 123.81 -15.81
Storage 71.84 145.77 3,675 62.03 -16.06
Functions 113.27 219.08 1,960 33.82 +8.47

Top API waits (after)

API request Max wait (ms)
account.name.update 584.23
functions.create 387.26
functions.delete 385
account.prefs.update 348.2
functions.variables.update 341.04

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.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit response model defaults

1 participant