Skip to content

fix(specs): serialize empty object defaults as objects - #13544

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/openapi-empty-object-defaults
Sep 8, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/openapi-empty-object-defaults

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Fix object-typed OpenAPI defaults being serialized as [] instead of {}.

Found during genuine Cloud spec verification for CLO-4377, tracked in Cloud #5716. This PR is independent of the optional-security migration in #13543 and branches directly from main.

Cause and fix

The object-specific formatter branches already normalize empty defaults to stdClass, but the shared default assignment later overwrites the normalized value with the route's raw PHP []. JSON then contains type: object with default: [], which fails strict OpenAPI validation.

Normalize an exactly empty array to stdClass at that shared assignment only when the final schema type is object. Preserve default eligibility, array defaults, populated maps, scalar defaults, examples, and runtime API behavior.

The captured Cloud document has 16 affected schemas, including screenshot headers, execution headers, presence metadata, and document/row update data. The published document has the same validation error; this was not introduced by the optional-security change.

Verification

  • Added GET-query and POST-request-body regressions that inspect the formatter's serialized JSON. Both failed before the production fix (array instead of stdClass) and pass afterward.
  • Coverage verifies empty Assoc/JSON object defaults serialize as {}, while populated maps, empty array schemas, 0, and false remain unchanged.
  • vendor/bin/phpunit tests/unit/SDK/Specification/FormatTest.php — passed: 38 tests, 210 assertions.
  • vendor/bin/pint --test src/Appwrite/SDK/Specification/Format/OpenAPI3.php tests/unit/SDK/Specification/FormatTest.php — passed.
  • composer refactor:check — passed across all 397 test files. The data provider now uses yield, fixing the failing CI Rector check.
  • git diff --check — passed.
  • Removed the redundant concrete-type assertion requested by Greptile; the regression asserts emitted {} JSON directly.

Not run for this separate branch: full Cloud specs workflow, full-document strict validation, SDK regeneration/output comparisons, Appwrite runtime e2e, or full-project static analysis. This fixes the demonstrated object-default mismatch; it does not claim that the entire live spec is now validator-clean. No screenshots apply to this nonvisual formatter change.

@greptile-apps

greptile-apps Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the serialization fix is narrowly scoped and the previous test-quality finding has been resolved.

Summary

  • Normalizes exactly empty array defaults to stdClass only when the derived schema type is object.
  • Adds serialized-output coverage for GET parameters and POST request bodies.
  • Preserves populated objects, array defaults, numeric zero, and boolean false.
  • Updates the data provider to the repository’s generator convention and removes the previously identified implementation-coupled assertion.

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@greptile review

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/openapi-empty-object-defaults (after).

Metric Before After Change
🚀 Requests/sec 210.3 184.53 🔴 -12.3%
⏱️ Latency P50 83.39 ms 93.19 ms 🔴 +11.8%
⏱️ Latency P95 190.69 ms 221.55 ms 🔴 +16.2%
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 93.19 221.55 11,457 184.53 +30.86
Account 188.55 353.82 603 10.01 +68.35
TablesDB 88.76 166.55 6,231 101.78 +11.6
Storage 88.06 190.27 3,015 51.35 +23.77
Functions 141.24 269.11 1,608 28.14 +48.08

Top API waits (after)

API request Max wait (ms)
account.name.update 503.6
tablesdb.rows.create 457.06
account.prefs.update 443.36
functions.variables.create 435.52
functions.variables.update 410.92

@ChiragAgg5k
ChiragAgg5k merged commit f66db6e into main Sep 8, 2026
46 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/openapi-empty-object-defaults branch September 8, 2026 17:48
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.

2 participants