Skip to content

feat: emit a canonical OpenAPI document covering every SDK platform - #13512

Merged
ChiragAgg5k merged 4 commits into
mainfrom
feat/canonical-openapi-document
Sep 7, 2026
Merged

ChiragAgg5k merged 4 commits into
mainfrom
feat/canonical-openapi-document

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What does this PR do?

The Specs task now writes one canonical OpenAPI document per version, open-api3-<version>.json, alongside the existing -client, -server and -console files. It covers every route any SDK platform offers, every method alias variant, all response models, and the union of tags and security schemes. sdk-generator 4.8.0 already selects a platform from x-appwrite.platforms (appwrite/sdk-generator#1880); this document is what it selects from.

The one thing the generator could not select by platform was x-appwrite.auth, the credentials an SDK example configures, because its value differs per platform. In the canonical document it is keyed by platform; appwrite/sdk-generator#1881 reads auth[platform] and keeps reading the flat form.

Spec changes

Canonical document only

Operation and alias auth keyed by platform. PATCH /presences/{presenceId} shows both, including the two update alias variants that differ in required:

"x-appwrite": {
  "platforms": ["client", "console", "server"],
  "auth": {
    "client":  { "Project": [] },
    "console": { "Project": [] },
    "server":  { "Project": [], "Session": [] }
  },
  "methods": [
    { "name": "update", "platforms": ["client", "console"], "auth": { "client": { "Project": [] }, "console": { "Project": [] } }, "required": ["presenceId"] },
    { "name": "update", "platforms": ["server"],            "auth": { "server": { "Project": [], "Key": [] } },                    "required": ["presenceId", "userId"] }
  ]
}

Security schemes are the union of the platforms' key sets in getPlatforms() order, first definition wins.

All documents

Each security scheme lists the platforms whose SDK offers it. This is the only change to the per-platform files:

 "Key": {
   "type": "apiKey", "name": "X-Appwrite-Key", "in": "header",
   "x-appwrite": {
+    "platforms": ["server", "console"],
     "demo": "<YOUR_API_KEY>"
   }
 }

Code changes

  • Specs::action() loops [...platforms, null]; the null pass is the canonical document: routes with any platform, all alias variants, models without the console-only isPublic filter, services whose platforms intersect the known ones. Filename suffix is omitted, and --git=yes copies the canonical file with the PR platforms' files.
  • Format takes the full per-platform key map and per-platform auth counts, and a nullable platform. getSecuritySchemes() returns the document's schemes with x-appwrite.platforms.
  • OpenAPI3::getExampleAuth() computes today's slice once per platform and returns it flat for a platform document, keyed for the canonical one. Route inclusion and alias inclusion accept "any platform" when the platform is null.

Validation

  • vendor/bin/phpunit tests/unit/SDK: 36 tests, 192 assertions, including two new canonical-document tests (keyed auth per platform, alias variants across platforms, scheme platforms and union order). Pint and Rector clean.
  • php app/cli.php specs --version=latest --mode=normal --git=no on this branch versus main:
    • The three per-platform documents are identical to main after removing the new scheme platforms lists.
    • Canonical: 622 operations and 263 schemas, equal to the union of the three; every auth[platform] matches the platform document's flat auth for all 1,336 operation/platform pairs; every alias variant matches.
  • SDK generation with sdk-generator#1881 for all 24 targets, compared with 4.8.0 output from main's documents:
    • From the new per-platform documents: byte-identical on client, server and console.
    • From the canonical document: byte-identical on client; on server and console only the Client.* files differ, in the order of the header setters, because the union follows the client's scheme order. Content is the same.

Follow-ups

  • appwrite-labs/cloud: its Specs subclass adds a manager platform whose Key scheme is a bearer token, not the X-Appwrite-Key header. In a union the first definition wins, so the canonical document would describe manager's Key wrongly. Rename that scheme on the cloud side before the canonical document is used for a manager SDK. The cloud specs workflow also needs to copy open-api3-<version>.json.
  • Consumers migrate to the canonical file before the per-platform files are retired.

Related to CLO-4377.

The Specs task writes open-api3-<version>.json alongside the per-platform files: every route any platform offers, every method alias variant, all response models, the union of tags and of security schemes. The generator selects a platform from x-appwrite.platforms since 4.8.0; what it could not select was x-appwrite.auth, whose value differs per platform, so the canonical document keys auth by platform and each security scheme lists the platforms whose SDK offers it. The per-platform documents are unchanged apart from that scheme-level platforms list, which is why they stay byte-identical for the SDKs generated from them.

Related to CLO-4377.
@greptile-apps

greptile-apps Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a canonical OpenAPI document containing the union of the client, server, and console SDK surfaces while retaining the existing platform-specific documents.

  • Generates an unsuffixed canonical specification alongside each platform specification.
  • Records platform availability on operations, aliases, authentication examples, and security schemes.
  • Preserves platform-specific authentication output while keying canonical authentication by platform.
  • Updates the SDK generator lockfile dependency and adds canonical-document coverage.

Confidence Score: 5/5

The PR appears safe to merge; no actionable correctness, security, or repository-rule violations remain.

The canonical generation path consistently preserves platform membership, authentication selection, alias variants, and security-scheme annotations, while platform-specific output retains its previous filtering semantics.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Tasks/Specs.php Adds the canonical generation pass, union-oriented filtering, filename handling, and canonical artifact copying.
src/Appwrite/SDK/Specification/Format.php Carries per-platform security and authentication configuration and builds annotated security-scheme unions.
src/Appwrite/SDK/Specification/Format/OpenAPI3.php Emits platform-keyed canonical authentication and includes operations and aliases offered by any selected SDK platform.
tests/unit/SDK/Specification/FormatTest.php Updates constructor fixtures and verifies canonical authentication, security-scheme metadata, and alias variants.
composer.lock Updates appwrite/sdk-generator from 4.7.8 to 4.9.0 with its corresponding OpenAPI dependency requirement.

Reviews (4): Last reviewed commit: "Merge branch 'main' into feat/canonical-..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/canonical-openapi-document (after).

Metric Before After Change
🚀 Requests/sec 210.53 214.85 ⚪ +2.1%
⏱️ Latency P50 85.31 ms 83.91 ms ⚪ -1.6%
⏱️ Latency P95 180.94 ms 182.47 ms ⚪ +0.8%
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 83.91 182.47 13,680 214.85 +1.53
Account 150.37 276.93 720 11.97 +5.64
TablesDB 84.99 150.67 7,440 119.61 -2.93
Storage 70.49 158.29 3,600 59.85 +4.63
Functions 110.6 215.26 1,920 32.52 +10.86

Top API waits (after)

API request Max wait (ms)
functions.variables.update 400.13
functions.variables.delete 395.87
account.name.update 373.54
account.prefs.update 371.72
functions.variables.create 365.99

@ChiragAgg5k
ChiragAgg5k merged commit 4d192a2 into main Sep 7, 2026
44 of 46 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the feat/canonical-openapi-document branch September 7, 2026 10:56
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 tasks
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