Skip to content

docs(response): require a usable default on every required response field - #14366

Merged
ChiragAgg5k merged 2 commits into
mainfrom
test/response-model-defaults
Oct 12, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
test/response-model-defaults

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Documents the convention that every required response field has a usable default, and adds defaults to the four required fields that had none.

Why

#14357 put response-model defaults into the spec. appwrite/sdk-generator#2005 makes every SDK fill a missing field from that default instead of failing. That's how sdk-for-php 28+ can read File.folder from a 1.x server again, which utopia-php/migration needs.

This only works if each field has a default the spec can emit. The spec drops a default its schema rejects, such as '' on an enum rule or a scalar on an array rule.

Changes

  • AGENTS.md, under Models: a required rule needs a default its schema accepts (an enum member, or an array for an array rule). Otherwise make the rule required => false.

  • New defaults for the four required fields that had none:

    Field Default
    AuthProvider.enabled false
    Embedding.model ''
    Embedding.dimension 0
    JWT.jwt ''

Many required fields still have a default the spec can't emit. They're old fields that every server has always sent, mostly status enums and $permissions arrays defaulting to '', so they're left as they are.

Closes #14367

…ield

SDK models fill a field an older server does not send from its spec default, so a required field with none makes every older server's response unreadable for that model. The test builds the spec for every registered model and fails on a required scalar property without a default. The 80 existing gaps are recorded in a baseline that must shrink as they are fixed. AuthProvider.enabled, Embedding.model, Embedding.dimension and JWT.jwt had no default at all and now do.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No blocking issues — 3 nitpicks below.

🧹 Nitpicks (3) — 🟢 3 low
  • 🟢 Guard silently skips required fields and $ref arrays (ModelDefaultsTest.php:75) — In the spec-walk loop, a required property with no properties entry hits the $definition === null continue and is never reported (tests/unit/Utopia/Response/ModelDefaultsTest.php:75).
  • 🟢 ModelDefaultsTest ignores silent spec failures (ModelDefaultsTest.php:44) — collectMissingDefaults() resets Method::$errors but never asserts it is empty (tests/unit/Utopia/Response/ModelDefaultsTest.php:44).
  • 🟢 Missing baseline fails as cryptic JsonException (ModelDefaultsTest.php:29) — If model-defaults-baseline.json is missing or unreadable, file_get_contents returns false and the (string) cast turns it into an empty string, so json_decode throws a generic Syntax error JsonException that hides the real cause (tests/unit/Utopia/Response/ModelDefaultsTest.php:29).

The PR introduces three new Utopia response models (AuthProvider, Embedding, JWT) whose required fields all carry defaults that satisfy their own rules, so generated SDKs can deserialize responses from older servers that omit these fields. It also adds a baseline contract test that serializes every response model to an OpenAPI-style spec, checks required-field defaults, and pins the resulting map against model-defaults-baseline.json so regressions fail the unit suite.

Files Change
src/Appwrite/Utopia/Response/Model/AuthProvider.php, Embedding.php, JWT.php New response models with defaults on every required rule
tests/unit/Utopia/Response/ModelDefaultsTest.php New contract test walking all models and asserting defaults against the baseline
tests/unit/Utopia/Response/model-defaults-baseline.json Checked-in snapshot of model required/default metadata
AGENTS.md Documentation updates

Reviewed commit: 40e1928

@ChiragAgg5k ChiragAgg5k changed the title test(response): require a usable default on every required response field docs(response): require a usable default on every required response field Oct 12, 2026
@ghost

ghost commented Oct 12, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The removed generated-spec regression check leaves the new SDK-default contract without coverage.

Documents that required response-model fields need schema-accepted defaults, and adds defaults to AuthProvider.enabled, Embedding.model/dimension, and JWT.jwt. The latest commit removes the generated-spec defaults test and baseline, along with the corresponding test reference in AGENTS.md.

Latest changes: The newest commit removes the model-defaults unit test and baseline and removes its enforcement link from AGENTS.md.

