Skip to content

Switch spec parsing to OpenAPI 3 (native pipeline)#1584

Merged
ChiragAgg5k merged 8 commits into
masterfrom
feat/openapi3-native-spec-parsing
Jun 11, 2026
Merged

Switch spec parsing to OpenAPI 3 (native pipeline)#1584
ChiragAgg5k merged 8 commits into
masterfrom
feat/openapi3-native-spec-parsing

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Jun 11, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Switches the SDK generator from Swagger 2 to OpenAPI 3 spec parsing, with OpenAPI 3 as the native pipeline of the codebase.

Architecture

  • src/Spec/OpenAPI3.php (new) — the native parser. Reads servers, components/schemas, components/securitySchemes, requestBody, response content, and real oneOf/anyOf/discriminator unions directly.
  • src/Spec/Swagger2.php — now a thin legacy adapter (~190 lines, was ~890). It converts the Swagger 2 document into its OpenAPI 3 equivalent at construction (host/basePath/schemes/x-host-docsservers, body/formData params → requestBody, response schema → response content, deep #/definitions/#/components/schemas/ ref rewrite) and inherits the entire pipeline — so both formats produce identical SDKs by construction.
  • example.php defaults to OpenAPI 3 specs (open-api3-{version}-{platform}.json); format is selectable: php example.php <sdk> <platform> <swagger2|openapi3>. A local spec can be supplied with SDK_GEN_SPEC_FILE=/path/to/spec.json.

Tests

  • tests/ split into unit/ (spec parser tests, no Docker, runs in its own CI job) and e2e/ (per-language SDK tests).
  • Shared fixtures in tests/resources/: spec-swagger2.json + spec-openapi3.json are parity twins; OpenAPI3SpecTest::testParsesIdenticallyToSwagger2 asserts both parse into the exact same internal representation, so the fixtures (and formats) can't drift silently.
  • e2e tests generate SDKs from the OpenAPI 3 fixture and the mock server is now removed in tearDown() (no more leftover mockapi containers locally).

Verification

  • Internal-representation parity harness against real cloud-generated specs: 0 differences across the console, client, server, and manager platforms.
  • Generated all SDK targets from both spec formats for console, client, and server: diff -r reports zero differing files, and output is also byte-identical to the pre-refactor generator.
  • PHP e2e against the mock server: 1379 assertions, green. composer lint, rector, unit suite (32 tests): clean.

Upstream dependencies (resolved)

  1. Fix OpenAPI 3 spec generation parity with Swagger 2 appwrite#12564 spec generator parity fixes → regenerated specs published via feat: API specs update for version latest specs#77 and feat: API specs update for version 1.9.x specs#78 (generated from the fix branch through appwrite-labs/cloud#4319); the generator patch itself still awaits merge upstream but no longer blocks this PR
  2. Republished open-api3-* specs → merged to appwrite/specs main; verified the default OpenAPI 3 flow produces SDKs byte-identical to Swagger 2
  3. New @appwrite.io/console release → 14.0.0 released and the CLI updated to ^14.0.0

All 58 CI checks are green.

Related PRs and Issues

Switch the generator from Swagger 2 to OpenAPI 3 spec parsing. OpenAPI 3
is now the native pipeline: the parser reads servers, components/schemas,
securitySchemes, requestBody, response content and oneOf/discriminator
unions directly. Swagger 2 stays fully supported as a legacy adapter that
converts its document to the OpenAPI 3 shape at construction and inherits
the pipeline, so both formats produce identical SDKs by construction.

- src/Spec/OpenAPI3.php: native OpenAPI 3 parser (new)
- src/Spec/Swagger2.php: thin up-converting adapter (was the full parser)
- src/Spec/Spec.php: getRequestModelEnums/getAllEnums on the base contract
- src/SDK/SDK.php: derive spec.basePath from the endpoint URL
- example.php: openapi3 by default, format as third CLI arg
  (php example.php <sdk> <platform> <swagger2|openapi3>), optional
  SDK_GEN_SPEC_FILE override, shared Config constants

Tests are restructured into suites and run on shared fixtures:

- tests/unit: spec parser tests incl. a cross-format parity test that
  asserts both formats parse into the exact same internal representation
- tests/e2e: per-language SDK tests, now generating from the OpenAPI 3
  fixture; the mock server is removed again in tearDown
- tests/resources: spec-swagger2.json + spec-openapi3.json parity twins
  shared by both suites (plus upload fixtures)
- CI runs the unit suite in its own job

Verified byte-identical output for all SDK targets across the console,
client and server platforms, between both spec formats and against the
pre-refactor generator.
The spec parser tests moved to tests/unit and run in the dedicated
Tests / Unit job.
The published @appwrite.io/console package does not export the new Apps
service yet, which breaks the CLI validation build.
Spatial attribute models (line, polygon) have nested array defaults
(List<List<double>>). The From() factory derived the ConvertToList
element type by stripping every List< prefix, collapsing nested lists
to their scalar type and breaking compilation. Strip only the outermost
List<...> instead.
The 14.0.0 release is generated from the updated console spec, fixing
the type errors against new API methods. The caret range picks up
future minor and patch updates.
Model and definition generation is fully supported: per-definition model
classes, request models, enums, nested references and union types.
@ChiragAgg5k ChiragAgg5k marked this pull request as ready for review June 11, 2026 05:34
@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces the legacy Swagger 2 parsing pipeline with a native OpenAPI 3 parser (OpenAPI3.php) and reduces Swagger2.php to a thin conversion adapter (~200 lines) that translates a Swagger 2 document into its OpenAPI 3 equivalent at construction time. Both formats share the same downstream pipeline, so identical SDKs are produced by construction.

  • OpenAPI3.php is a full native parser covering servers, components/schemas, components/securitySchemes, requestBody, response content, and oneOf/anyOf/discriminator unions; parity with Swagger 2 output is verified by a dedicated cross-format assertion test.
  • Test structure is reorganised into tests/unit/ (no Docker, runs in a new CI job) and tests/e2e/; e2e tests now use the OpenAPI 3 fixture and the mock-server container is torn down in tearDown().
  • SDK.php derives basePath from parse_url(getEndpoint()) instead of the defunct Swagger 2 basePath field, and example.php defaults to the OpenAPI 3 spec with an optional swagger2 flag.

Confidence Score: 5/5

Safe to merge. The cross-format parity test is a strong correctness guarantee, and the author reports zero diff across all SDK targets when comparing both parsers against the real cloud spec.

The refactoring is well-contained: Swagger 2 converts to OpenAPI 3 at construction time and inherits the shared pipeline, so no template or downstream consumer can silently diverge. The parity harness plus 1379-assertion e2e suite gives strong confidence. Both noted items are non-functional.

No files require special attention.

Important Files Changed

Filename Overview
src/Spec/OpenAPI3.php New native OpenAPI 3 parser with full pipeline; small dead-code nit on the auth field and a subtle emptyResponse edge case with empty response maps.
src/Spec/Swagger2.php Slimmed to a thin Swagger 2 → OpenAPI 3 conversion adapter; ref-rewriting and formData/body conversion look correct.
src/Spec/Spec.php Added getRequestModelEnums() and getAllEnums() stubs plus stricter type on setAttribute; clean additions.
tests/unit/OpenAPI3SpecTest.php Comprehensive unit test covering the new parser and the cross-format parity assertion.
tests/unit/Swagger2SpecTest.php Unit tests covering Swagger 2 adapter behaviour; focused set that complements the parity test in OpenAPI3SpecTest.
tests/e2e/Base.php E2E base moved to new namespace and now uses the OpenAPI 3 fixture; tearDown brings down the mock-server container, fixing leftover containers on local runs.
src/SDK/SDK.php Single-line fix: basePath now derived from the endpoint URL via parse_url instead of the defunct Swagger 2 basePath field.
.github/workflows/ci.yml Adds dedicated unit CI job running --testsuite Unit; e2e matrix updated to the new tests/e2e/ path.
example.php Refactored to default to OpenAPI 3 specs, with a $specFormat flag and buildSpec() helper; Config constants reduce magic strings.

Reviews (2): Last reviewed commit: "(fix): initialize the header parameters ..." | Re-trigger Greptile

Comment thread src/Spec/OpenAPI3.php
The parameters map initialized 'headers' (plural) while header
parameters are appended to 'header' (singular), which is also what the
templates consume. Carried over from the legacy parser.
@ChiragAgg5k ChiragAgg5k merged commit 60a2e80 into master Jun 11, 2026
59 checks passed
@ChiragAgg5k ChiragAgg5k deleted the feat/openapi3-native-spec-parsing branch June 11, 2026 07:57
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