Skip to content

Add includeExperimental flag to experimental endpoint code samples#128

Merged
travis-hoover-glean merged 1 commit into
mainfrom
add-experimental-flag-to-code-samples
Jul 8, 2026
Merged

Add includeExperimental flag to experimental endpoint code samples#128
travis-hoover-glean merged 1 commit into
mainfrom
add-experimental-flag-to-code-samples

Conversation

@travis-hoover-glean

Copy link
Copy Markdown
Contributor

Summary

Endpoints marked with x-glean-experimental require the SDK's experimental opt-in (surfaced as the X-Glean-Include-Experimental request header). Without it, the SDKs refuse to call the endpoint — so the generated code samples for these operations don't actually run as-is.

This adds a post-processing transform that injects the experimental opt-in into the code samples for experimental endpoints only.

Changes

  • experimentalCodeSnippets(pathSpec) — generator that yields samples only for operations carrying x-glean-experimental.
  • addIncludeExperimentalToCodeSamples(spec) — injects the flag per language, wired into transform() to run after addServerURLToCodeSamples (so the server-URL constructor line exists to anchor onto):
    • Python: include_experimental=True, after the server_url line
    • TypeScript: includeExperimental: true, after the serverURL line
    • Go: apiclientgo.WithIncludeExperimental(true), after WithServerURL
    • Java: swaps Glean.builder() → the regen-safe GleanBuilder.create() (adding its import) and appends .includeExperimental(true) after .apiToken(...)

Notes

  • Java uses the documented regen-safe GleanBuilder.create() because the generated Glean.builder() isn't guaranteed to expose includeExperimental. Since platform Java samples never carry a serverURL line, the Java edit anchors on .apiToken(...) instead.
  • Verified end-to-end against the real merged_code_samples_specs/glean-platform-merged-code-samples-spec.yaml: all four /api/agents/search samples correctly gain the flag, and there are zero leaks into non-experimental samples.

Testing

  • New fixture tests/fixtures/example-with-experimental-code-samples.yaml (one experimental + one stable endpoint).
  • 6 new tests covering all four languages + a guard that non-experimental samples stay untouched.
  • All 77 tests pass; prettier clean.

Endpoints marked with `x-glean-experimental` require the SDK's experimental
opt-in (surfaced as the `X-Glean-Include-Experimental` request header), or the
SDK refuses to call them. The generated samples for these operations were
missing this, so they would not actually run as-is.

Adds `addIncludeExperimentalToCodeSamples` (run after
`addServerURLToCodeSamples`) which injects the flag per language:
- Python: `include_experimental=True,`
- TypeScript: `includeExperimental: true,`
- Go: `apiclientgo.WithIncludeExperimental(true),`
- Java: swaps `Glean.builder()` for the regen-safe `GleanBuilder.create()`
  (adding its import) and appends `.includeExperimental(true)`

A new `experimentalCodeSnippets` generator ensures only operations carrying
`x-glean-experimental` are touched. Adds a dedicated fixture and tests covering
all four languages plus a guard that non-experimental samples are untouched.
@travis-hoover-glean travis-hoover-glean marked this pull request as ready for review July 6, 2026 22:59
@travis-hoover-glean travis-hoover-glean requested a review from a team as a code owner July 6, 2026 22:59
@travis-hoover-glean travis-hoover-glean requested a review from a team July 6, 2026 22:59
@travis-hoover-glean travis-hoover-glean merged commit a2ecaa9 into main Jul 8, 2026
3 checks passed
@travis-hoover-glean travis-hoover-glean deleted the add-experimental-flag-to-code-samples branch July 8, 2026 20:16
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