Skip to content

feat(sdks): add isomorphic spec platform#12346

Closed
ChiragAgg5k wants to merge 1 commit into
1.9.xfrom
feat/isomorphic-spec-platform
Closed

feat(sdks): add isomorphic spec platform#12346
ChiragAgg5k wants to merge 1 commit into
1.9.xfrom
feat/isomorphic-spec-platform

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

Summary

Adds a virtual isomorphic SDK platform whose spec is the union of the existing client and server specs. This lets a single SDK release (concretely: the web SDK) surface methods from both runtimes — including ones that are hidden from the server spec or auth-excluded from it.

Motivation: the upcoming isomorphic Web SDK (sdk-generator #1512) targets --platform=server but needs to keep all the methods previously shipped on the client side (e.g. account.createOAuth2Session, account.createPushTarget / update / delete) so existing browser callers don't regress. Without this PR, generating the web SDK against --platform=server drops those methods because they're hidden from / auth-excluded from the server spec.

Changes

  • APP_SDK_PLATFORM_ISOMORPHIC = 'isomorphic' constant
  • Specs.php
    • Adds isomorphic to getPlatforms(), getKeys() (union of client + server keys), getAuthCounts()
    • Generalizes the route + service filters with an effectivePlatformsFor() helper that expands isomorphic to [client, server]; legacy single-platform behavior is preserved
  • SDKs.php
    • New optional specPlatform config field per SDK; falls back to family. Lets a server-family SDK consume the isomorphic spec without changing its rendering family
  • Format.php (base) — effectivePlatforms() helper
  • Format/Swagger2.php, Format/OpenAPI3.php — use effectivePlatforms() in the additional-methods filter so rename pairs like createMfaAuthenticatorcreateMFAAuthenticator continue to surface in the isomorphic spec

Verification

Regenerated specs and the web SDK locally with specPlatform: isomorphic on a server-family web SDK config:

  • swagger2-1.9.x-isomorphic.json contains 606 operations (= server's 602 + the four client-only account.createOAuth2Session / createPushTarget / updatePushTarget / deletePushTarget)
  • Diffing generated server-web/ against the live appwrite/sdk-for-web main branch shows zero method removals
  • Rename pairs (createMfaAuthenticator + createMFAAuthenticator, etc.) both appear in the generated output

Test plan

  • CI passes
  • Manual: php app/cli.php specs --version=1.9.x --git=no produces a non-empty swagger2-1.9.x-isomorphic.json whose operation count ≥ server spec's
  • Manual: an SDK with specPlatform => APP_SDK_PLATFORM_ISOMORPHIC consumes that spec correctly

Adds an `isomorphic` virtual SDK platform whose spec is the union of the
`client` and `server` specs. Lets a single SDK release (e.g. the web
SDK) surface methods from both runtimes — including ones that are
hidden from the `server` spec or auth-excluded from it.

- `APP_SDK_PLATFORM_ISOMORPHIC` constant
- Specs.php emits `swagger2-<v>-isomorphic.json` (and OpenAPI3) using a
  union filter; `getKeys()` / `getAuthCounts()` extended accordingly
- SDKs.php honors an optional `specPlatform` per-SDK config override so
  a server-family SDK can point at the isomorphic spec
- Format/Swagger2 + OpenAPI3 use a shared `effectivePlatforms()` helper
  so the additional-methods filter expands isomorphic to client+server,
  preserving rename pairs like `createMfaAuthenticator` ↔
  `createMFAAuthenticator`
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 19, 2026

Greptile Summary

This PR introduces an isomorphic virtual SDK platform whose spec is the union of the client and server specs, enabling the upcoming web SDK to surface both browser-side and server-side methods without dropping client-only routes like account.createOAuth2Session. The implementation adds the platform constant, expands route/service filtering via effectivePlatformsFor() / effectivePlatforms() helpers, and allows individual SDKs to opt in through a new specPlatform config field.

  • Specs.php: effectivePlatformsFor('isomorphic') expands to [client, server] for route, service, and auth filtering; keys for the new platform are built as the PHP union of client and server key maps; authCount is set to 1 (flagged below).
  • SDKs.php: Adds an optional specPlatform per-SDK config that overrides the default family when resolving the spec file path, so a server-family web SDK can consume the isomorphic spec.
  • Format/Swagger2.php & Format/OpenAPI3.php: The additional-method filter now uses array_intersect against effectivePlatforms() so rename pairs continue to surface correctly in the isomorphic spec.

Confidence Score: 3/5

The change is generally well-structured, but authCount = 1 for the isomorphic platform causes array_slice to drop the JWT entry from x-appwrite.auth on every server-side route in the isomorphic spec.

The route-filtering and key-union logic look correct, and the author's manual verification (606 ops = 602 + 4) lines up with expectations. The one concrete defect is authCount = 1: the server spec deliberately uses 2 so that both Key and JWT appear in x-appwrite.auth for server routes; with 1, JWT is silently truncated from every server-side route's auth metadata in the isomorphic spec, which could cause the SDK generator to omit JWT auth constructors for those methods.

src/Appwrite/Platform/Tasks/Specs.php — specifically the getAuthCounts() value for the isomorphic platform and its stale type annotations.

Important Files Changed

Filename Overview
app/init/constants.php Adds the APP_SDK_PLATFORM_ISOMORPHIC constant alongside the existing platform constants; straightforward and correct.
src/Appwrite/Platform/Tasks/Specs.php Core spec-generation logic extended with effectivePlatformsFor() and isomorphic platform support; the authCount for isomorphic is set to 1 (matching client) rather than 2 (matching server), which silently drops JWT from x-appwrite.auth for server-side routes in the isomorphic spec. Type annotations for getAuthCounts() and getKeys() are also stale.
src/Appwrite/Platform/Tasks/SDKs.php Adds optional specPlatform config field per SDK with fallback to family; clean and localised change with no issues.
src/Appwrite/SDK/Specification/Format.php Adds the effectivePlatforms() instance helper, mirroring the static effectivePlatformsFor() in Specs.php; correct and well-documented.
src/Appwrite/SDK/Specification/Format/OpenAPI3.php Replaces single-platform in_array check with array_intersect against effectivePlatforms(); correct and symmetric with Swagger2 change.
src/Appwrite/SDK/Specification/Format/Swagger2.php Replaces single-platform in_array check with array_intersect against effectivePlatforms(); correct and symmetric with OpenAPI3 change.

Comments Outside Diff (2)

  1. src/Appwrite/Platform/Tasks/Specs.php, line 135-137 (link)

    P2 The @return type annotation for getAuthCounts() does not include the new isomorphic key added by this PR. Static-analysis tools and future readers will not know the full set of valid keys the returned array may contain.

  2. src/Appwrite/Platform/Tasks/Specs.php, line 150-152 (link)

    P2 The @return type annotation for getKeys() still only lists client, server, and console — it no longer reflects the isomorphic key added at the bottom of the method.

Reviews (1): Last reviewed commit: "feat(sdks): add isomorphic spec platform" | Re-trigger Greptile

'client' => 1,
'server' => 2,
'console' => 1,
APP_SDK_PLATFORM_ISOMORPHIC => 1,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 The authCount for isomorphic is set to 1, matching the client's value, but the server platform uses 2 to expose both Key and JWT in x-appwrite.auth. Since the isomorphic spec includes server-side routes (whose $securities will contain both Key and JWT), array_slice($securities, 0, 1) silently drops the JWT entry from every server route's x-appwrite.auth extension. If the SDK generator reads that extension to decide which auth constructors to emit, the isomorphic SDK would lose JWT support for server-side operations — a regression compared to generating directly against the server spec.

Suggested change
APP_SDK_PLATFORM_ISOMORPHIC => 1,
APP_SDK_PLATFORM_ISOMORPHIC => 2,

@github-actions
Copy link
Copy Markdown

✨ Benchmark results

Comparing 1.9.x (before) to feat/isomorphic-spec-platform (after).

Before

Scenario P50 (ms) P95 (ms) Requests RPS
API total 13.58 138.52 185 35.35
Account 24.32 173.11 35 7.29
TablesDB 12.91 21.19 35 8.73
Storage 11.51 46.96 75 18.34
Functions 19.93 29.63 40 9.96

After

Scenario P50 (ms) P95 (ms) Requests RPS
API total 13.4 139.44 185 34.13
Account 24.74 223.55 35 7.03
TablesDB 12.67 19.09 35 8.4
Storage 11.71 45.46 75 17.76
Functions 20.64 31.86 40 9.61

Delta

Scenario P95 delta (ms)
API total +0.91
Account +50.44
TablesDB -2.1
Storage -1.5
Functions +2.23
Top API waits
API request Max wait (ms)
account.sessions.email.create 635.29
account.create 223.41
account.password.update 204.82

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

🔄 PHP-Retry Summary

Flaky tests detected across commits:

Commit da763bd - 2 flaky tests
Test Retries Total Time Details
UsageTest::testStorageStats 1 10.49s Logs
DatabaseServerTest::testBulkCreate 1 240.45s Logs

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.

1 participant