← back to Cli Printing Press
fix(generator): use simple backticks in auth_client_credentials.go.tmpl (#734)
6436392108844edace2390b7680eaaf9b4c56a44 · 2026-05-08 14:06:22 -0700 · Jeremy Knows
* fix(generator): use simple backticks in auth_client_credentials.go.tmpl
The OAuth2 client_credentials auth template emitted literal `+ "`" + `
template-syntax into the generated `internal/cli/auth.go`, producing
uncompilable Go for any spec triggering this auth path (Discord is the
clear case).
The over-escaped pattern was meant to embed a literal backtick inside an
enclosing raw string, but there was no enclosing raw string — the
docstrings and struct tags don't contain internal backticks. Replacing
each `\` + "\`" + \`` sequence with a plain backtick produces clean Go.
Verification: regenerated pp-discord from the official Discord OpenAPI
spec; full PASS on govulncheck, go vet, go build, runnable binary,
--help/version/doctor smoke tests, and MCP bundle creation.
Closes #733
* test(golden): update oauth2-cc auth.go to match template fix
Per @tmchow's review feedback on PR #734: the existing golden fixture at
testdata/golden/expected/generate-golden-api-oauth2-cc/printing-press-oauth2-cc/
internal/cli/auth.go contained the old escaped output. scripts/golden.sh
verify failed on this branch because the rendered output now uses simple
backticks (the intentional template fix) but the golden still showed the
broken `+ "`" + ` patterns.
Ran `scripts/golden.sh update` and verified the diff is exactly what's
expected: 6 insertions / 6 deletions, all replacing `+ "`" + ` sequences
with plain backticks in the rendered Go output. No other golden cases
changed (other 13 cases compare byte-identical pre/post update).
`scripts/golden.sh verify` now passes 14/14.
Updates the generator contract to match the template fix in
internal/generator/templates/auth_client_credentials.go.tmpl from this PR.
Files touched
M internal/generator/templates/auth_client_credentials.go.tmplM testdata/golden/expected/generate-golden-api-oauth2-cc/printing-press-oauth2-cc/internal/cli/auth.go
Diff
commit 6436392108844edace2390b7680eaaf9b4c56a44
Author: Jeremy Knows <jeremy@veefriends.com>
Date: Fri May 8 14:06:22 2026 -0700
fix(generator): use simple backticks in auth_client_credentials.go.tmpl (#734)
* fix(generator): use simple backticks in auth_client_credentials.go.tmpl
The OAuth2 client_credentials auth template emitted literal `+ "`" + `
template-syntax into the generated `internal/cli/auth.go`, producing
uncompilable Go for any spec triggering this auth path (Discord is the
clear case).
The over-escaped pattern was meant to embed a literal backtick inside an
enclosing raw string, but there was no enclosing raw string — the
docstrings and struct tags don't contain internal backticks. Replacing
each `\` + "\`" + \`` sequence with a plain backtick produces clean Go.
Verification: regenerated pp-discord from the official Discord OpenAPI
spec; full PASS on govulncheck, go vet, go build, runnable binary,
--help/version/doctor smoke tests, and MCP bundle creation.
Closes #733
* test(golden): update oauth2-cc auth.go to match template fix
Per @tmchow's review feedback on PR #734: the existing golden fixture at
testdata/golden/expected/generate-golden-api-oauth2-cc/printing-press-oauth2-cc/
internal/cli/auth.go contained the old escaped output. scripts/golden.sh
verify failed on this branch because the rendered output now uses simple
backticks (the intentional template fix) but the golden still showed the
broken `+ "`" + ` patterns.
Ran `scripts/golden.sh update` and verified the diff is exactly what's
expected: 6 insertions / 6 deletions, all replacing `+ "`" + ` sequences
with plain backticks in the rendered Go output. No other golden cases
changed (other 13 cases compare byte-identical pre/post update).
`scripts/golden.sh verify` now passes 14/14.
Updates the generator contract to match the template fix in
internal/generator/templates/auth_client_credentials.go.tmpl from this PR.
---
internal/generator/templates/auth_client_credentials.go.tmpl | 12 ++++++------
.../printing-press-oauth2-cc/internal/cli/auth.go | 12 ++++++------
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/internal/generator/templates/auth_client_credentials.go.tmpl b/internal/generator/templates/auth_client_credentials.go.tmpl
index 75881e52..89b3ffcd 100644
--- a/internal/generator/templates/auth_client_credentials.go.tmpl
+++ b/internal/generator/templates/auth_client_credentials.go.tmpl
@@ -45,20 +45,20 @@ func newAuthLoginCmd(flags *rootFlags) *cobra.Command {
cmd := &cobra.Command{
Use: "login",
Short: "Mint an OAuth2 bearer token via the client_credentials grant",
- Long: strings.TrimSpace(` + "`" + `
+ Long: strings.TrimSpace(`
Mint an OAuth2 bearer token via POST {{.Auth.TokenURL}} with
grant_type=client_credentials and cache it on disk. Subsequent commands
auto-refresh the token before expiry.
Credentials default to {{if .Auth.EnvVars}}{{index .Auth.EnvVars 0}} (Client ID){{if gt (len .Auth.EnvVars) 1}} and {{index .Auth.EnvVars 1}} (Client Secret){{end}}{{else}}your project's Client ID and Client Secret{{end}} environment variables.
-` + "`" + `),
- Example: strings.Trim(` + "`" + `
+`),
+ Example: strings.Trim(`
# Use env vars
{{.Name}}-pp-cli auth login
# Explicit credentials
{{.Name}}-pp-cli auth login --client-id <id> --client-secret <secret>
-` + "`" + `, "\n"),
+`, "\n"),
Annotations: map[string]string{"mcp:hidden": "true"},
RunE: func(cmd *cobra.Command, args []string) error {
if cliutil.IsVerifyEnv() {
@@ -121,8 +121,8 @@ Credentials default to {{if .Auth.EnvVars}}{{index .Auth.EnvVars 0}} (Client ID)
}
type tokenResponse struct {
- AccessToken string ` + "`" + `json:"access_token"` + "`" + `
- ExpiresIn int ` + "`" + `json:"expires_in"` + "`" + `
+ AccessToken string `json:"access_token"`
+ ExpiresIn int `json:"expires_in"`
}
// mintClientCredentialsToken POSTs grant_type=client_credentials to the
diff --git a/testdata/golden/expected/generate-golden-api-oauth2-cc/printing-press-oauth2-cc/internal/cli/auth.go b/testdata/golden/expected/generate-golden-api-oauth2-cc/printing-press-oauth2-cc/internal/cli/auth.go
index 11c0e4bb..0fdeac71 100644
--- a/testdata/golden/expected/generate-golden-api-oauth2-cc/printing-press-oauth2-cc/internal/cli/auth.go
+++ b/testdata/golden/expected/generate-golden-api-oauth2-cc/printing-press-oauth2-cc/internal/cli/auth.go
@@ -45,20 +45,20 @@ func newAuthLoginCmd(flags *rootFlags) *cobra.Command {
cmd := &cobra.Command{
Use: "login",
Short: "Mint an OAuth2 bearer token via the client_credentials grant",
- Long: strings.TrimSpace(` + "`" + `
+ Long: strings.TrimSpace(`
Mint an OAuth2 bearer token via POST https://api.cc.example/oauth/token with
grant_type=client_credentials and cache it on disk. Subsequent commands
auto-refresh the token before expiry.
Credentials default to PRINTING_PRESS_OAUTH2_CLIENT_ID (Client ID) and PRINTING_PRESS_OAUTH2_CLIENT_SECRET (Client Secret) environment variables.
-` + "`" + `),
- Example: strings.Trim(` + "`" + `
+`),
+ Example: strings.Trim(`
# Use env vars
printing-press-oauth2-pp-cli auth login
# Explicit credentials
printing-press-oauth2-pp-cli auth login --client-id <id> --client-secret <secret>
-` + "`" + `, "\n"),
+`, "\n"),
Annotations: map[string]string{"mcp:hidden": "true"},
RunE: func(cmd *cobra.Command, args []string) error {
if cliutil.IsVerifyEnv() {
@@ -103,8 +103,8 @@ Credentials default to PRINTING_PRESS_OAUTH2_CLIENT_ID (Client ID) and PRINTING_
}
type tokenResponse struct {
- AccessToken string ` + "`" + `json:"access_token"` + "`" + `
- ExpiresIn int ` + "`" + `json:"expires_in"` + "`" + `
+ AccessToken string `json:"access_token"`
+ ExpiresIn int `json:"expires_in"`
}
// mintClientCredentialsToken POSTs grant_type=client_credentials to the
← 4ca4b7cf Add contributor PR template and guide (#744)
·
back to Cli Printing Press
·
fix(cli): preserve novel cli files on force generate (#747) 9675f8b2 →