Skip to content

fix(sdk): sync generator templates with hand-edited SDK output#884

Merged
mergify[bot] merged 5 commits intomainfrom
fix/sdk-generator-template-drift
Mar 11, 2026
Merged

fix(sdk): sync generator templates with hand-edited SDK output#884
mergify[bot] merged 5 commits intomainfrom
fix/sdk-generator-template-drift

Conversation

@maskarb
Copy link
Contributor

@maskarb maskarb commented Mar 11, 2026

Summary

  • Update Go SDK generator templates and OpenAPI spec so that running make generate-sdk produces output identical to the current hand-edited SDK code
  • Prevents regeneration from silently dropping features

Changes

generator/templates/go/http_client.go.tmpl

  • Add crypto/tls import
  • Add insecureSkipVerify field to Client struct
  • Add WithInsecureSkipVerify() client option (needed for OpenShift/self-signed certs)
  • Compile bearerTokenPattern regex at package level (was MustCompile per call)

ambient-api-server/openapi/openapi.sessions.yaml

  • Add DELETE /api/ambient/v1/sessions/{id} endpoint so the generator emits Sessions().Delete()

generator/templates/go/types.go.tmpl

  • Fix extra blank lines between builder methods by trimming whitespace in {{range}} blocks

Verification

After these changes, running the generator produces output that differs from the committed SDK only in the timestamp and spec hash:

$ cd generator && go run . -spec ... -go-out ../go-sdk && cd ../go-sdk && go fmt ./...
$ git diff --stat go-sdk/
 client/client.go               |  4 ++--  # timestamp + hash only
 client/session_api.go           | 12 +++---     # Delete moved position + timestamp
 types/user.go                   |  4 ++--  # timestamp + hash only
 ...

Test plan

  • go run . -spec ... succeeds, reports Session delete=true
  • Generated client.go retains WithInsecureSkipVerify, insecureSkipVerify, compiled regex
  • Generated session_api.go includes Delete() method
  • Generated type files have no extra blank lines after gofmt
  • Only diff from committed code is timestamp/hash and Delete method position

🤖 Generated with Claude Code

The generated Go SDK had hand-edits that would be lost on regeneration:
- WithInsecureSkipVerify client option (TLS skip for self-signed certs)
- Compiled bearerTokenPattern regex (was per-call MustCompile)
- Sessions().Delete() method (missing DELETE in OpenAPI spec)
- Extra blank lines in type builders (template whitespace)

Fix by updating the source templates and OpenAPI spec so regeneration
produces identical output (minus timestamp/hash).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

Warning

Rate limit exceeded

@maskarb has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 042921e2-efad-4bfc-92bc-5b6514964bac

📥 Commits

Reviewing files that changed from the base of the PR and between f0a9e8b and 9c90ebf.

📒 Files selected for processing (38)
  • .github/workflows/sdk-drift-check.yml
  • components/ambient-sdk/generator/main.go
  • components/ambient-sdk/generator/templates/go/http_client.go.tmpl
  • components/ambient-sdk/go-sdk/client/client.go
  • components/ambient-sdk/go-sdk/client/iterator.go
  • components/ambient-sdk/go-sdk/client/project_api.go
  • components/ambient-sdk/go-sdk/client/project_settings_api.go
  • components/ambient-sdk/go-sdk/client/session_api.go
  • components/ambient-sdk/go-sdk/client/user_api.go
  • components/ambient-sdk/go-sdk/types/base.go
  • components/ambient-sdk/go-sdk/types/list_options.go
  • components/ambient-sdk/go-sdk/types/project.go
  • components/ambient-sdk/go-sdk/types/project_settings.go
  • components/ambient-sdk/go-sdk/types/session.go
  • components/ambient-sdk/go-sdk/types/user.go
  • components/ambient-sdk/python-sdk/ambient_platform/__init__.py
  • components/ambient-sdk/python-sdk/ambient_platform/_base.py
  • components/ambient-sdk/python-sdk/ambient_platform/_iterator.py
  • components/ambient-sdk/python-sdk/ambient_platform/_project_api.py
  • components/ambient-sdk/python-sdk/ambient_platform/_project_settings_api.py
  • components/ambient-sdk/python-sdk/ambient_platform/_session_api.py
  • components/ambient-sdk/python-sdk/ambient_platform/_user_api.py
  • components/ambient-sdk/python-sdk/ambient_platform/client.py
  • components/ambient-sdk/python-sdk/ambient_platform/project.py
  • components/ambient-sdk/python-sdk/ambient_platform/project_settings.py
  • components/ambient-sdk/python-sdk/ambient_platform/session.py
  • components/ambient-sdk/python-sdk/ambient_platform/user.py
  • components/ambient-sdk/ts-sdk/src/base.ts
  • components/ambient-sdk/ts-sdk/src/client.ts
  • components/ambient-sdk/ts-sdk/src/index.ts
  • components/ambient-sdk/ts-sdk/src/project.ts
  • components/ambient-sdk/ts-sdk/src/project_api.ts
  • components/ambient-sdk/ts-sdk/src/project_settings.ts
  • components/ambient-sdk/ts-sdk/src/project_settings_api.ts
  • components/ambient-sdk/ts-sdk/src/session.ts
  • components/ambient-sdk/ts-sdk/src/session_api.ts
  • components/ambient-sdk/ts-sdk/src/user.ts
  • components/ambient-sdk/ts-sdk/src/user_api.ts

Walkthrough

