fix(generator-cli): retain Go /vN module suffix in SDK-Name header and README under --version AUTO#17039
Conversation
…d README under --version AUTO Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
AI Review Summary
The PR extends the Go /vN suffix retrofit to cover non-import string literals in .go files and Markdown docs. Logic is generally sound with quote-anchoring to avoid prefix corruption, but there's a double-suffixing risk on the bare-literal replacement for both .go and Markdown files when the path is already versioned.
- 🟡 1 warning(s)
- 🔵 1 suggestion(s)
| let updated = content | ||
| .split(`"${modulePath}/`) | ||
| .join(`"${modulePath}${suffix}/`) | ||
| .split(`"${modulePath}"`) | ||
| .join(`"${modulePath}${suffix}"`); |
There was a problem hiding this comment.
🟡 warning
The quoted-import replacement here has no guard against an already-suffixed path. If modulePath is github.com/org/repo and the README already contains "github.com/org/repo/v4" (or "github.com/org/repo/v4/client"), the "${modulePath}/ split will turn it into "github.com/org/repo/v4/v4/.... The go get regex uses a negative lookahead to prevent exactly this, but the quoted path handling does not. Idempotency matters if this ever runs twice or on partially-suffixed input.
| const newLine = isImportLine | ||
| ? line | ||
| .split(`"${modulePath}/`) | ||
| .join(`"${modulePath}${suffix}/`) | ||
| .split(`"${modulePath}"`) | ||
| .join(`"${modulePath}${suffix}"`) | ||
| : line.split(`"${modulePath}"`).join(`"${modulePath}${suffix}"`); |
There was a problem hiding this comment.
🔵 suggestion
Same double-suffix concern as the Markdown path: .split("${modulePath}/) on an import line that's already "<modulePath>/v4/client" produces "<modulePath>/v4/v4/client". Fine under the documented AUTO placeholder flow (always unsuffixed), but the operation isn't idempotent. Worth a lookahead-style guard or an early check for an existing /vN segment.
Description
Under
--version AUTO, a Go SDK is generated with the major-zero placeholder (v0.0.0-fern-placeholder), so the generator emits the module path with no/vNsuffix anywhere. generator-cli retrofits the suffix afterward, butaddGoMajorVersionSuffixonly rewrotego.modand import lines in.gofiles. It missed two other places the module path is emitted:X-Fern-SDK-Nameheader value — a plain (non-import) string literal:headers.Set("X-Fern-SDK-Name", "github.com/org/repo")README.md) —go getinstall command and quoted import samples (README is not a.gofile, so the walk skipped it entirely)Result for a v4 module: the header shipped as
github.com/org/repo(missing/v4), the README import example didn't compile when copy-pasted, and theUser-Agent(which is"<modulePath>/<version>") looked wrong (.../v4.19.0) because the name half lost its/v4.This is distinct from #16964 (which strips
/vNdiff churn before FAI analysis to avoid a false breaking-change) — that fixes classification, not the shipped output format.Changes Made
addGoMajorVersionSuffixnow also rewrites non-import module-path string literals in.gofiles and Markdown docs, in addition to imports andgo.mod..gofiles: import lines get the suffix on both the bare path and subpackage paths (unchanged); non-import lines only get the bare"<modulePath>"literal rewritten (coversX-Fern-SDK-Name). The compositeUser-Agentvalue"<modulePath>/<version>"is deliberately left alone so it doesn't become.../v4/v4.19.0.README.mdetc.): rewritesgo get/go installcommands and quoted import samples. Web URLs (e.g.https://pkg.go.dev/<modulePath>) are untouched because the module path there is neither quote-anchored nor preceded by an install command.Pseudo-diff of the effect on a generated v4 Go SDK:
addSuffixToMarkdownFileTesting
addGoMajorVersionSuffixsuite: SDK-Name header literal gets/v4; compositeUser-Agentis not double-suffixed; READMEgo get+ import samples get/v4while thepkg.go.devbadge URL is left intact.@fern-api/generator-clisuite green (452 passed, 1 skipped).Link to Devin session: https://app.devin.ai/sessions/d7363ebb78134b23b785a4750dd9ea06
Requested by: @dvdaruri-art