spike: codegen experiments (SDK-1107)#273
Draft
Tr00d wants to merge 4 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status: 🚧 DRAFT — spike, not for merge
This is an evaluation spike. All generated code lives in isolated, standalone projects that are
in the solution for visibility but are not referenced by
Supabase.csproj(analyzers disabled,separate assemblies) — nothing here affects the product build, analyzers, or quality metrics.
Summary
Evaluates whether the HTTP layer of the C# SDK (Storage / Functions / PostgREST; Auth is blocked by
model coverage) can be generated from the shared Smithy models in
supabase/sdk#51, producingidiomatic C# that a maintainer would own long-term. Input is the committed Smithy→OpenAPI
artifacts; Smithy is never run in the C# toolchain. All evaluated generators are deterministic,
template-based tools — output is a function of the input document and configuration only, with no
generative-AI component.
Two toolchains were run end-to-end (NSwag and Kiota), the rest of the brief's list assessed
with rationale, and both generated clients were exercised against a live local Supabase platform.
What's included
Supabase.sln)nswag-spike/(spike-nswag)kiota-spike/(spike-kiota)nswag-testrun/(spike-nswag.TestRun)kiota-testrun/(spike-kiota.TestRun)codegen-comparison.md(root)Key findings
neither generated client improves on the shipped code: NSwag's client re-implements the existing
MakeRequesttransport; Kiota's replaces it with 4,338 generated LOC plus an 8-package runtime,without the current ergonomics (progress reporting, caching,
FailureHintmapping). Generatedmodels do add value — as drift protection against the shared contract and as the type source
for new endpoints.
without its client; Kiota's models implement
IParsable, require its runtime, and placeMicrosoft.Kiota.Abstractionson the SDK's public API — there is no models-only adoption pathfor Kiota.
in the generators: the list-response envelope (model wraps arrays the API returns bare — Kiota
returns empty results silently, NSwag throws) and missing
nullableon optional fields (NSwagserializes defaults the server rejects; Kiota omits unset fields). Both generators translated
their input faithfully and deterministically — which means a model fix propagates identically to
every SDK on regeneration. Validation must target the model; the test-run harnesses are the
mechanism.
(FileStream → StreamContent, no buffering). Live runs covered Storage; Functions and Database
clients were generated and compiled but not exercised.
Recommendation — adapt, with NSwag in models-only mode, in two stages
fixes:
WhenWritingNull+ nullable value types, source-generatedJsonSerializerContextforAOT, PascalCase naming); use generated models as the type source for newly implemented endpoints;
stand up a drift monitor — generated models diffed against the existing public types, with a
committed baseline, reported and triaged (divergence on implemented surface = defect/contract
change; unimplemented surface = parity-backlog input), not a build gate; adopt
HttpCompletionOption.ResponseHeadersReadinCore; raise the model gaps upstream.model types, bundled with the breaking changes already planned for the feature-parity catch-up,
conditional on the contract source having proven reliable through Stage-1 monitoring.
Scope of validity: these conclusions are specific to an SDK with owned transport, a published
public API, and a parity backlog. For an SDK built from scratch, the same evaluation favours
whole-client generation (Kiota is the strongest candidate assessed). Invariant in both settings:
generated code is only as correct as the contract it is generated from, and a live contract-test
harness is a required pipeline stage. Full rationale, cost analysis, and reversal criteria in
codegen-comparison.md.Upstream model gaps to raise on
supabase/sdkaffects every SDK).
nullable— leads generators to serialize defaults the serverrejects.
byte→binary; required multipart parts;{wildcardPath+}label; Auth unmodelled.How to run the harnesses
🤖 Generated with Claude Code (https://claude.com/claude-code)