Adds a DELETE operation to the sessions OpenAPI spec, introduces an HTTP client option to skip TLS verification and improves bearer-token redaction in the Go SDK generator template, tightens whitespace in the Go types generator template, and adds a GitHub Actions workflow to detect SDK drift by regenerating and diffing SDKs.

Changes

Cohort / File(s) Summary
OpenAPI Session Endpoint
components/ambient-api-server/openapi/openapi.sessions.yaml
Added DELETE /api/ambient/v1/sessions/{id} with responses: 204, 401, 403, 404, and 500 (Error schema).
Go HTTP Client Template
components/ambient-sdk/generator/templates/go/http_client.go.tmpl
Added WithInsecureSkipVerify() ClientOption, insecureSkipVerify client field, crypto/tls import, and global bearerTokenPattern for URL log redaction.
Go Types Template
components/ambient-sdk/generator/templates/go/types.go.tmpl
Adjusted template whitespace delimiters to remove extra blank lines between ranges and Build/StatusPatchBuilder sections; no behavioral changes.
CI Workflow
.github/workflows/sdk-drift-check.yml
New "SDK Drift Check" workflow: regenerates Go/Python/TypeScript SDKs, runs gofmt, diffs generated SDKs against committed code, and fails on drift with diagnostics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: syncing generator templates with hand-edited SDK output to prevent feature loss during regeneration.
Description check ✅ Passed The description is comprehensive and clearly related to the changeset, explaining the rationale, specific changes, and verification steps.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/sdk-generator-template-drift

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Regenerates the SDK from the OpenAPI spec on PRs that touch the
generator, templates, SDK output, or OpenAPI specs. Fails if the
regenerated output differs from what's committed (ignoring timestamps).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/ambient-api-server/openapi/openapi.sessions.yaml`:
- Around line 193-198: The OpenAPI docs advertise a 403 but the DeleteSession
handler never returns it; update the DeleteSession handler to explicitly detect
a forbidden RBAC/Kubernetes error (e.g. apierrors.IsForbidden(err) or matching
the Forbidden status) and return an HTTP 403 using the same Error response
shape, ensuring the response matches the openapi.sessions.yaml Error schema;
alternatively, if you prefer docs change, remove the 403 entry from
openapi.sessions.yaml so the spec matches current DeleteSession behavior.

In `@components/ambient-sdk/generator/templates/go/http_client.go.tmpl`:
- Around line 44-51: The WithInsecureSkipVerify ClientOption currently replaces
c.httpClient.Transport with a new *http.Transport, losing defaults like
ProxyFromEnvironment and HTTP/2 support; instead, retrieve the existing
transport (from c.httpClient.Transport or http.DefaultTransport), clone it into
a new *http.Transport, ensure TLSClientConfig is non-nil, set
TLSClientConfig.InsecureSkipVerify = true on the clone, and assign the cloned
transport back to c.httpClient.Transport so only the TLS setting is changed
while other defaults are preserved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: faa9fb3e-cccd-43fb-82af-4fdf99e1ebeb

📥 Commits

Reviewing files that changed from the base of the PR and between ac84355 and 371aee0.

📒 Files selected for processing (3)
  • components/ambient-api-server/openapi/openapi.sessions.yaml
  • components/ambient-sdk/generator/templates/go/http_client.go.tmpl
  • components/ambient-sdk/generator/templates/go/types.go.tmpl

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/sdk-drift-check.yml:
- Around line 67-84: The workflow currently runs the same git diff twice when
DRIFT is detected; change the logic to run git diff once, capture its output
into a variable or temp file (e.g., store into DRIFT or DIFF_OUTPUT), then test
if the variable is non-empty and print that captured diff in the echo/Display
section before exit 1; update the conditional that checks -n "$DRIFT" to use the
captured content and remove the second git diff invocation so only a single git
diff call (the one that populates the variable/file) is used.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b1b2e597-d893-4036-b294-7d0ad8569d78

📥 Commits

Reviewing files that changed from the base of the PR and between 371aee0 and f0a9e8b.

📒 Files selected for processing (1)
  • .github/workflows/sdk-drift-check.yml

maskarb and others added 3 commits March 11, 2026 11:06
Regenerate all SDK outputs (Go, Python, TypeScript) so committed files
match what the generator produces with the updated OpenAPI spec (session
DELETE endpoint) and templates. Fix drift check ignore patterns to match
both // and # comment styles for timestamp/hash lines.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The generator templates produce trailing blank lines that pre-commit's
end-of-file-fixer strips on commit, causing perpetual drift. Fix by
trimming trailing newlines in the generator itself so output always ends
with exactly one newline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t check

- Clone the existing http.Transport instead of replacing it, preserving
  ProxyFromEnvironment, HTTP/2, and connection pool defaults
- Remove duplicate git diff call in SDK drift check workflow

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Contributor

@markturansky markturansky left a comment

Choose a reason for hiding this comment

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

LGTM.

@mergify mergify bot merged commit 744c0d4 into main Mar 11, 2026
34 checks passed
@mergify mergify bot deleted the fix/sdk-generator-template-drift branch March 11, 2026 15:57
@mergify
Copy link

mergify bot commented Mar 11, 2026

Merge Queue Status

  • Entered queue2026-03-11 15:57 UTC · Rule: default
  • Checks passed · in-place
  • Merged2026-03-11 15:57 UTC · at 9c90ebfc1a2284d7af6812706551bc80b0742fff

This pull request spent 6 seconds in the queue, with no time running CI.

Required conditions to merge

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