Verdict New comments Fixed Still open
✅ Approved 1 0 0
Finding Where
🟡 Keep coverage for generated response defaults AGENTS.md:290
Fix with agent prompt
### Issue 1
AGENTS.md:290
**Keep coverage for generated response defaults**

The latest commit removes the only test that checked required response fields against generated-spec defaults, leaving these new defaults without a regression check. The nearby response-model tests cover filtering and requiredness, but not whether defaults remain present in the generated spec, so a future regression could break SDK fallback unnoticed.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 6
File Change
AGENTS.md Documents the required response-field default convention and removes the link to its test.
src/Appwrite/Utopia/Response/Model/AuthProvider.php Adds a false default for the required enabled field.
src/Appwrite/Utopia/Response/Model/Embedding.php Adds empty-string and zero defaults for required model and dimension fields.
src/Appwrite/Utopia/Response/Model/JWT.php Adds an empty-string default for the required JWT field.
tests/unit/Utopia/Response/ModelDefaultsTest.php Removes the generated-spec test for required response defaults.
tests/unit/Utopia/Response/model-defaults-baseline.json Removes the baseline of existing required fields without emitted defaults.

Reviewed the commits since 40e1928 · 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

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 12, 2026

@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

Comment thread AGENTS.md
- **Collections:** lowercase plural. Attributes camelCase; do not prefix with the collection name. `resourceType` is usually plural (`functions`, `sites`, `deployments`).
- **DI:** inject object dependencies only (`$dbForProject`, `$queueForEvents`, `$user`). `{role}For{Target}` only when multiple of that role coexist (`dbForProject` / `dbForPlatform`). Register new resources in `app/init/resources.php` and `app/init/resources/request.php`. Never inject callbacks or global-shaped functions to reuse logic — see [Reuse](#reuse).
- **Models:** class PascalCase; `getName()` matches. `Response::MODEL_*` constants `SCREAMING_SNAKE_CASE`; values camelCase singular (`team`) or `{name}List`.
- **Models:** class PascalCase; `getName()` matches. `Response::MODEL_*` constants `SCREAMING_SNAKE_CASE`; values camelCase singular (`team`) or `{name}List`. A required rule needs a `default` its schema accepts (an enum member, an array for an array rule), because SDK models fill a field an older server does not send from it; without one, make the rule `required => false`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Keep coverage for generated response defaults

The latest commit removes the only test that checked required response fields against generated-spec defaults, leaving these new defaults without a regression check. The nearby response-model tests cover filtering and requiredness, but not whether defaults remain present in the generated spec, so a future regression could break SDK fallback unnoticed.

Prompt To Fix With AI
This is a comment left during a code review.
Path: AGENTS.md
Line: 290

Comment:
**Keep coverage for generated response defaults**

The latest commit removes the only test that checked required response fields against generated-spec defaults, leaving these new defaults without a regression check. The nearby response-model tests cover filtering and requiredness, but not whether defaults remain present in the generated spec, so a future regression could break SDK fallback unnoticed.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

@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 merged commit 5534cb5 into main Oct 12, 2026
65 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the test/response-model-defaults branch October 12, 2026 12:19
@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → test/response-model-defaults (after).

Metric Before After Change
🚀 Requests/sec 202.68 207.92 ⚪ +2.6%
⏱️ Latency P50 85.03 ms 84.71 ms ⚪ -0.4%
⏱️ Latency P95 203.62 ms 188.11 ms 🟢 -7.6%
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 84.71 188.11 12,882 207.92 -15.51
Account 158.13 278.96 678 11.24 -66.43
TablesDB 81.74 146.62 7,006 114.75 -2.73
Storage 79.34 168.22 3,390 57.7 +0.1
Functions 118 217.38 1,808 31.62 -36.31

Top API waits (after)

API request Max wait (ms)
account.prefs.update 418.91
functions.create 407.63
tablesdb.rows.create 369.6
account.name.update 368.84
functions.variables.update 353.62

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.

Require a usable default on every required response field

1 participant